Initial transition configurable and defaulted

This commit is contained in:
mouth4war 2020-02-20 15:22:07 +05:30 committed by GitHub
commit 05f98fa673
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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'
CONF_INITIAL_TRANSITION = 'initial_transition'
DEFAULT_INITIAL_TRANSITION = 1
PLATFORM_SCHEMA = vol.Schema({
@ -66,7 +67,9 @@ PLATFORM_SCHEMA = vol.Schema({
vol.Optional(CONF_SLEEP_BRIGHT):
vol.All(vol.Coerce(int), vol.Range(min=1, max=100)),
vol.Optional(CONF_DISABLE_ENTITY): cv.entity_id,
vol.Optional(CONF_DISABLE_STATE): cv.string
vol.Optional(CONF_DISABLE_STATE): cv.string,
vol.Optional(CONF_INITIAL_TRANSITION, default=DEFAULT_INITIAL_TRANSITION):
vol.All(vol.Coerce(int), vol.Range(min=1, max=1000))
})
def setup_platform(hass, config, add_devices, discovery_info=None):
@ -87,10 +90,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
sleep_brightness = config.get(CONF_SLEEP_BRIGHT)
disable_entity = config.get(CONF_DISABLE_ENTITY)
disable_state = config.get(CONF_DISABLE_STATE)
initial_transition = config.get(CONF_INITIAL_TRANSITION)
cs = CircadianSwitch(hass, cl, name, lights_ct, lights_rgb, lights_xy, lights_brightness,
disable_brightness_adjust, min_brightness, max_brightness,
sleep_entity, sleep_state, sleep_colortemp, sleep_brightness,
disable_entity, disable_state)
disable_entity, disable_state, initial_transition)
add_devices([cs])
def update(call=None):
@ -107,7 +111,7 @@ class CircadianSwitch(SwitchDevice, RestoreEntity):
def __init__(self, hass, cl, name, lights_ct, lights_rgb, lights_xy, lights_brightness,
disable_brightness_adjust, min_brightness, max_brightness,
sleep_entity, sleep_state, sleep_colortemp, sleep_brightness,
disable_entity, disable_state):
disable_entity, disable_state, initial_transition):
"""Initialize the Circadian Lighting switch."""
self.hass = hass
self._cl = cl
@ -129,6 +133,7 @@ class CircadianSwitch(SwitchDevice, RestoreEntity):
self._sleep_brightness = sleep_brightness
self._disable_entity = disable_entity
self._disable_state = disable_state
self._initial_transition = initial_transition
self._attributes = {}
self._attributes['hs_color'] = self._hs_color
self._attributes['brightness'] = None
@ -195,7 +200,7 @@ class CircadianSwitch(SwitchDevice, RestoreEntity):
self._state = True
# Make initial update
self.update_switch(DEFAULT_INITIAL_TRANSITION)
self.update_switch(CONF_INITIAL_TRANSITION)
self.schedule_update_ha_state()
@ -331,7 +336,7 @@ class CircadianSwitch(SwitchDevice, RestoreEntity):
try:
_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], DEFAULT_INITIAL_TRANSITION)
self.adjust_lights([entity_id], CONF_INITIAL_TRANSITION)
except:
pass
@ -339,7 +344,7 @@ class CircadianSwitch(SwitchDevice, RestoreEntity):
try:
_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(DEFAULT_INITIAL_TRANSITION)
self.update_switch(CONF_INITIAL_TRANSITION)
except:
pass
@ -347,6 +352,6 @@ class CircadianSwitch(SwitchDevice, RestoreEntity):
try:
_LOGGER.debug(entity_id + " change from " + str(from_state) + " to " + str(to_state))
if from_state.state == self._disable_state:
self.update_switch(DEFAULT_INITIAL_TRANSITION)
self.update_switch(CONF_INITIAL_TRANSITION)
except:
pass
pass