From: Martin Mares Date: Wed, 23 Aug 2023 20:13:48 +0000 (+0200) Subject: Iris: Updated to aiomqtt and Python 3.11 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=474f659b51a49f19a5bfe1c43d1307461757b482;p=home-hw.git Iris: Updated to aiomqtt and Python 3.11 --- diff --git a/rainbow/iris/burrow-iris.py b/rainbow/iris/burrow-iris.py index 9d65617..dbf14e7 100755 --- a/rainbow/iris/burrow-iris.py +++ b/rainbow/iris/burrow-iris.py @@ -5,7 +5,7 @@ import argparse import asyncio -import asyncio_mqtt +import aiomqtt from datetime import datetime, timedelta import logging from logging.handlers import SysLogHandler @@ -141,17 +141,17 @@ 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') - will = asyncio_mqtt.Will(topic='status/iris', payload='dead', qos=1, retain=True) + will = aiomqtt.Will(topic='status/iris', payload='dead', qos=1, retain=True) - async with asyncio_mqtt.Client(client_id='iris', hostname="burrow-mqtt", port=8883, tls_context=sctx, will=will) as mqtt: + async with aiomqtt.Client(client_id='iris', hostname="burrow-mqtt", port=8883, tls_context=sctx, will=will) as mqtt: global st st = State(mqtt) - async with mqtt.unfiltered_messages() as messages: + async with mqtt.messages() as messages: await mqtt.subscribe("burrow/air/ac-on") await mqtt.subscribe("burrow/heating/#") await mqtt.subscribe("burrow/temp/#") @@ -165,7 +165,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/rainbow/iris/requirements.txt b/rainbow/iris/requirements.txt index f6f80c2..6c1bce1 100644 --- a/rainbow/iris/requirements.txt +++ b/rainbow/iris/requirements.txt @@ -1 +1 @@ -asyncio-mqtt +aiomqtt