diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2023-05-12 04:33:32 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2023-05-12 04:33:32 +0300 |
commit | f2a7cafc9be2e1e2ad01c77917108b76624e4a66 (patch) | |
tree | e67646ebcdb5c6674bca26b1c8004740b0e00b26 /src/home | |
parent | 883f3181392b1f46c9299cf28396cf635c8ac492 (diff) |
temphum: refactoring in progress
Diffstat (limited to 'src/home')
-rw-r--r-- | src/home/mqtt/temphum.py | 21 | ||||
-rw-r--r-- | src/home/util.py | 12 |
2 files changed, 27 insertions, 6 deletions
diff --git a/src/home/mqtt/temphum.py b/src/home/mqtt/temphum.py index b9b2eb9..83886ac 100644 --- a/src/home/mqtt/temphum.py +++ b/src/home/mqtt/temphum.py @@ -1,10 +1,25 @@ import paho.mqtt.client as mqtt import re -from .payload.temphum import ( - TempHumDataPayload -) +from enum import auto +from .payload.temphum import TempHumDataPayload from .esp import MqttEspBase +from ..util import HashableEnum + + +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() + + SPB_FLAT120_CABINET = auto() class MqttTempHum(MqttEspBase): diff --git a/src/home/util.py b/src/home/util.py index 5050ebb..d5c4229 100644 --- a/src/home/util.py +++ b/src/home/util.py @@ -7,9 +7,10 @@ import logging import string import random -from enum import Enum +from enum import Enum, IntEnum from datetime import datetime -from typing import Tuple, Optional, List +from typing import Tuple, Optional, List, Union +from zlib import adler32 Addr = Tuple[str, int] # network address type (host, port) @@ -187,4 +188,9 @@ def filesize_fmt(num, suffix="B") -> str: if abs(num) < 1024.0: return f"{num:3.1f} {unit}{suffix}" num /= 1024.0 - return f"{num:.1f} Yi{suffix}"
\ No newline at end of file + return f"{num:.1f} Yi{suffix}" + + +class HashableEnum(Enum): + def hash(self) -> int: + return adler32(self.name.encode())
\ No newline at end of file |