mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-12 14:54:04 +02:00
fixes
This commit is contained in:
parent
313c1addf4
commit
ba44113277
1 changed files with 4 additions and 12 deletions
|
|
@ -40,7 +40,7 @@ from homeassistant.const import (
|
|||
ATTR_SERVICE_DATA,
|
||||
CONF_NAME,
|
||||
EVENT_CALL_SERVICE,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
EVENT_HOMEASSISTANT_STARTED,
|
||||
EVENT_STATE_CHANGED,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
|
|
@ -117,7 +117,7 @@ SCAN_INTERVAL = timedelta(seconds=10)
|
|||
|
||||
# Consider it a significant change when attribute changes more than
|
||||
BRIGHTNESS_CHANGE = 25 # ≈10% of total range
|
||||
COLOR_TEMP_CHANGE = 250 # ≈5% of total range
|
||||
COLOR_TEMP_CHANGE = 20 # ≈5% of total range
|
||||
RGB_CHANGE = 30 # ≈12% of total range per component
|
||||
|
||||
|
||||
|
|
@ -227,14 +227,6 @@ def _supported_features(hass: HomeAssistant, light: str):
|
|||
return {key for key, value in _SUPPORT_OPTS.items() if supported_features & value}
|
||||
|
||||
|
||||
def abs_rel_diff(val_a, val_b) -> float:
|
||||
"""Absolute relative difference in %."""
|
||||
if val_b == 0:
|
||||
# To avoid ZeroDivisionError
|
||||
val_b = 1e-6
|
||||
return abs((val_a - val_b) / val_b) * 100
|
||||
|
||||
|
||||
class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
||||
"""Representation of a Adaptive Lighting switch."""
|
||||
|
||||
|
|
@ -294,7 +286,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
# Locks that prevent light adjusting when waiting for a light to 'turn_off'
|
||||
self._locks: Dict[str, asyncio.Lock] = {}
|
||||
# To identify that this integration made a change
|
||||
self.__context = Context() # self._context will be overwritten
|
||||
self.__context = Context() # self._context would be overwritten
|
||||
self.turn_on_off_listener.contexts.add(self.__context)
|
||||
|
||||
# Set in self._update_attrs_and_maybe_adapt_lights
|
||||
|
|
@ -336,7 +328,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
await self._setup_listeners()
|
||||
else:
|
||||
self.hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_START, self._setup_listeners
|
||||
EVENT_HOMEASSISTANT_STARTED, self._setup_listeners
|
||||
)
|
||||
last_state = await self.async_get_last_state()
|
||||
is_new_entry = last_state is None # newly added to HA
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue