Skip to content

Commit 78b236e

Browse files
authored
feat!: add missing keys for q.OUTPUTS queries (#130)
1 parent 090c658 commit 78b236e

File tree

3 files changed

+44
-41
lines changed

3 files changed

+44
-41
lines changed

src/elmo/api/client.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -602,46 +602,23 @@ def query(self, query):
602602
HTTPError: if there is an error raised by the API (not 2xx response).
603603
ParseError: if the response cannot be parsed because the format is unexpected.
604604
Returns:
605-
A dict representing the raw query retrieved by the backend call. The structure is the following:
606-
{
607-
'last_id': 3,
608-
'sectors': {
609-
0: {
610-
'id': 1,
611-
'index': 0,
612-
'element': 1,
613-
'excluded': False,
614-
'status': True,
615-
'name': 'S1 Living Room'
616-
},
617-
1: {
618-
'id': 2,
619-
'index': 1,
620-
'element': 2,
621-
'excluded': False,
622-
'status': True,
623-
'name': 'S2 Bedroom'
624-
},
625-
},
626-
}
605+
A dict representing the raw query retrieved by the backend call.
606+
627607
`last_id`: is the last ID of the query, used to retrieve new state changes
628608
`sectors`: is the key you use to retrieve sectors if that was the query
629609
`inputs`: is the key you use to retrieve inputs if that was the query
630610
'outputs`: is the key you use to retrieve outputs if that was the query
631611
"""
632612
# Query detection
633613
if query == q.SECTORS:
634-
status = "Active"
635614
key_group = "sectors"
636615
endpoint = self._router.sectors
637616
_LOGGER.debug("Client | Querying sectors")
638617
elif query == q.INPUTS:
639-
status = "Alarm"
640618
key_group = "inputs"
641619
endpoint = self._router.inputs
642620
_LOGGER.debug("Client | Querying inputs")
643621
elif query == q.OUTPUTS:
644-
status = "Active"
645622
key_group = "outputs"
646623
endpoint = self._router.outputs
647624
_LOGGER.debug("Client | Querying outputs")
@@ -678,16 +655,39 @@ def query(self, query):
678655
# providing a sector/input/output that doesn't actually exist in the main unit.
679656
# To handle this, we default the name to "Unknown" if its description
680657
# isn't found in the cloud data to prevent KeyError.
681-
name = descriptions[query].get(entry["Index"], "Unknown")
682658
item = {
683659
"id": entry.get("Id"),
684660
"index": entry.get("Index"),
685661
"element": entry.get("Element"),
686-
"excluded": entry.get("Excluded", False),
687-
"status": entry.get(status, False),
688-
"name": name,
662+
"name": descriptions[query].get(entry["Index"], "Unknown"),
689663
}
690664

665+
if query == q.SECTORS:
666+
item.update(
667+
{
668+
"activable": entry.get("Activable", False),
669+
"status": entry.get("Active", False),
670+
}
671+
)
672+
_LOGGER.debug("Client | Querying sectors")
673+
elif query == q.INPUTS:
674+
item.update(
675+
{
676+
"excluded": entry.get("Excluded", False),
677+
"status": entry.get("Alarm", False),
678+
}
679+
)
680+
_LOGGER.debug("Client | Querying inputs")
681+
elif query == q.OUTPUTS:
682+
item.update(
683+
{
684+
"do_not_require_authentication": entry.get("DoNotRequireAuthentication", False),
685+
"control_denied_to_users": entry.get("ControlDeniedToUsers", False),
686+
"status": entry.get("Active", False),
687+
}
688+
)
689+
_LOGGER.debug("Client | Querying outputs")
690+
691691
items[entry.get("Index")] = item
692692
except KeyError as err:
693693
raise ParseError(f"Client | Unable to parse query response: {err}") from err

tests/fixtures/responses.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def test_client_get_sectors_status(server):
199199
"Active": false,
200200
"ActivePartial": false,
201201
"Max": false,
202-
"Activable": true,
202+
"Activable": false,
203203
"ActivablePartial": false,
204204
"InUse": true,
205205
"Id": 3,
@@ -299,7 +299,7 @@ def test_client_get_sectors_status(server):
299299
"Active": false,
300300
"InUse": true,
301301
"DoNotRequireAuthentication": false,
302-
"ControlDeniedToUsers": false,
302+
"ControlDeniedToUsers": true,
303303
"Id": 400260,
304304
"Index": 2,
305305
"Element": 3,

tests/test_client.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,7 @@ def test_client_get_sectors_status(server, mocker):
16691669
"Active": false,
16701670
"ActivePartial": false,
16711671
"Max": false,
1672-
"Activable": true,
1672+
"Activable": false,
16731673
"ActivablePartial": false,
16741674
"InUse": true,
16751675
"Id": 3,
@@ -1713,23 +1713,23 @@ def test_client_get_sectors_status(server, mocker):
17131713
"id": 1,
17141714
"index": 0,
17151715
"status": True,
1716-
"excluded": False,
1716+
"activable": True,
17171717
"name": "Living Room",
17181718
},
17191719
1: {
17201720
"element": 2,
17211721
"id": 2,
17221722
"index": 1,
17231723
"status": True,
1724-
"excluded": False,
1724+
"activable": True,
17251725
"name": "Bedroom",
17261726
},
17271727
2: {
17281728
"element": 3,
17291729
"id": 3,
17301730
"index": 2,
17311731
"status": False,
1732-
"excluded": False,
1732+
"activable": False,
17331733
"name": "Kitchen",
17341734
},
17351735
},
@@ -1861,7 +1861,7 @@ def test_client_get_outputs_status(server, mocker):
18611861
"Active": false,
18621862
"InUse": true,
18631863
"DoNotRequireAuthentication": false,
1864-
"ControlDeniedToUsers": false,
1864+
"ControlDeniedToUsers": true,
18651865
"Id": 400260,
18661866
"Index": 2,
18671867
"Element": 3,
@@ -1902,23 +1902,26 @@ def test_client_get_outputs_status(server, mocker):
19021902
"id": 400258,
19031903
"index": 0,
19041904
"status": True,
1905-
"excluded": False,
1905+
"control_denied_to_users": False,
1906+
"do_not_require_authentication": True,
19061907
"name": "Output 1",
19071908
},
19081909
1: {
19091910
"element": 2,
19101911
"id": 400259,
19111912
"index": 1,
19121913
"status": False,
1913-
"excluded": False,
1914+
"control_denied_to_users": False,
1915+
"do_not_require_authentication": False,
19141916
"name": "Output 2",
19151917
},
19161918
2: {
19171919
"element": 3,
19181920
"id": 400260,
19191921
"status": False,
19201922
"index": 2,
1921-
"excluded": False,
1923+
"control_denied_to_users": True,
1924+
"do_not_require_authentication": False,
19221925
"name": "Output 3",
19231926
},
19241927
},
@@ -1973,15 +1976,15 @@ def test_client_get_sectors_missing_area(server, mocker):
19731976
"id": 1,
19741977
"index": 0,
19751978
"status": True,
1976-
"excluded": False,
1979+
"activable": True,
19771980
"name": "Living Room",
19781981
},
19791982
1: {
19801983
"element": 2,
19811984
"id": 2,
19821985
"index": 1,
19831986
"status": True,
1984-
"excluded": False,
1987+
"activable": True,
19851988
"name": "Unknown",
19861989
},
19871990
},

0 commit comments

Comments
 (0)