exception

This commit is contained in:
Bas Nijholt 2020-10-01 10:09:06 +02:00
commit 8ec62305f0

View file

@ -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