Define "initial transition" and use it when CL switch is turned on

A 1 sec transition was used when a light is turned on or when sleep state changes. The short transition should also be used when the CL switch is turned on. Also, because this is used in multiple spots, better to define it in one spot (this will also make it easier to make it configurable, if desired)
This commit is contained in:
Clayton Nummer 2019-08-04 14:16:59 -04:00
commit be01be243d
2 changed files with 5 additions and 4 deletions

View file

@ -48,7 +48,7 @@ from homeassistant.util.dt import utcnow as dt_utcnow, as_local
from datetime import datetime, timedelta
VERSION = '1.0.8'
VERSION = '1.0.9'
_LOGGER = logging.getLogger(__name__)

View file

@ -45,6 +45,7 @@ CONF_SLEEP_CT = 'sleep_colortemp'
CONF_SLEEP_BRIGHT = 'sleep_brightness'
CONF_DISABLE_ENTITY = 'disable_entity'
CONF_DISABLE_STATE = 'disable_state'
DEFAULT_INITIAL_TRANSITION = 1
PLATFORM_SCHEMA = vol.Schema({
vol.Required(CONF_PLATFORM): 'circadian_lighting',
@ -192,7 +193,7 @@ class CircadianSwitch(SwitchDevice, RestoreEntity):
self._state = True
# Make initial update
self.update_switch()
self.update_switch(DEFAULT_INITIAL_TRANSITION)
self.schedule_update_ha_state()
@ -327,9 +328,9 @@ class CircadianSwitch(SwitchDevice, RestoreEntity):
def light_state_changed(self, entity_id, from_state, to_state):
_LOGGER.debug(entity_id + " change from " + str(from_state) + " to " + str(to_state))
if to_state.state == 'on' and from_state.state != 'on':
self.adjust_lights([entity_id], 1)
self.adjust_lights([entity_id], DEFAULT_INITIAL_TRANSITION)
def sleep_state_changed(self, entity_id, from_state, to_state):
_LOGGER.debug(entity_id + " change from " + str(from_state) + " to " + str(to_state))
if to_state.state == self._sleep_state or from_state.state == self._sleep_state:
self.update_switch(1)
self.update_switch(DEFAULT_INITIAL_TRANSITION)