3 # © Copyright 2021-2022, Scott Gasch
5 """Utilities for dealing with the webcams."""
8 from typing import Optional
11 import smart_home.device as dev
13 logger = logging.getLogger(__name__)
16 class BaseCamera(dev.Device):
17 """A base class for a webcam device."""
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',
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)
33 def get_stream_url(self) -> Optional[str]:
34 """Get the URL for the webcam's live stream. Return None on error."""
36 name = self.camera_name
39 if name == 'driveway':
40 return f'http://10.0.0.226:8080/{scott_secrets.SHINOBI_KEY1}/mjpeg/{scott_secrets.SHINOBI_KEY2}/driveway'
42 return f'http://10.0.0.226:8080/{scott_secrets.SHINOBI_KEY1}/mp4/{scott_secrets.SHINOBI_KEY2}/{name}/s.mp4'