summaryrefslogtreecommitdiff
path: root/src/pump_mqtt_bot.py
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-05-11 04:18:08 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-05-11 04:18:12 +0300
commit0aba139aeff8ff80757c5d36502413299a0b449e (patch)
tree2b8e760ff14d4691783eb7c7d341f093199aab82 /src/pump_mqtt_bot.py
parent586d84b0c0a8b4dc1b5057733892b754397234ec (diff)
mqtt, esp: add new esp8266-based device
Diffstat (limited to 'src/pump_mqtt_bot.py')
-rwxr-xr-xsrc/pump_mqtt_bot.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/pump_mqtt_bot.py b/src/pump_mqtt_bot.py
index accafcb..d3b6de4 100755
--- a/src/pump_mqtt_bot.py
+++ b/src/pump_mqtt_bot.py
@@ -8,10 +8,10 @@ from telegram import ReplyKeyboardMarkup, User
from home.config import config
from home.telegram import bot
from home.telegram._botutil import user_any_name
-from home.api.types import BotType
-from home.mqtt import MQTTRelay, MQTTRelayState, MQTTRelayDevice
-from home.mqtt.payload import MQTTPayload
-from home.mqtt.payload.relay import InitialStatPayload, StatPayload
+from home.mqtt.esp import MqttEspDevice
+from home.mqtt import MqttRelay, MqttRelayState
+from home.mqtt.payload import MqttPayload
+from home.mqtt.payload.relay import InitialDiagnosticsPayload, DiagnosticsPayload
config.load('pump_mqtt_bot')
@@ -70,8 +70,8 @@ bot.lang.en(
)
-mqtt_relay: Optional[MQTTRelay] = None
-relay_state = MQTTRelayState()
+mqtt_relay: Optional[MqttRelay] = None
+relay_state = MqttRelayState()
class UserAction(Enum):
@@ -79,10 +79,10 @@ class UserAction(Enum):
OFF = 'off'
-def on_mqtt_message(home_id, message: MQTTPayload):
- if isinstance(message, InitialStatPayload) or isinstance(message, StatPayload):
+def on_mqtt_message(home_id, message: MqttPayload):
+ if isinstance(message, InitialDiagnosticsPayload) or isinstance(message, DiagnosticsPayload):
kwargs = dict(rssi=message.rssi, enabled=message.flags.state)
- if isinstance(message, InitialStatPayload):
+ if isinstance(message, InitialDiagnosticsPayload):
kwargs['fw_version'] = message.fw_version
relay_state.update(**kwargs)
@@ -157,8 +157,8 @@ def markup(ctx: Optional[bot.Context]) -> Optional[ReplyKeyboardMarkup]:
if __name__ == '__main__':
- mqtt_relay = MQTTRelay(devices=MQTTRelayDevice(id=config['mqtt']['home_id'],
- secret=config['mqtt']['home_secret']))
+ mqtt_relay = MqttRelay(devices=MqttEspDevice(id=config['mqtt']['home_id'],
+ secret=config['mqtt']['home_secret']))
mqtt_relay.set_message_callback(on_mqtt_message)
mqtt_relay.configure_tls()
mqtt_relay.connect_and_loop(loop_forever=False)