Skip to content

Commit 92f14af

Browse files
committed
Bug fix: As a result of parsing device values, DUMMY_VAL may be set, which causes ha_diff to fail.
1 parent be59bcf commit 92f14af

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

inelsmqtt/devices/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
TOPIC_FRAGMENTS,
1919
VERSION,
2020
)
21-
from inelsmqtt.utils.core import DeviceClassProtocol, DeviceTypeNotFound, DeviceValue, ProtocolHandlerMapper
21+
from inelsmqtt.utils.core import DUMMY_VAL, DeviceClassProtocol, DeviceTypeNotFound, DeviceValue, ProtocolHandlerMapper
2222

2323
_LOGGER = logging.getLogger(__name__)
2424

@@ -335,6 +335,9 @@ def ha_diff(self, last_val: Any, curr_val: Any) -> None:
335335
if self.__entity_callbacks is None:
336336
return
337337

338+
if last_val is DUMMY_VAL or curr_val is DUMMY_VAL:
339+
return
340+
338341
for k, curr_value in curr_val.__dict__.items():
339342
if k.startswith("_"):
340343
continue

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name="elkoep-mqtt",
7-
version="0.2.33.beta.8",
7+
version="0.2.33.beta.9",
88
url="https://github.com/epdevlab/elkoep-mqtt",
99
license="MIT",
1010
author="Elko EP s.r.o.",

tests/test_device.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010
from inelsmqtt.devices import Device, DeviceInfo
1111
from inelsmqtt.utils.common import SimpleRelay, WarmLight, new_object
12+
from inelsmqtt.utils.core import DUMMY_VAL
1213

1314
TEST_STATE_TOPIC = "inels/status/10e97f8b7d30/02/02E8"
1415

@@ -205,3 +206,37 @@ def test_ha_diff_plain(device):
205206
callback_low_battery.assert_not_called()
206207
callback_temp_in.assert_called_once()
207208
callback_temp_out.assert_not_called()
209+
210+
211+
def test_ha_diff_dummy_val(device):
212+
callback_low_battery = MagicMock()
213+
callback_temp_in = MagicMock()
214+
callback_temp_out = MagicMock()
215+
216+
device.add_ha_callback("low_battery", -1, callback_low_battery)
217+
device.add_ha_callback("temp_in", -1, callback_temp_in)
218+
device.add_ha_callback("temp_out", -1, callback_temp_out)
219+
220+
curr_val = new_object(
221+
low_battery=True,
222+
temp_in=2250,
223+
temp_out=2000,
224+
)
225+
226+
# Test when last_val is DUMMY_VAL
227+
device.ha_diff(DUMMY_VAL, curr_val)
228+
callback_low_battery.assert_not_called()
229+
callback_temp_in.assert_not_called()
230+
callback_temp_out.assert_not_called()
231+
232+
# Test when curr_val is DUMMY_VAL
233+
device.ha_diff(curr_val, DUMMY_VAL)
234+
callback_low_battery.assert_not_called()
235+
callback_temp_in.assert_not_called()
236+
callback_temp_out.assert_not_called()
237+
238+
# Test when both values are DUMMY_VAL
239+
device.ha_diff(DUMMY_VAL, DUMMY_VAL)
240+
callback_low_battery.assert_not_called()
241+
callback_temp_in.assert_not_called()
242+
callback_temp_out.assert_not_called()

0 commit comments

Comments
 (0)