From 5debab30c5a0eb40148260b4fb419389c5e0ab8e Mon Sep 17 00:00:00 2001 From: Emanuele Palazzetti Date: Thu, 12 Oct 2023 13:19:00 +0000 Subject: [PATCH] refactor: rename lastIds in last_ids (snake case) --- custom_components/econnect_metronet/devices.py | 10 +++++----- tests/test_devices.py | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/custom_components/econnect_metronet/devices.py b/custom_components/econnect_metronet/devices.py index 9971b1a..28e8c11 100644 --- a/custom_components/econnect_metronet/devices.py +++ b/custom_components/econnect_metronet/devices.py @@ -40,7 +40,7 @@ def __init__(self, connection, config=None): self._sectors_home = [] self._sectors_night = [] self._sectors_vacation = [] - self._lastIds = { + self._last_ids = { q.SECTORS: 0, q.INPUTS: 0, } @@ -108,7 +108,7 @@ def has_updates(self): """ try: self._connection.get_status() - return self._connection.poll({key: value for key, value in self._lastIds.items()}) + return self._connection.poll({key: value for key, value in self._last_ids.items()}) except HTTPError as err: _LOGGER.error(f"Device | Error while polling for updates: {err.response.text}") raise err @@ -164,7 +164,7 @@ def update(self): sectors_disarmed (dict): A dictionary of sectors that are disarmed. inputs_alerted (dict): A dictionary of inputs that are in an alerted state. inputs_wait (dict): A dictionary of inputs that are in a wait state. - _lastIds (dict): Updated last known IDs for sectors and inputs. + _last_ids (dict): Updated last known IDs for sectors and inputs. state (str): Updated internal state of the device. """ # Retrieve sectors and inputs @@ -190,8 +190,8 @@ def update(self): self.inputs_alerted = _filter_data(inputs, "inputs", True) self.inputs_wait = _filter_data(inputs, "inputs", False) - self._lastIds[q.SECTORS] = sectors.get("last_id", 0) - self._lastIds[q.INPUTS] = inputs.get("last_id", 0) + self._last_ids[q.SECTORS] = sectors.get("last_id", 0) + self._last_ids[q.INPUTS] = inputs.get("last_id", 0) # Update system alerts self.alerts = alerts diff --git a/tests/test_devices.py b/tests/test_devices.py index ec6221e..05a3a2d 100644 --- a/tests/test_devices.py +++ b/tests/test_devices.py @@ -26,7 +26,7 @@ def test_device_constructor(client): # Test assert device._connection == client assert device._inventory == {} - assert device._lastIds == {q.SECTORS: 0, q.INPUTS: 0} + assert device._last_ids == {q.SECTORS: 0, q.INPUTS: 0} assert device._sectors_home == [] assert device._sectors_night == [] assert device._sectors_vacation == [] @@ -49,7 +49,7 @@ def test_device_constructor_with_config(client): # Test assert device._connection == client assert device._inventory == {} - assert device._lastIds == {q.SECTORS: 0, q.INPUTS: 0} + assert device._last_ids == {q.SECTORS: 0, q.INPUTS: 0} assert device._sectors_home == [3, 4] assert device._sectors_night == [1, 2, 3] assert device._sectors_vacation == [5, 3] @@ -97,8 +97,8 @@ def test_device_has_updates(client, mocker): """Should call the client polling system passing the internal state.""" device = AlarmDevice(client) device.connect("username", "password") - device._lastIds[q.SECTORS] = 20 - device._lastIds[q.INPUTS] = 20 + device._last_ids[q.SECTORS] = 20 + device._last_ids[q.INPUTS] = 20 mocker.spy(device._connection, "poll") # Test device.has_updates() @@ -115,13 +115,13 @@ def bad_poll(ids): device = AlarmDevice(client) device.connect("username", "password") - device._lastIds = {q.SECTORS: 4, q.INPUTS: 42} + device._last_ids = {q.SECTORS: 4, q.INPUTS: 42} mocker.patch.object(device._connection, "poll") device._connection.poll.side_effect = bad_poll # Test device.has_updates() assert device._connection.poll.call_count == 1 - assert {9: 4, 10: 42} == device._lastIds + assert {9: 4, 10: 42} == device._last_ids def test_device_has_updates_errors(client, mocker): @@ -134,7 +134,7 @@ def test_device_has_updates_errors(client, mocker): with pytest.raises(HTTPError): device.has_updates() assert device._connection.poll.call_count == 1 - assert {9: 0, 10: 0} == device._lastIds + assert {9: 0, 10: 0} == device._last_ids def test_device_has_updates_parse_errors(client, mocker): @@ -147,7 +147,7 @@ def test_device_has_updates_parse_errors(client, mocker): with pytest.raises(ParseError): device.has_updates() assert device._connection.poll.call_count == 1 - assert {9: 0, 10: 0} == device._lastIds + assert {9: 0, 10: 0} == device._last_ids def test_device_update_success(client, mocker): @@ -204,7 +204,7 @@ def test_device_update_success(client, mocker): assert device.inputs_alerted == inputs_alerted assert device.inputs_wait == inputs_wait assert device.alerts == alerts - assert device._lastIds == { + assert device._last_ids == { q.SECTORS: 4, q.INPUTS: 42, }