diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2023-05-31 09:22:00 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2023-06-03 01:01:27 +0300 |
commit | 0f0a5fd44867b684bcbafd102b6b769ae61229b4 (patch) | |
tree | d4845bd3295159c06041b25753af4eb2d7b59461 /src/home/mqtt/module/temphum.py | |
parent | 3e3753d726f8a02d98368f20f77dd9fa739e3d80 (diff) |
wip
Diffstat (limited to 'src/home/mqtt/module/temphum.py')
-rw-r--r-- | src/home/mqtt/module/temphum.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/home/mqtt/module/temphum.py b/src/home/mqtt/module/temphum.py new file mode 100644 index 0000000..0e43f1b --- /dev/null +++ b/src/home/mqtt/module/temphum.py @@ -0,0 +1,57 @@ +from enum import auto +from .._node import MqttNode +from .._module import MqttModule +from .._payload import MqttPayload +from ...util import HashableEnum +from typing import Optional + +two_digits_precision = lambda x: round(x, 2) + +MODULE_NAME = 'MqttTempHumModule' + + +class MqttTemphumDataPayload(MqttPayload): + FORMAT = '=ddb' + UNPACKER = { + 'temp': two_digits_precision, + 'rh': two_digits_precision + } + + temp: float + rh: float + error: int + + +class MqttTempHumNodes(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_NH_1FL_INV = auto() + KBN_NH_1FL_CENTER = auto() + KBN_NH_1LF_KT = auto() + KBN_NH_1FL_DS = auto() + KBN_NH_1FS_EZ = auto() + + SPB_FLAT120_CABINET = auto() + + +class MqttTempHumModule(MqttModule): + def init(self, mqtt: MqttNode): + mqtt.subscribe_module('temphum/data', self) + + def handle_payload(self, + mqtt: MqttNode, + topic: str, + payload: bytes) -> Optional[MqttPayload]: + if topic == 'temphum/data': + message = MqttTemphumDataPayload.unpack(payload) + self._logger.debug(message) + return message
\ No newline at end of file |