Since this thing is on the innerwebs I suppose it should have a
[python_utils.git] / smart_home / cameras.py
1 #!/usr/bin/env python3
2
3 # © Copyright 2021-2022, Scott Gasch
4
5 """Utilities for dealing with the webcams."""
6
7 import logging
8
9 import smart_home.device as dev
10
11 logger = logging.getLogger(__name__)
12
13
14 class BaseCamera(dev.Device):
15     """A base class for a webcam device."""
16
17     camera_mapping = {
18         'cabin_drivewaycam': 'cabin_driveway',
19         'outside_backyard_camera': 'backyard',
20         'outside_driveway_camera_wired': 'driveway',
21         'outside_driveway_camera_wifi': 'driveway',
22         'outside_doorbell_camera': 'doorbell',
23         'outside_front_door_camera': 'front_door',
24         'crawlspace_camera': 'crawlspace',
25     }
26
27     def __init__(self, name: str, mac: str, keywords: str = "") -> None:
28         super().__init__(name.strip(), mac.strip(), keywords)
29         self.camera_name = BaseCamera.camera_mapping.get(name, None)
30
31     def get_stream_url(self) -> str:
32         name = self.camera_name
33         assert name is not None
34         if name == 'driveway':
35             return 'http://10.0.0.226:8080/Umtxxf1uKMBniFblqeQ9KRbb6DDzN4/mjpeg/GKlT2FfiSQ/driveway'
36         else:
37             return (
38                 f'http://10.0.0.226:8080/Umtxxf1uKMBniFblqeQ9KRbb6DDzN4/mp4/GKlT2FfiSQ/{name}/s.mp4'
39             )