summaryrefslogtreecommitdiff
path: root/smart_home/cameras.py
blob: 8643611811f69f61a6c46f37f9c6680c0479d441 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3

# © Copyright 2021-2022, Scott Gasch

"""Utilities for dealing with the webcams."""

import logging

import scott_secrets
import smart_home.device as dev

logger = logging.getLogger(__name__)


class BaseCamera(dev.Device):
    """A base class for a webcam device."""

    camera_mapping = {
        'cabin_drivewaycam': 'cabin_driveway',
        'outside_backyard_camera': 'backyard',
        'outside_driveway_camera_wired': 'driveway',
        'outside_driveway_camera_wifi': 'driveway',
        'outside_doorbell_camera': 'doorbell',
        'outside_front_door_camera': 'front_door',
        'crawlspace_camera': 'crawlspace',
    }

    def __init__(self, name: str, mac: str, keywords: str = "") -> None:
        super().__init__(name.strip(), mac.strip(), keywords)
        self.camera_name = BaseCamera.camera_mapping.get(name, None)

    def get_stream_url(self) -> str:
        name = self.camera_name
        assert name is not None
        if name == 'driveway':
            return f'http://10.0.0.226:8080/{scott_secrets.SHINOBI_KEY1}/mjpeg/{scott_secrets.SHINOBI_KEY2}/driveway'
        else:
            return f'http://10.0.0.226:8080/{scott_secrets.SHINOBI_KEY1}/mp4/{scott_secrets.SHINOBI_KEY2}/{name}/s.mp4'