Skip to content

Commit

Permalink
refactor: rename lastIds in last_ids (snake case)
Browse files Browse the repository at this point in the history
  • Loading branch information
palazzem committed Oct 12, 2023
1 parent ccf4a67 commit 5debab3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions custom_components/econnect_metronet/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions tests/test_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == []
Expand All @@ -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]
Expand Down Expand Up @@ -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()
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit 5debab3

Please sign in to comment.