Skip to content

Commit

Permalink
feat: add capability to AlarmDevice to retrieve panel details (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
palazzem authored Feb 2, 2024
1 parent 5daa5ee commit c0866ef
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 6 deletions.
8 changes: 8 additions & 0 deletions custom_components/econnect_metronet/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def __init__(self, connection, config=None):
# Alarm state
self.state = STATE_UNAVAILABLE

@property
def panel(self):
"""Return the panel status."""
return self._inventory.get(q.PANEL, {})

@property
def inputs(self):
"""Iterate over the device's inventory of inputs.
Expand Down Expand Up @@ -257,6 +262,7 @@ def update(self):
inputs = self._connection.query(q.INPUTS)
outputs = self._connection.query(q.OUTPUTS)
alerts = self._connection.query(q.ALERTS)
panel = self._connection.query(q.PANEL)
except HTTPError as err:
_LOGGER.error(f"Device | Error during the update: {err.response.text}")
raise err
Expand All @@ -269,12 +275,14 @@ def update(self):
self._inventory.update({q.INPUTS: inputs["inputs"]})
self._inventory.update({q.OUTPUTS: outputs["outputs"]})
self._inventory.update({q.ALERTS: alerts["alerts"]})
self._inventory.update({q.PANEL: panel["panel"]})

# Update the _last_ids
self._last_ids[q.SECTORS] = sectors.get("last_id", 0)
self._last_ids[q.INPUTS] = inputs.get("last_id", 0)
self._last_ids[q.OUTPUTS] = outputs.get("last_id", 0)
self._last_ids[q.ALERTS] = alerts.get("last_id", 0)
self._last_ids[q.PANEL] = panel.get("last_id", 0)

# Update the internal state machine (mapping state)
self.state = self.get_state()
Expand Down
2 changes: 1 addition & 1 deletion custom_components/econnect_metronet/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"elmo"
],
"requirements": [
"econnect-python==0.10.0"
"econnect-python==0.11.0b0"
],
"version": "2.2.1"
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
]
dependencies = [
"econnect-python==0.10.0",
"econnect-python==0.11.0b0",
"async_timeout",
"homeassistant",
]
Expand Down
68 changes: 65 additions & 3 deletions tests/fixtures/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,78 @@ def test_client_get_sectors_status(server):
"Domain": "domain",
"Language": "en",
"IsActivated": true,
"ShowTimeZoneControls": true,
"TimeZone": "(UTC+01:00) Amsterdam, Berlino, Berna, Roma, Stoccolma, Vienna",
"ShowChronothermostat": false,
"ShowThumbnails": false,
"ShowExtinguish": false,
"IsConnected": true,
"IsLoggedIn": false,
"IsLoginInProgress": false,
"CanElevate": true,
"Panel": {
"Description": "T-800 1.0.1",
"LastConnection": "01/01/1984 13:27:28",
"LastDisconnection": "01/10/1984 13:27:18",
"Major": 1,
"Minor": 0,
"SourceIP": "10.0.0.1",
"ConnectionType": "EthernetWiFi",
"DeviceClass": 92,
"Revision": 1,
"Build": 1,
"Brand": 0,
"Language": 0,
"Areas": 4,
"SectorsPerArea": 4,
"TotalSectors": 16,
"Inputs": 24,
"Outputs": 24,
"Operators": 64,
"SectorsInUse": [
true,
true,
true,
true,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false
],
"Model": "T-800",
"LoginWithoutUserID": true,
"AdditionalInfoSupported": 1,
"IsFirePanel": false
},
"AccountId": 100,
"ManagedAccounts": [
{
"Id": 1,
"FullUsername": "domain\\\\test"
}
],
"IsManaged": false,
"Message": "",
"DVRPort": "",
"ExtendedAreaInfoOnStatusPage": true,
"DefaultPage": "Status",
"NotificationTitle": "",
"NotificationText": "",
"NotificationDontShowAgain": true,
"Redirect": false,
"IsElevation": false
}
"""
"IsElevation": false,
"InstallerForceSupervision": true,
"PrivacyLink": "/PrivacyAndTerms/v1/Informativa_privacy_econnect_2020_09.pdf",
"TermsLink": "/PrivacyAndTerms/v1/CONTRATTO_UTILIZZATORE_FINALE_2020_02_07.pdf"
}"""
UPDATES = """
{
"ConnectionStatus": false,
Expand Down
42 changes: 42 additions & 0 deletions tests/test_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,48 @@ async def test_coordinator_async_update_with_data(mocker, coordinator):
# Test
await coordinator.async_refresh()
assert coordinator.data == {
0: {
"additional_info_supported": 1,
"areas": 4,
"brand": 0,
"build": 1,
"connection_type": "EthernetWiFi",
"description": "T-800 1.0.1",
"device_class": 92,
"inputs": 24,
"is_fire_panel": False,
"language": 0,
"last_connection": "01/01/1984 13:27:28",
"last_disconnection": "01/10/1984 13:27:18",
"login_without_user_id": True,
"major": 1,
"minor": 0,
"model": "T-800",
"operators": 64,
"outputs": 24,
"revision": 1,
"sectors_in_use": [
True,
True,
True,
True,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
False,
],
"sectors_per_area": 4,
"source_ip": "10.0.0.1",
"total_sectors": 16,
},
11: {
0: {"name": "alarm_led", "status": 0},
1: {"name": "anomalies_led", "status": 1},
Expand Down
Loading

0 comments on commit c0866ef

Please sign in to comment.