Fix calculation of Starlink sleep end setting (#115507)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Jack Boswell 2024-06-05 07:19:09 +12:00 committed by GitHub
parent b4f6325278
commit 278751607f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -119,12 +119,16 @@ class StarlinkUpdateCoordinator(DataUpdateCoordinator[StarlinkData]):
async def async_set_sleep_duration(self, end: int) -> None: async def async_set_sleep_duration(self, end: int) -> None:
"""Set Starlink system sleep schedule end time.""" """Set Starlink system sleep schedule end time."""
duration = end - self.data.sleep[0]
if duration < 0:
# If the duration pushed us into the next day, add one days worth to correct that.
duration += 1440
async with asyncio.timeout(4): async with asyncio.timeout(4):
try: try:
await self.hass.async_add_executor_job( await self.hass.async_add_executor_job(
set_sleep_config, set_sleep_config,
self.data.sleep[0], self.data.sleep[0],
end, duration,
self.data.sleep[2], self.data.sleep[2],
self.channel_context, self.channel_context,
) )

View file

@ -62,6 +62,8 @@ 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)
if hour > 23:
hour -= 24
minute = utc_minutes % 60 minute = utc_minutes % 60
try: try:
utc = datetime.now(UTC).replace( utc = datetime.now(UTC).replace(