Increase uptime deviation for Shelly (#142996)

* Increase uptime deviation for Shelly

* fix test

* make troubleshooting easy

* change deviation interval

* increase deviation to 1m
This commit is contained in:
Simone Chemelli 2025-04-16 14:02:27 +02:00 committed by Franck Nijhof
parent e240707b32
commit 74c4553bb0
No known key found for this signature in database
GPG Key ID: AB33ADACE7101952
3 changed files with 16 additions and 4 deletions

View File

@ -209,7 +209,7 @@ KELVIN_MIN_VALUE_COLOR: Final = 3000
BLOCK_WRONG_SLEEP_PERIOD = 21600
BLOCK_EXPECTED_SLEEP_PERIOD = 43200
UPTIME_DEVIATION: Final = 5
UPTIME_DEVIATION: Final = 60
# Time to wait before reloading entry upon device config change
ENTRY_RELOAD_COOLDOWN = 60

View File

@ -200,8 +200,18 @@ def get_device_uptime(uptime: float, last_uptime: datetime | None) -> datetime:
if (
not last_uptime
or abs((delta_uptime - last_uptime).total_seconds()) > UPTIME_DEVIATION
or (diff := abs((delta_uptime - last_uptime).total_seconds()))
> UPTIME_DEVIATION
):
if last_uptime:
LOGGER.debug(
"Time deviation %s > %s: uptime=%s, last_uptime=%s, delta_uptime=%s",
diff,
UPTIME_DEVIATION,
uptime,
last_uptime,
delta_uptime,
)
return delta_uptime
return last_uptime

View File

@ -21,6 +21,7 @@ from homeassistant.components.shelly.const import (
GEN1_RELEASE_URL,
GEN2_BETA_RELEASE_URL,
GEN2_RELEASE_URL,
UPTIME_DEVIATION,
)
from homeassistant.components.shelly.utils import (
get_block_channel_name,
@ -188,8 +189,9 @@ async def test_get_device_uptime() -> None:
) == dt_util.as_utc(dt_util.parse_datetime("2019-01-10 18:42:00+00:00"))
assert get_device_uptime(
50, dt_util.as_utc(dt_util.parse_datetime("2019-01-10 18:42:00+00:00"))
) == dt_util.as_utc(dt_util.parse_datetime("2019-01-10 18:42:10+00:00"))
55 - UPTIME_DEVIATION,
dt_util.as_utc(dt_util.parse_datetime("2019-01-10 18:42:00+00:00")),
) == dt_util.as_utc(dt_util.parse_datetime("2019-01-10 18:43:05+00:00"))
async def test_get_block_input_triggers(