Skip to content

Commit 1c54f16

Browse files
committed
whenever
1 parent 7d887dd commit 1c54f16

5 files changed

Lines changed: 15 additions & 14 deletions

File tree

‎hass-addon-sunsynk-edge/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All items below are changes since add-on **1.3.0**.
88

99
- Failed Modbus writes no longer update the local register cache. #692
1010
- Fix AsyncCallback checks. #693
11+
- Bump whenever to 0.11
1112

1213
## Release 1.3.0
1314

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies = [
3434
"modbus-connection[pymodbus,tmodbus]>=4.7",
3535
"mqtt-entity[options]>=1.2.5",
3636
"prettytable>=3.17,<4",
37-
"whenever>=0.10,<11",
37+
"whenever>=0.11,<0.12",
3838
]
3939
optional-dependencies.solarman = [ "pysolarmanv5==3.0.6" ]
4040
urls.Homepage = "https://kellerza.github.io/sunsynk/"

‎src/ha_addon_sunsynk_multi/timer_callback.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections.abc import Awaitable, Callable
77
from dataclasses import dataclass, field
88

9-
from whenever import Time, ZonedDateTime
9+
from whenever import SYSTEM_TZ, Time, ZonedDateTime
1010

1111
from sunsynk.helpers import slug
1212

@@ -90,7 +90,7 @@ class ToggleLogCallback(Callback):
9090

9191
def calc_next_run(self) -> None:
9292
"""Calculate the next run times."""
93-
now = ZonedDateTime.now_in_system_tz()
93+
now = ZonedDateTime.now(SYSTEM_TZ)
9494
self.next_runs = [
9595
n if n > now else n.add(days=1)
9696
for n in (now.replace_time(t) for t in self.times)
@@ -101,19 +101,19 @@ def calc_next_run(self) -> None:
101101
@property
102102
def next_run0(self) -> int:
103103
"""Return next run seconds of entry 0."""
104-
return self.next_runs[0].timestamp_millis() // 1000
104+
return self.next_runs[0].timestamp(unit="millisecond") // 1000
105105

106106
def __post_init__(self) -> None:
107107
"""Init."""
108108
assert len(self.times) > 0
109-
self.next_runs = [ZonedDateTime.now_in_system_tz()]
109+
self.next_runs = [ZonedDateTime.now(SYSTEM_TZ)]
110110
self.task = None # type:ignore[assignment]
111111
self.calc_next_run()
112112
self.original_level = _LOG.level
113113

114114
async def mute_log(self) -> None:
115115
"""Set log level to critical, and reset after duration."""
116-
now, _, _ = ZonedDateTime.now_in_system_tz().format_iso().partition("T")
116+
now, _, _ = ZonedDateTime.now(SYSTEM_TZ).format_iso().partition("T")
117117
_LOG.info(
118118
"[%s] Disabling the log for %s seconds",
119119
now,
@@ -184,7 +184,7 @@ async def run_callbacks(callbacks: list[Callback]) -> None:
184184
"""Run the timer."""
185185
while True:
186186
now_s = 0
187-
now_ms = ZonedDateTime.now_in_system_tz().timestamp_millis()
187+
now_ms = ZonedDateTime.now(SYSTEM_TZ).timestamp(unit="millisecond")
188188
for cb in callbacks:
189189
if now_ms < cb.due_at_ms():
190190
continue

‎src/tests/ha_addon_sunsynk_multi/test_timer.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ def run2(now: int) -> None:
5757
):
5858
now_ms = 2000
5959

60-
def get_now() -> MagicMock:
60+
def get_now(*_a: object, **_k: object) -> MagicMock:
6161
nonlocal now_ms
6262
if now_ms > 19990:
6363
raise IndexError
6464
res = MagicMock()
65-
res.timestamp_millis.return_value = now_ms
65+
res.timestamp.return_value = now_ms
6666
now_ms += TICK_MS
6767
return res
6868

69-
mock_zdt.now_in_system_tz.side_effect = get_now
69+
mock_zdt.now.side_effect = get_now
7070

7171
try:
7272
await run_callbacks(cbs)
@@ -115,17 +115,17 @@ def cb_c(_now: int) -> None:
115115
),
116116
):
117117

118-
def get_now() -> MagicMock:
118+
def get_now(*_a: object, **_k: object) -> MagicMock:
119119
nonlocal now_ms
120120
if now_ms > 2990:
121121
raise IndexError
122122
last_now_ms[0] = now_ms
123123
res = MagicMock()
124-
res.timestamp_millis.return_value = now_ms
124+
res.timestamp.return_value = now_ms
125125
now_ms += TICK_MS
126126
return res
127127

128-
mock_zdt.now_in_system_tz.side_effect = get_now
128+
mock_zdt.now.side_effect = get_now
129129

130130
try:
131131
await run_callbacks(cbs)

‎uv.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)