From fc45ae6e5097e667a68290260565c264bc392db9 Mon Sep 17 00:00:00 2001 From: Stackie Jia Date: Thu, 6 Mar 2025 16:55:51 +0800 Subject: [PATCH] fix: update paho-mqtt dependency version range Expand paho-mqtt version constraint to allow minor version updates up to version 3. This should make libdeye compatible with homeassistant 2025.3 --- setup.cfg | 2 +- src/libdeye/mqtt_client.py | 13 +++++-------- tests/test_mqtt_client.py | 6 +++--- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/setup.cfg b/setup.cfg index 2e5b6c3..9dbaa73 100644 --- a/setup.cfg +++ b/setup.cfg @@ -51,7 +51,7 @@ python_requires = >=3.10 install_requires = aiohttp>=3.8,<4.0 PyJWT>=2.0,<3.0 - paho-mqtt>=1.6,<2 + paho-mqtt>=1.6,<3 [options.package_data] libdeye = py.typed diff --git a/src/libdeye/mqtt_client.py b/src/libdeye/mqtt_client.py index 711c4cf..3f8c71f 100644 --- a/src/libdeye/mqtt_client.py +++ b/src/libdeye/mqtt_client.py @@ -10,10 +10,7 @@ import paho.mqtt.client as mqtt -from .cloud_api import ( - DeyeApiResponseFogPlatformDeviceProperties, - DeyeCloudApi, -) +from .cloud_api import DeyeApiResponseFogPlatformDeviceProperties, DeyeCloudApi from .const import QUERY_DEVICE_STATE_COMMAND_CLASSIC from .device_command import DeyeDeviceCommand from .device_state import DeyeDeviceState @@ -40,7 +37,7 @@ def __init__( self._mqtt.on_connect = self._mqtt_on_connect self._mqtt.on_message = self._mqtt_on_message self._mqtt.on_disconnect = self._mqtt_on_disconnect - self._subscribers: dict[str, set[Callable[[mqtt.MQTTMessage], None]]] = {} + self._subscribers: dict[str, set[Callable[[Any], None]]] = {} self._pending_commands: list[tuple[str, bytes]] = [] @abstractmethod @@ -64,8 +61,8 @@ def _mqtt_on_connect( _mqtt: mqtt.Client, _userdata: None, _flags: dict[str, int], - _result_code: int, - _properties: mqtt.Properties | None = None, + _result_code: Any, + _properties: Any, ) -> None: for topic, callbacks in self._subscribers.items(): if len(callbacks) > 0: @@ -110,7 +107,7 @@ def _mqtt_on_message( def _subscribe_topic( self, topic: str, - callback: Callable[[mqtt.MQTTMessage], None], + callback: Callable[[Any], None], ) -> Callable[[], None]: if topic not in self._subscribers: self._subscribers[topic] = set() diff --git a/tests/test_mqtt_client.py b/tests/test_mqtt_client.py index a41e996..2d6d263 100644 --- a/tests/test_mqtt_client.py +++ b/tests/test_mqtt_client.py @@ -134,7 +134,7 @@ def test_mqtt_on_connect(self, base_client: MockBaseDeyeMqttClient) -> None: # Call _mqtt_on_connect with patch.object(base_client._mqtt, "subscribe") as mock_subscribe: with patch.object(base_client._mqtt, "publish") as mock_publish: - base_client._mqtt_on_connect(base_client._mqtt, None, {}, 0) + base_client._mqtt_on_connect(base_client._mqtt, None, {}, 0, {}) mock_subscribe.assert_called_once_with(topic1) mock_publish.assert_called_once_with(pending_topic, pending_command) assert len(base_client._pending_commands) == 0 @@ -278,7 +278,7 @@ async def test_set_mqtt_info(self, classic_client: DeyeClassicMqttClient) -> Non assert classic_client._mqtt_host == "test.mqtt.host" assert classic_client._mqtt_ssl_port == 8883 assert classic_client._endpoint == "test_endpoint" - classic_client._mqtt.username_pw_set.assert_called_once_with( + cast(MagicMock, classic_client._mqtt).username_pw_set.assert_called_once_with( "test_user", "test_password" ) @@ -458,7 +458,7 @@ async def test_set_mqtt_info(self, fog_client: DeyeFogMqttClient) -> None: assert fog_client._mqtt_host == "test.mqtt.host" assert fog_client._mqtt_ssl_port == 8883 assert fog_client._topic == "fogcloud/app/test_user/sub" - fog_client._mqtt.username_pw_set.assert_called_once_with( + cast(MagicMock, fog_client._mqtt).username_pw_set.assert_called_once_with( "test_user", "test_password" )