summaryrefslogtreecommitdiff
path: root/smart_home
diff options
context:
space:
mode:
Diffstat (limited to 'smart_home')
-rw-r--r--smart_home/cameras.py6
-rw-r--r--smart_home/chromecasts.py8
-rw-r--r--smart_home/device_utils.py7
-rw-r--r--smart_home/outlets.py15
l---------smart_home/pyproject.toml1
-rw-r--r--smart_home/thermometers.py12
6 files changed, 35 insertions, 14 deletions
diff --git a/smart_home/cameras.py b/smart_home/cameras.py
index 712d73f..f77ddc6 100644
--- a/smart_home/cameras.py
+++ b/smart_home/cameras.py
@@ -10,6 +10,8 @@ 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',
@@ -30,4 +32,6 @@ class BaseCamera(dev.Device):
if name == 'driveway':
return 'http://10.0.0.226:8080/Umtxxf1uKMBniFblqeQ9KRbb6DDzN4/mjpeg/GKlT2FfiSQ/driveway'
else:
- return f'http://10.0.0.226:8080/Umtxxf1uKMBniFblqeQ9KRbb6DDzN4/mp4/GKlT2FfiSQ/{name}/s.mp4'
+ return (
+ f'http://10.0.0.226:8080/Umtxxf1uKMBniFblqeQ9KRbb6DDzN4/mp4/GKlT2FfiSQ/{name}/s.mp4'
+ )
diff --git a/smart_home/chromecasts.py b/smart_home/chromecasts.py
index bec8461..dd6d217 100644
--- a/smart_home/chromecasts.py
+++ b/smart_home/chromecasts.py
@@ -17,6 +17,8 @@ logger = logging.getLogger(__name__)
class BaseChromecast(dev.Device):
+ """A base class to represent a Google Chromecase device."""
+
ccasts: List[Any] = []
refresh_ts = None
browser = None
@@ -45,13 +47,11 @@ class BaseChromecast(dev.Device):
self.cast = None
for cc in BaseChromecast.ccasts:
if cc.cast_info.host == ip and cc.cast_info.cast_type != 'group':
- logger.debug(f'Found chromecast at {ip}: {cc}')
+ logger.debug('Found chromecast at %s: %s', ip, cc)
self.cast = cc
self.cast.wait(timeout=1.0)
if self.cast is None:
- raise Exception(
- f'Can\'t find ccast device at {ip}, is that really a ccast device?'
- )
+ raise Exception(f'Can\'t find ccast device at {ip}, is that really a ccast device?')
def is_idle(self):
return self.cast.is_idle
diff --git a/smart_home/device_utils.py b/smart_home/device_utils.py
index f79c734..40a7b70 100644
--- a/smart_home/device_utils.py
+++ b/smart_home/device_utils.py
@@ -1,12 +1,11 @@
#!/usr/bin/env python3
+"""General utility functions involving smart home devices."""
+
import logging
from typing import Any
-import smart_home.cameras as cameras
-import smart_home.chromecasts as chromecasts
-import smart_home.lights as lights
-import smart_home.outlets as outlets
+from smart_home import cameras, chromecasts, lights, outlets
logger = logging.getLogger(__name__)
diff --git a/smart_home/outlets.py b/smart_home/outlets.py
index a7f6f47..60b98a6 100644
--- a/smart_home/outlets.py
+++ b/smart_home/outlets.py
@@ -58,11 +58,13 @@ def tplink_outlet_command(command: str) -> bool:
logger.warning(msg)
logging_utils.hlog(msg)
return False
- logger.debug(f'{command} succeeded.')
+ logger.debug('%s succeeded.', command)
return True
class BaseOutlet(dev.Device):
+ """An abstract base class for smart outlets."""
+
def __init__(self, name: str, mac: str, keywords: str = "") -> None:
super().__init__(name.strip(), mac.strip(), keywords)
@@ -84,6 +86,8 @@ class BaseOutlet(dev.Device):
class TPLinkOutlet(BaseOutlet):
+ """A TPLink smart outlet."""
+
def __init__(self, name: str, mac: str, keywords: str = '') -> None:
super().__init__(name, mac, keywords)
self.info: Optional[Dict] = None
@@ -150,6 +154,9 @@ class TPLinkOutlet(BaseOutlet):
class TPLinkOutletWithChildren(TPLinkOutlet):
+ """A TPLink outlet where the top and bottom plus are individually
+ controllable."""
+
def __init__(self, name: str, mac: str, keywords: str = "") -> None:
super().__init__(name, mac, keywords)
self.children: List[str] = []
@@ -178,7 +185,7 @@ class TPLinkOutletWithChildren(TPLinkOutlet):
cmd = self.get_cmdline(child) + f"-c {cmd}"
if extra_args is not None:
cmd += f" {extra_args}"
- logger.debug(f'About to execute {cmd}')
+ logger.debug('About to execute: %s', cmd)
return tplink_outlet_command(cmd)
def get_children(self) -> List[str]:
@@ -208,6 +215,8 @@ class TPLinkOutletWithChildren(TPLinkOutlet):
class GoogleOutlet(BaseOutlet):
+ """A smart outlet controlled via Google Assistant."""
+
def __init__(self, name: str, mac: str, keywords: str = "") -> None:
super().__init__(name.strip(), mac.strip(), keywords)
self.info = None
@@ -285,6 +294,8 @@ class MerossWrapper(object):
class MerossOutlet(BaseOutlet):
+ """A Meross smart outlet class."""
+
def __init__(self, name: str, mac: str, keywords: str = '') -> None:
super().__init__(name, mac, keywords)
self.meross_wrapper: Optional[MerossWrapper] = None
diff --git a/smart_home/pyproject.toml b/smart_home/pyproject.toml
new file mode 120000
index 0000000..1e11d78
--- /dev/null
+++ b/smart_home/pyproject.toml
@@ -0,0 +1 @@
+../pyproject.toml \ No newline at end of file
diff --git a/smart_home/thermometers.py b/smart_home/thermometers.py
index dff84f6..90199b9 100644
--- a/smart_home/thermometers.py
+++ b/smart_home/thermometers.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python3
+"""Code involving querying various smart home thermometers."""
+
import logging
import urllib.request
from typing import Optional
@@ -8,6 +10,8 @@ logger = logging.getLogger()
class ThermometerRegistry(object):
+ """A registry of thermometer hosts / names and how to talk with them."""
+
def __init__(self):
self.thermometers = {
'house_outside': ('10.0.0.75', 'outside_temp'),
@@ -25,11 +29,13 @@ class ThermometerRegistry(object):
record = self.thermometers.get(location, None)
if record is None:
logger.error(
- f'Location {location} is not known. Valid locations are {self.thermometers.keys()}.'
+ 'Location %s is not known. Valid locations are %s.',
+ location,
+ self.thermometers.keys(),
)
return None
url = f'http://{record[0]}/~pi/{record[1]}'
- logger.debug(f'Constructed URL: {url}')
+ logger.debug('Constructed URL: %s', url)
try:
www = urllib.request.urlopen(url, timeout=3)
temp = www.read().decode('utf-8')
@@ -40,7 +46,7 @@ class ThermometerRegistry(object):
temp = round(temp)
except Exception as e:
logger.exception(e)
- logger.error(f'Failed to read temperature at URL: {url}')
+ logger.error('Failed to read temperature at URL: %s', url)
temp = None
finally:
if www is not None: