Skip to content

Commit

Permalink
Merge pull request #26 from zachberger/master
Browse files Browse the repository at this point in the history
Capture firmware version from local devices
  • Loading branch information
ahayworth authored Aug 16, 2022
2 parents d3cff1c + a3ed591 commit 49cdda1
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ async def fetch_data():

# Print things out!
print(f"Device: {devices[0]}")
print(f"Device firmware: {devices[0].fw_version}")

# You can access sensors as dict items:
for sensor, value in data.sensors.items():
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "python-awair"
version = "0.2.3"
description = "asyncio client for the Awair GraphQL API"
version = "0.2.4"
description = "asyncio client for the Awair GraphQL and Local APIs"
authors = ["Andrew Hayworth <[email protected]>"]
license = "MIT"
readme = "README.md"
Expand Down
4 changes: 4 additions & 0 deletions python_awair/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ class AwairLocalDevice(AwairBaseDevice):
device_addr: str
"""The DNS or IP address of the device."""

fw_version: str
"""The firmware version currently running on the device."""

def __init__(
self, client: AwairClient, device_addr: str, attributes: Dict[str, Any]
):
Expand All @@ -451,6 +454,7 @@ def __init__(
attributes["macAddress"] = attributes.get("wifi_mac", None)
super().__init__(client, attributes)
self.device_addr = device_addr
self.fw_version = attributes.get("fw_version", None)

def _get_airdata_base_url(self) -> str:
"""Get the base URL to use for airdata."""
Expand Down
2 changes: 2 additions & 0 deletions tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
"deviceId": 6049,
"deviceType": "awair-element",
"deviceUUID": "awair-element_6049",
"fw_version": "1.1.5",
}
MOCK_ELEMENT_DEVICE_B_ATTRS = {
"deviceId": 5366,
"deviceType": "awair-element",
"deviceUUID": "awair-element_5366",
"fw_version": "1.2.8",
}
2 changes: 1 addition & 1 deletion tests/fixtures/cassettes/local_devices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interactions:
uri: http://awair-elem-1419e1.local/settings/config/data
response:
body:
string: '{"device_uuid":"awair-element_5366","wifi_mac":"70:88:6B:14:19:E1","ssid":"morpac-east","ip":"192.168.1.225","netmask":"255.255.255.0","gateway":"none","fw_version":"1.1.5","timezone":"America/Los_Angeles","display":"co2","led":{"mode":"manual","brightness":73},"voc_feature_set":"Unknown"}'
string: '{"device_uuid":"awair-element_5366","wifi_mac":"70:88:6B:14:19:E1","ssid":"morpac-east","ip":"192.168.1.225","netmask":"255.255.255.0","gateway":"none","fw_version":"1.2.8","timezone":"America/Los_Angeles","display":"co2","led":{"mode":"manual","brightness":73},"voc_feature_set":"Unknown"}'
headers:
Access-Control-Allow-Origin: '*'
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expand Down
2 changes: 2 additions & 0 deletions tests/test_python_awair.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ async def test_get_local_devices() -> Any:
assert devices[0].device_id == MOCK_ELEMENT_DEVICE_A_ATTRS["deviceId"]
assert devices[0].device_type == MOCK_ELEMENT_DEVICE_A_ATTRS["deviceType"]
assert devices[0].uuid == MOCK_ELEMENT_DEVICE_A_ATTRS["deviceUUID"]
assert devices[0].fw_version == MOCK_ELEMENT_DEVICE_A_ATTRS["fw_version"]
assert "<AwairDevice" in str(devices[0])

assert devices[1].device_id == MOCK_ELEMENT_DEVICE_B_ATTRS["deviceId"]
assert devices[1].device_type == MOCK_ELEMENT_DEVICE_B_ATTRS["deviceType"]
assert devices[1].uuid == MOCK_ELEMENT_DEVICE_B_ATTRS["deviceUUID"]
assert devices[1].fw_version == MOCK_ELEMENT_DEVICE_B_ATTRS["fw_version"]
assert "<AwairDevice" in str(devices[1])


Expand Down

0 comments on commit 49cdda1

Please sign in to comment.