projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Improve wildcard semantics again.
[python_utils.git]
/
smart_home
/
thermometers.py
diff --git
a/smart_home/thermometers.py
b/smart_home/thermometers.py
index dff84f6250dfb410f11ed6dd81ef42d87fd54148..73117bc1a3cccddf0c22be8ab8cb10572b3b41f8 100644
(file)
--- a/
smart_home/thermometers.py
+++ b/
smart_home/thermometers.py
@@
-1,5
+1,9
@@
#!/usr/bin/env python3
#!/usr/bin/env python3
+# © Copyright 2021-2022, Scott Gasch
+
+"""Code involving querying various smart home thermometers."""
+
import logging
import urllib.request
from typing import Optional
import logging
import urllib.request
from typing import Optional
@@
-8,6
+12,8
@@
logger = logging.getLogger()
class ThermometerRegistry(object):
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'),
def __init__(self):
self.thermometers = {
'house_outside': ('10.0.0.75', 'outside_temp'),
@@
-25,11
+31,13
@@
class ThermometerRegistry(object):
record = self.thermometers.get(location, None)
if record is None:
logger.error(
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]}'
)
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')
try:
www = urllib.request.urlopen(url, timeout=3)
temp = www.read().decode('utf-8')
@@
-40,7
+48,7
@@
class ThermometerRegistry(object):
temp = round(temp)
except Exception as e:
logger.exception(e)
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:
temp = None
finally:
if www is not None: