summaryrefslogtreecommitdiff
path: root/src/home/temphum
diff options
context:
space:
mode:
Diffstat (limited to 'src/home/temphum')
-rw-r--r--src/home/temphum/__init__.py38
-rw-r--r--src/home/temphum/__init__.pyi9
-rw-r--r--src/home/temphum/nodes.py23
3 files changed, 61 insertions, 9 deletions
diff --git a/src/home/temphum/__init__.py b/src/home/temphum/__init__.py
index 55a7e1f..30a459e 100644
--- a/src/home/temphum/__init__.py
+++ b/src/home/temphum/__init__.py
@@ -1,18 +1,38 @@
-from .base import SensorType, TempHumSensor
-from .si7021 import Si7021
-from .dht12 import DHT12
+from importlib import import_module
__all__ = [
'SensorType',
'TempHumSensor',
+ 'TempHumNodes',
'create_sensor'
]
-def create_sensor(type: SensorType, bus: int) -> TempHumSensor:
- if type == SensorType.Si7021:
- return Si7021(bus)
- elif type == SensorType.DHT12:
- return DHT12(bus)
+def __import_sensor(name):
+ if name == 'si7021':
+ return import_module('.si7021', __name__).Si7021
+ elif name == 'dht12':
+ return import_module('.dht12', __name__).DHT12
else:
- raise ValueError('unexpected sensor type')
+ raise ValueError(f'unexpected sensor type: {name}')
+
+
+def __getattr__(name):
+ if name == 'create_sensor':
+ base = import_module('.base', __name__)
+
+ def create_sensor(type: base.SensorType, bus: int) -> base.TempHumSensor:
+ if type == base.SensorType.Si7021:
+ return __import_sensor('si7021')(bus)
+ elif type == base.SensorType.DHT12:
+ return __import_sensor('dht12')(bus)
+ else:
+ raise ValueError(f'unexpected sensor type: {type}')
+
+ return create_sensor
+
+ elif name in ('SensorType', 'TempHumSensor'):
+ return getattr(import_module('.base', __name__), name)
+
+ elif name == 'TempHumNodes':
+ return import_module('.nodes', __name__).TempHumNodes
diff --git a/src/home/temphum/__init__.pyi b/src/home/temphum/__init__.pyi
new file mode 100644
index 0000000..c0370da
--- /dev/null
+++ b/src/home/temphum/__init__.pyi
@@ -0,0 +1,9 @@
+from .base import (
+ SensorType as SensorType,
+ TempHumSensor as TempHumSensor
+)
+from .nodes import TempHumNodes as TempHumNodes
+
+
+def create_sensor(type: SensorType, bus: int) -> TempHumSensor:
+ pass \ No newline at end of file
diff --git a/src/home/temphum/nodes.py b/src/home/temphum/nodes.py
new file mode 100644
index 0000000..b86a22a
--- /dev/null
+++ b/src/home/temphum/nodes.py
@@ -0,0 +1,23 @@
+from ..util import HashableEnum
+from enum import auto
+
+
+class TempHumNodes(HashableEnum):
+ KBN_SH_HALL = auto()
+ KBN_SH_BATHROOM = auto()
+ KBN_SH_LIVINGROOM = auto()
+ KBN_SH_BEDROOM = auto()
+
+ KBN_BH_2FL = auto()
+ KBN_BH_2FL_STREET = auto()
+ KBN_BH_1FL_LIVINGROOM = auto()
+ KBN_BH_1FL_BEDROOM = auto()
+ KBN_BH_1FL_BATHROOM = auto()
+ KBN_STR_EL_BOX = auto()
+
+ SPB_FLAT120_CABINET = auto()
+ SPB_FLAT120_LIVINGROOM = auto()
+ SPB_FLAT120_BEDROOM = auto()
+ SPB_FLAT120_LVR_BALCONY = auto()
+ SPB_FLAT120_BDR_BALCONY = auto()
+ SPB_FLAT120_BATHROOM = auto()