Add some docs and doctests to things that have 0% coverage.
[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 from typing import Optional
9
10 import scott_secrets
11 import smart_home.device as dev
12
13 logger = logging.getLogger(__name__)
14
15
16 class BaseCamera(dev.Device):
17     """A base class for a webcam device."""
18
19     camera_mapping = {
20         'cabin_drivewaycam': 'cabin_driveway',
21         'outside_backyard_camera': 'backyard',
22         'outside_driveway_camera_wired': 'driveway',
23         'outside_driveway_camera_wifi': 'driveway',
24         'outside_doorbell_camera': 'doorbell',
25         'outside_front_door_camera': 'front_door',
26         'crawlspace_camera': 'crawlspace',
27     }
28
29     def __init__(self, name: str, mac: str, keywords: str = "") -> None:
30         super().__init__(name.strip(), mac.strip(), keywords)
31         self.camera_name = BaseCamera.camera_mapping.get(name, None)
32
33     def get_stream_url(self) -> Optional[str]:
34         """Get the URL for the webcam's live stream.  Return None on error."""
35
36         name = self.camera_name
37         if not name:
38             return None
39         if name == 'driveway':
40             return f'http://10.0.0.226:8080/{scott_secrets.SHINOBI_KEY1}/mjpeg/{scott_secrets.SHINOBI_KEY2}/driveway'
41         else:
42             return f'http://10.0.0.226:8080/{scott_secrets.SHINOBI_KEY1}/mp4/{scott_secrets.SHINOBI_KEY2}/{name}/s.mp4'