mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Catch potential ValueError when getting or setting Starlink sleep values (#114607)
This commit is contained in:
parent
4a93b4a4b4
commit
385da75963
@ -10,6 +10,7 @@ import math
|
|||||||
from homeassistant.components.time import TimeEntity, TimeEntityDescription
|
from homeassistant.components.time import TimeEntity, TimeEntityDescription
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@ -62,14 +63,22 @@ class StarlinkTimeEntity(StarlinkEntity, TimeEntity):
|
|||||||
def _utc_minutes_to_time(utc_minutes: int, timezone: tzinfo) -> time:
|
def _utc_minutes_to_time(utc_minutes: int, timezone: tzinfo) -> time:
|
||||||
hour = math.floor(utc_minutes / 60)
|
hour = math.floor(utc_minutes / 60)
|
||||||
minute = utc_minutes % 60
|
minute = utc_minutes % 60
|
||||||
utc = datetime.now(UTC).replace(hour=hour, minute=minute, second=0, microsecond=0)
|
try:
|
||||||
|
utc = datetime.now(UTC).replace(
|
||||||
|
hour=hour, minute=minute, second=0, microsecond=0
|
||||||
|
)
|
||||||
|
except ValueError as exc:
|
||||||
|
raise HomeAssistantError from exc
|
||||||
return utc.astimezone(timezone).time()
|
return utc.astimezone(timezone).time()
|
||||||
|
|
||||||
|
|
||||||
def _time_to_utc_minutes(t: time, timezone: tzinfo) -> int:
|
def _time_to_utc_minutes(t: time, timezone: tzinfo) -> int:
|
||||||
zoned_time = datetime.now(timezone).replace(
|
try:
|
||||||
hour=t.hour, minute=t.minute, second=0, microsecond=0
|
zoned_time = datetime.now(timezone).replace(
|
||||||
)
|
hour=t.hour, minute=t.minute, second=0, microsecond=0
|
||||||
|
)
|
||||||
|
except ValueError as exc:
|
||||||
|
raise HomeAssistantError from exc
|
||||||
utc_time = zoned_time.astimezone(UTC).time()
|
utc_time = zoned_time.astimezone(UTC).time()
|
||||||
return (utc_time.hour * 60) + utc_time.minute
|
return (utc_time.hour * 60) + utc_time.minute
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user