From c3fd0dbdb0972c7f5394da7a3a6ff57a1f12fd3d Mon Sep 17 00:00:00 2001 From: Boris Fersing Date: Sat, 20 Dec 2025 21:31:12 +0000 Subject: [PATCH 1/4] Add reward field --- pyhilo/event.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyhilo/event.py b/pyhilo/event.py index 6b50e6c..2032ab9 100755 --- a/pyhilo/event.py +++ b/pyhilo/event.py @@ -1,4 +1,5 @@ -"""Event object """ +"""Event object""" + from datetime import datetime, timedelta, timezone import logging import re @@ -26,7 +27,7 @@ class Event: def __init__(self, **event: dict[str, Any]): """Initialize.""" - self._convert_phases(cast(dict[str, Any], event.get("phases"))) + self._convert_phases(cast(dict[str, Any], event.get("phases", {}))) params: dict[str, Any] = event.get("parameters") or {} devices: list[dict[str, Any]] = params.get("devices", []) consumption: dict[str, Any] = event.get("consumption", {}) @@ -44,6 +45,7 @@ def __init__(self, **event: dict[str, Any]): self.allowed_kWh: float = round(allowed_wH / 1000, 2) self.used_kWh: float = round(used_wH / 1000, 2) self.used_percentage: float = 0 + self.reward = cast(float, event.get("reward", 0.0)) self.last_update = datetime.now(timezone.utc).astimezone() if allowed_wH > 0: self.used_percentage = round(used_wH / allowed_wH * 100, 2) @@ -63,6 +65,7 @@ def __init__(self, **event: dict[str, Any]): "used_kWh", "used_percentage", "last_update", + "reward", ] def update_wh(self, used_wH: float) -> None: From d4602667824e9c1f828845398dd1945e57f9a70e Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Sat, 3 Jan 2026 13:09:23 -0500 Subject: [PATCH 2/4] Correctif version --- pyhilo/const.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyhilo/const.py b/pyhilo/const.py index b16f963..63fe71f 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.12.05" +PYHILO_VERSION: Final = "2026.1.01" # 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 a3021cf..adf705d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ exclude = ".venv/.*" [tool.poetry] name = "python-hilo" -version = "2025.12.5" +version = "2026.1.6" description = "A Python3, async interface to the Hilo API" readme = "README.md" authors = ["David Vallee Delisle "] From aecd359199afae9aa9e4c1b6aedb5e89aa07da6b Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Sun, 4 Jan 2026 12:13:13 -0500 Subject: [PATCH 3/4] Update event.py Make sure event stays lowercase --- pyhilo/event.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyhilo/event.py b/pyhilo/event.py index 2032ab9..ea84476 100755 --- a/pyhilo/event.py +++ b/pyhilo/event.py @@ -35,7 +35,7 @@ def __init__(self, **event: dict[str, Any]): used_wH: int = consumption.get("currentWh", 0) or 0 self.participating: bool = cast(bool, event.get("isParticipating", False)) self.configurable: bool = cast(bool, event.get("isConfigurable", False)) - self.period: str = cast(str, event.get("period", "")) + self.period: str = (cast(str, event.get("period", "")) or "").lower() self.event_id: int = cast(int, event["id"]) self.total_devices: int = len(devices) self.opt_out_devices: int = len([x for x in devices if x["optOut"]]) From e5d76d2e9a33798082cc4bb8602a3adbd419db02 Mon Sep 17 00:00:00 2001 From: "Ian C." <108159253+ic-dev21@users.noreply.github.com> Date: Sun, 4 Jan 2026 17:46:48 -0500 Subject: [PATCH 4/4] Update event.py Ajout d'un update dynamique du used percentage --- pyhilo/event.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pyhilo/event.py b/pyhilo/event.py index ea84476..fd8a0a5 100755 --- a/pyhilo/event.py +++ b/pyhilo/event.py @@ -73,12 +73,21 @@ def update_wh(self, used_wH: float) -> None: LOG.debug("Updating Wh: %s", used_wH) self.used_kWh = round(used_wH / 1000, 2) self.last_update = datetime.now(timezone.utc).astimezone() + self._recalculate_percentage() def update_allowed_wh(self, allowed_wH: float) -> None: """This function is used to update the allowed_kWh attribute during a Hilo Challenge Event""" LOG.debug("Updating allowed Wh: %s", allowed_wH) self.allowed_kWh = round(allowed_wH / 1000, 2) self.last_update = datetime.now(timezone.utc).astimezone() + self._recalculate_percentage() + + def _recalculate_percentage(self) -> None: + """Recalculate used percentage based on current values""" + if self.allowed_kWh > 0: + self.used_percentage = round(self.used_kWh / self.allowed_kWh * 100, 2) + else: + self.used_percentage = 0 def should_check_for_allowed_wh(self) -> bool: """This function is used to authorize subscribing to a specific event in Hilo to receive the allowed_kWh