mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-15 16:24:04 +02:00
exception
This commit is contained in:
parent
8d4e0d12c1
commit
8ec62305f0
1 changed files with 13 additions and 4 deletions
|
|
@ -40,7 +40,7 @@ from homeassistant.const import (
|
|||
SUN_EVENT_SUNRISE,
|
||||
SUN_EVENT_SUNSET,
|
||||
)
|
||||
from homeassistant.core import Context, Event, ServiceCall
|
||||
from homeassistant.core import Context, Event, ServiceCall, callback
|
||||
from homeassistant.helpers import entity_platform
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.event import (
|
||||
|
|
@ -393,7 +393,8 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
self._state = False
|
||||
self._remove_listeners()
|
||||
|
||||
async def _update_attrs(self):
|
||||
@callback
|
||||
def _update_attrs(self):
|
||||
"""Update Adaptive Values."""
|
||||
# Setting all values because this method takes <0.5ms to execute.
|
||||
self._percent = self._calc_percent()
|
||||
|
|
@ -418,7 +419,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
force: bool = False,
|
||||
context: Optional[Context] = None,
|
||||
):
|
||||
await self._update_attrs()
|
||||
self._update_attrs()
|
||||
if self._only_once and not force:
|
||||
return
|
||||
await self._adapt_lights(lights or self._lights, transition, context)
|
||||
|
|
@ -464,7 +465,15 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
# Check whether order is correct
|
||||
events = sorted(events, key=lambda x: x[1])
|
||||
events_names, _ = zip(*events)
|
||||
assert events_names in _ALLOWED_ORDERS, events_names
|
||||
if events_names not in _ALLOWED_ORDERS:
|
||||
msg = (
|
||||
f"{self._name}: The sun events {events_names} are not in the expected"
|
||||
" order. The Adaptive Lighting integration will not work!"
|
||||
" This might happen if your sunrise/sunset offset is too large or"
|
||||
" your manually set sunrise/sunset time is past/before noon/midnight."
|
||||
)
|
||||
_LOGGER.error(msg)
|
||||
raise ValueError(msg)
|
||||
|
||||
return events
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue