From: Martin Mares Date: Wed, 23 Aug 2023 20:18:02 +0000 (+0200) Subject: Telegram: Updated to aiomqtt and Python 3.11 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=10c033f95cdeeaa692c7f62eabcfcc83536d81bf;hp=474f659b51a49f19a5bfe1c43d1307461757b482;p=home-hw.git Telegram: Updated to aiomqtt and Python 3.11 --- diff --git a/telegram/burrow-telegram.py b/telegram/burrow-telegram.py index 7305915..bf2e46a 100755 --- a/telegram/burrow-telegram.py +++ b/telegram/burrow-telegram.py @@ -4,7 +4,7 @@ from aiogram import Bot, Dispatcher, executor, types import asyncio -import asyncio_mqtt +import aiomqtt from configparser import ConfigParser from datetime import datetime, timedelta import logging @@ -132,13 +132,13 @@ async def mqtt_process_msg(topic, val): async def mqtt_loop(): - sctx = ssl.SSLContext(ssl.PROTOCOL_TLS) + sctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) sctx.verify_mode = ssl.CERT_REQUIRED sctx.load_cert_chain('/etc/burrow-mqtt/client.crt', '/etc/burrow-mqtt/client.key') sctx.load_verify_locations(cafile='/etc/burrow-mqtt/ca.crt') - async with asyncio_mqtt.Client(client_id='telegram', hostname="burrow-mqtt", port=8883, tls_context=sctx) as mqtt: - async with mqtt.unfiltered_messages() as messages: + async with aiomqtt.Client(client_id='telegram', hostname="burrow-mqtt", port=8883, tls_context=sctx) as mqtt: + async with mqtt.messages() as messages: await mqtt.subscribe("burrow/heating/#") await mqtt.subscribe("burrow/temp/#") async for msg in messages: @@ -150,7 +150,7 @@ async def mqtt_watcher(): try: logger.info("Starting MQTT") await mqtt_loop() - except asyncio_mqtt.MqttError as error: + except aiomqtt.MqttError as error: logger.error(f"MQTT error: {error}") await asyncio.sleep(10) diff --git a/telegram/requirements.txt b/telegram/requirements.txt index ce90c2b..07810ca 100644 --- a/telegram/requirements.txt +++ b/telegram/requirements.txt @@ -1,2 +1,2 @@ aiogram -asyncio-mqtt +aiomqtt