From fcc525f170c74eb37832897be2e24e7a88b4dc77 Mon Sep 17 00:00:00 2001 From: Abigail Asselin Date: Sun, 13 Apr 2025 17:54:23 -0400 Subject: [PATCH 1/4] Add support for whitebulb and normalize OnOff attribute state --- pyhilo/device/graphql_value_mapper.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/pyhilo/device/graphql_value_mapper.py b/pyhilo/device/graphql_value_mapper.py index cb66bf6..3d6aafc 100644 --- a/pyhilo/device/graphql_value_mapper.py +++ b/pyhilo/device/graphql_value_mapper.py @@ -57,6 +57,8 @@ def _map_devices_values(self, device: Dict[str, Any]) -> list[Dict[str, Any]]: attributes.extend(self._build_gateway(device)) case "colorbulb": attributes.extend(self._build_light(device)) + case "whitebulb": + attributes.extend(self._build_light(device)) case "dimmer": attributes.extend(self._build_dimmer(device)) case "switch": @@ -354,6 +356,11 @@ def _build_charge_controller(self, device: Dict[str, Any]) -> list[Dict[str, Any attributes.append( self.build_attribute(device["hiloId"], "CcrMode", device["ccrMode"]) ) + attributes.append( + self.build_attribute( + device["hiloId"], "OnOff", device["state"].lower() == "on" + ) + ) return attributes def _build_charging_point(self, device: Dict[str, Any]) -> list[Dict[str, Any]]: @@ -372,10 +379,14 @@ def _build_switch(self, device: Dict[str, Any]) -> list[Dict[str, Any]]: if device.get("power") is not None: attributes.append(self._map_power(device)) attributes.append( - self.build_attribute(device["hiloId"], "Status", device["state"]) + self.build_attribute( + device["hiloId"], "Status", device["state"].lower() == "on" + ) ) attributes.append( - self.build_attribute(device["hiloId"], "OnOff", device["state"]) + self.build_attribute( + device["hiloId"], "OnOff", device["state"].lower() == "on" + ) ) return attributes @@ -390,7 +401,9 @@ def _build_dimmer(self, device: Dict[str, Any]) -> list[Dict[str, Any]]: ) ) attributes.append( - self.build_attribute(device["hiloId"], "OnOff", device["state"]) + self.build_attribute( + device["hiloId"], "OnOff", device["state"].lower() == "on" + ) ) return attributes @@ -420,7 +433,9 @@ def _build_light(self, device: Dict[str, Any]) -> list[Dict[str, Any]]: ) ) attributes.append( - self.build_attribute(device["hiloId"], "OnOff", device["state"]) + self.build_attribute( + device["hiloId"], "OnOff", device["state"].lower() == "on" + ) ) return attributes From 7c9e99a017d0d6d329dcbb450ce7ece5b9752cef Mon Sep 17 00:00:00 2001 From: Abigail Asselin Date: Sun, 13 Apr 2025 17:57:43 -0400 Subject: [PATCH 2/4] Refactor OnOff state checks to use a constant for improved readability --- pyhilo/device/graphql_value_mapper.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pyhilo/device/graphql_value_mapper.py b/pyhilo/device/graphql_value_mapper.py index 3d6aafc..7750e7b 100644 --- a/pyhilo/device/graphql_value_mapper.py +++ b/pyhilo/device/graphql_value_mapper.py @@ -8,7 +8,8 @@ class GraphqlValueMapper: """ A class to map GraphQL values to DeviceReading instances. """ - + OnState = "on" + def map_query_values(self, values: Dict[str, Any]) -> list[Dict[str, Any]]: readings: list[Dict[str, Any]] = [] for device in values: @@ -358,7 +359,7 @@ def _build_charge_controller(self, device: Dict[str, Any]) -> list[Dict[str, Any ) attributes.append( self.build_attribute( - device["hiloId"], "OnOff", device["state"].lower() == "on" + device["hiloId"], "OnOff", device["state"].lower() == self.OnState ) ) return attributes @@ -380,12 +381,12 @@ def _build_switch(self, device: Dict[str, Any]) -> list[Dict[str, Any]]: attributes.append(self._map_power(device)) attributes.append( self.build_attribute( - device["hiloId"], "Status", device["state"].lower() == "on" + device["hiloId"], "Status", device["state"].lower() == self.OnState ) ) attributes.append( self.build_attribute( - device["hiloId"], "OnOff", device["state"].lower() == "on" + device["hiloId"], "OnOff", device["state"].lower() == self.OnState ) ) return attributes @@ -402,7 +403,7 @@ def _build_dimmer(self, device: Dict[str, Any]) -> list[Dict[str, Any]]: ) attributes.append( self.build_attribute( - device["hiloId"], "OnOff", device["state"].lower() == "on" + device["hiloId"], "OnOff", device["state"].lower() == self.OnState ) ) return attributes @@ -434,7 +435,7 @@ def _build_light(self, device: Dict[str, Any]) -> list[Dict[str, Any]]: ) attributes.append( self.build_attribute( - device["hiloId"], "OnOff", device["state"].lower() == "on" + device["hiloId"], "OnOff", device["state"].lower() == self.OnState ) ) return attributes From a893320df7fc7b5b20bcb503c167173d6de43b1b Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Mon, 14 Apr 2025 08:45:09 -0400 Subject: [PATCH 3/4] Bump up versions --- package.json | 2 +- pyhilo/const.py | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 6215273..64aa974 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "python-hilo", - "version": "2025.4.1", + "version": "2025.4.2", "private": true, "description": "A Python3, async interface to the Hilo API", "scripts": { diff --git a/pyhilo/const.py b/pyhilo/const.py index bc360ad..334d6b6 100755 --- a/pyhilo/const.py +++ b/pyhilo/const.py @@ -7,7 +7,7 @@ LOG: Final = logging.getLogger(__package__) DEFAULT_STATE_FILE: Final = "hilo_state.yaml" REQUEST_RETRY: Final = 9 -PYHILO_VERSION: Final = "2025.4.01" +PYHILO_VERSION: Final = "2025.4.02" # TODO: Find a way to keep previous line in sync with pyproject.toml automatically CONTENT_TYPE_FORM: Final = "application/x-www-form-urlencoded" diff --git a/pyproject.toml b/pyproject.toml index 6daf3c8..f5278e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ exclude = ".venv/.*" [tool.poetry] name = "python-hilo" -version = "2025.4.1" +version = "2025.4.2" description = "A Python3, async interface to the Hilo API" readme = "README.md" authors = ["David Vallee Delisle "] From 184fbe1f08bac0b390d4fe95eac7a67bf0922579 Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Mon, 14 Apr 2025 18:43:01 -0400 Subject: [PATCH 4/4] Linting --- pyhilo/device/graphql_value_mapper.py | 3 ++- pyhilo/util/state.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pyhilo/device/graphql_value_mapper.py b/pyhilo/device/graphql_value_mapper.py index 7750e7b..9ffc39d 100644 --- a/pyhilo/device/graphql_value_mapper.py +++ b/pyhilo/device/graphql_value_mapper.py @@ -8,8 +8,9 @@ class GraphqlValueMapper: """ A class to map GraphQL values to DeviceReading instances. """ + OnState = "on" - + def map_query_values(self, values: Dict[str, Any]) -> list[Dict[str, Any]]: readings: list[Dict[str, Any]] = [] for device in values: diff --git a/pyhilo/util/state.py b/pyhilo/util/state.py index 0fd3951..08fe3f1 100644 --- a/pyhilo/util/state.py +++ b/pyhilo/util/state.py @@ -58,6 +58,7 @@ class RegistrationDict(TypedDict, total=False): class FirebaseDict(TypedDict): """Represents a dictionary containing Firebase information.""" + fid: str | None name: str | None token: TokenDict