From be01be243dd011e5d23f4b92c2a882e77717da9f Mon Sep 17 00:00:00 2001 From: Clayton Nummer Date: Sun, 4 Aug 2019 14:16:59 -0400 Subject: [PATCH] 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) --- custom_components/circadian_lighting/__init__.py | 2 +- custom_components/circadian_lighting/switch.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/custom_components/circadian_lighting/__init__.py b/custom_components/circadian_lighting/__init__.py index 95f19301..c3f993ba 100644 --- a/custom_components/circadian_lighting/__init__.py +++ b/custom_components/circadian_lighting/__init__.py @@ -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__) diff --git a/custom_components/circadian_lighting/switch.py b/custom_components/circadian_lighting/switch.py index 8c5b25a5..420a3d90 100644 --- a/custom_components/circadian_lighting/switch.py +++ b/custom_components/circadian_lighting/switch.py @@ -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) \ No newline at end of file + self.update_switch(DEFAULT_INITIAL_TRANSITION) \ No newline at end of file