Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions src/libdeye/mqtt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions tests/test_mqtt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
)

Expand Down Expand Up @@ -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"
)

Expand Down