Skip to content

Commit a8ef67b

Browse files
authored
Merge pull request #241 from fersingb/update_kwh
Ugly quick fix to update the kwh values
2 parents cd9f9b0 + 3616ea4 commit a8ef67b

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

pyhilo/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ async def _async_post_init(self) -> None:
385385
# instantiate differently
386386
self.websocket_devices = WebsocketClient(self.websocket_manager.devicehub)
387387

388-
# For backward compatibility during the transition to challengehub websocket
388+
# For backward compatibility during the transition to challengehub websocket
389389
self.websocket = self.websocket_devices
390390
self.websocket_challenges = WebsocketClient(self.websocket_manager.challengehub)
391391

pyhilo/const.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
LOG: Final = logging.getLogger(__package__)
99
DEFAULT_STATE_FILE: Final = "hilo_state.yaml"
1010
REQUEST_RETRY: Final = 9
11-
PYHILO_VERSION: Final = "2025.2.01"
11+
PYHILO_VERSION: Final = "2025.2.02"
1212
# TODO: Find a way to keep previous line in sync with pyproject.toml automatically
1313

1414
CONTENT_TYPE_FORM: Final = "application/x-www-form-urlencoded"

pyhilo/event.py

+18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
class Event:
13+
"""This class is used to populate the data of a Hilo Challenge Event, contains datetime info and consumption data"""
1314
setting_deadline: datetime
1415
pre_cold_start: datetime
1516
pre_cold_end: datetime
@@ -62,13 +63,28 @@ def __init__(self, **event: dict[str, Any]):
6263
"last_update",
6364
]
6465

66+
def update_wh(self, used_wH: float) -> None:
67+
"""This function is used to update the used_kWh attribute during a Hilo Challenge Event"""
68+
LOG.debug(f"Updating Wh: {used_wH}")
69+
self.used_kWh = round(used_wH / 1000, 2)
70+
self.last_update = datetime.now(timezone.utc).astimezone()
71+
72+
def should_check_for_allowed_wh(self) -> bool:
73+
"""This function is used to authorize subscribing to a specific event in Hilo to receive the allowed_kWh
74+
that is made available in the pre_heat phase"""
75+
now = datetime.now(self.preheat_start.tzinfo)
76+
time_since_preheat_start = (self.preheat_start - now).total_seconds()
77+
already_has_allowed_wh = self.allowed_kWh > 0
78+
return 1800 <= time_since_preheat_start <= 2700 and not already_has_allowed_wh
79+
6580
def as_dict(self) -> dict[str, Any]:
6681
rep = {k: getattr(self, k) for k in self.dict_items}
6782
rep["phases"] = {k: getattr(self, k) for k in self.phases_list}
6883
rep["state"] = self.state
6984
return rep
7085

7186
def _convert_phases(self, phases: dict[str, Any]) -> None:
87+
"""Formats phase times for later use"""
7288
self.phases_list = []
7389
for key, value in phases.items():
7490
phase_match = re.match(r"(.*)(DateUTC|Utc)", key)
@@ -89,6 +105,7 @@ def _convert_phases(self, phases: dict[str, Any]) -> None:
89105
def _create_phases(
90106
self, hours: int, phase_name: str, parent_phase: str
91107
) -> datetime:
108+
"""Creates optional "appreciation" and "pre_cold" phases according to Hilo phases datetimes"""
92109
parent_start = getattr(self, f"{parent_phase}_start")
93110
phase_start = f"{phase_name}_start"
94111
phase_end = f"{phase_name}_end"
@@ -128,6 +145,7 @@ def current_phase_times(self) -> dict[str, datetime]:
128145

129146
@property
130147
def state(self) -> str:
148+
"""Defines state in the next_event attribute"""
131149
now = datetime.now(self.preheat_start.tzinfo)
132150
if self.pre_cold_start and self.pre_cold_start <= now < self.pre_cold_end:
133151
return "pre_cold"

pyhilo/util/__init__.py

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Define utility modules."""
22
import asyncio
33
from datetime import datetime, timedelta
4-
import logging
54
import re
65
from typing import Any, Callable
76

@@ -10,9 +9,6 @@
109

1110
from pyhilo.const import LOG # noqa: F401
1211

13-
LOG = logging.getLogger(__package__)
14-
15-
1612
CAMEL_REX_1 = re.compile("(.)([A-Z][a-z]+)")
1713
CAMEL_REX_2 = re.compile("([a-z0-9])([A-Z])")
1814

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ exclude = ".venv/.*"
4040

4141
[tool.poetry]
4242
name = "python-hilo"
43-
version = "2025.2.1"
43+
version = "2025.2.2"
4444
description = "A Python3, async interface to the Hilo API"
4545
readme = "README.md"
4646
authors = ["David Vallee Delisle <[email protected]>"]

0 commit comments

Comments
 (0)