Add cameras, fix bugs
[python_utils.git] / smart_home / cameras.py
diff --git a/smart_home/cameras.py b/smart_home/cameras.py
new file mode 100644 (file)
index 0000000..963f54e
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+
+"""Utilities for dealing with the webcams."""
+
+from abc import abstractmethod
+import datetime
+import json
+import logging
+import os
+import re
+import subprocess
+import sys
+from typing import Any, Dict, List, Optional, Set
+
+import argparse_utils
+import config
+import logging_utils
+import smart_home.device as dev
+from google_assistant import ask_google, GoogleResponse
+from decorator_utils import timeout, memoized
+
+logger = logging.getLogger(__name__)
+
+class BaseCamera(dev.Device):
+    camera_mapping = {
+        'cabin_drivewaycam': 'cabin_driveway',
+        'outside_backyard_camera': 'backyard',
+        'outside_driveway_camera': 'driveway',
+        'outside_doorbell_camera': 'doorbell',
+        'outside_front_door_camera': 'frontdoor',
+    }
+
+    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:
+        assert self.camera_name is not None
+        return f'http://10.0.0.56:81/mjpg/{self.camera_name}/video.mjpg?h=1024&q=99'