diff options
Diffstat (limited to 'src/relay_mqtt_bot.py')
-rwxr-xr-x | src/relay_mqtt_bot.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/relay_mqtt_bot.py b/src/relay_mqtt_bot.py index 33b7e06..ebbff82 100755 --- a/src/relay_mqtt_bot.py +++ b/src/relay_mqtt_bot.py @@ -6,10 +6,10 @@ from functools import partial from home.config import config from home.telegram import bot -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 import MqttRelay, MqttRelayState +from home.mqtt.esp import MqttEspDevice +from home.mqtt.payload import MqttPayload +from home.mqtt.payload.relay import InitialDiagnosticsPayload, DiagnosticsPayload config.load('relay_mqtt_bot') @@ -34,8 +34,8 @@ status_emoji = { 'on': '✅', 'off': '❌' } -mqtt_relay: Optional[MQTTRelay] = None -relay_states: dict[str, MQTTRelayState] = {} +mqtt_relay: Optional[MqttRelay] = None +relay_states: dict[str, MqttRelayState] = {} class UserAction(Enum): @@ -43,13 +43,13 @@ 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 if home_id not in relay_states: - relay_states[home_id] = MQTTRelayState() + relay_states[home_id] = MqttRelayState() relay_states[home_id].update(**kwargs) @@ -87,8 +87,8 @@ def markup(ctx: Optional[bot.Context]) -> Optional[ReplyKeyboardMarkup]: if __name__ == '__main__': devices = [] for device_id, data in config['relays'].items(): - devices.append(MQTTRelayDevice(id=device_id, - secret=data['secret'])) + devices.append(MqttEspDevice(id=device_id, + secret=data['secret'])) labels = data['labels'] bot.lang.ru(**{device_id: labels['ru']}) bot.lang.en(**{device_id: labels['en']}) @@ -101,7 +101,7 @@ if __name__ == '__main__': messages.append(f'{type_emoji}{status_emoji[action.value]} {labels[_lang]}') bot.handler(texts=messages)(partial(enable_handler if action == UserAction.ON else disable_handler, device_id)) - mqtt_relay = MQTTRelay(devices=devices) + mqtt_relay = MqttRelay(devices=devices) mqtt_relay.set_message_callback(on_mqtt_message) mqtt_relay.configure_tls() mqtt_relay.connect_and_loop(loop_forever=False) |