Skip to content

Commit

Permalink
Update update_lights.py
Browse files Browse the repository at this point in the history
- Added support for event subscription
- Allow for disabling time-based updates
- Allow for disabling listing for light state update
  • Loading branch information
haberda authored Sep 20, 2020
1 parent 322eecc commit 6daae4d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions apps/update_lights/update_lights.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ def initialize(self):
self.color_temp_unit = str(self.args.get('color_temp_unit', 'kelvin'))
self.color_temp_max = int(self.args.get('color_temp_max', 4000))
self.color_temp_min = int(self.args.get('color_temp_min', 2200))
self.watch_light_state = bool(self.args.get('watch_light_state', True))
self.keep_lights_on = bool(self.args.get('keep_lights_on', False))
self.start_lights_on = bool(self.args.get('start_lights_on', False))
self.stop_lights_off = bool(self.args.get('stop_lights_off', False))
self.event = self.args.get('event_subscription', None)

if isinstance(self.all_lights, str):
self.all_lights = self.all_lights.split(',')
Expand Down Expand Up @@ -88,9 +90,13 @@ def initialize(self):
if len(entity.split(',')) > 1:
entity = entity.split(',')[0]
self.listen_state(self.state_change, entity)
for light in self.all_lights:
self.listen_state(self.state_change, light)
self.run_every(self.time_change, target, interval)
if self.watch_light_state:
for light in self.all_lights:
self.listen_state(self.state_change, light)
if interval > 0:
self.run_every(self.time_change, target, interval)
if self.event is not None:
self.listen_event(self.event_subscription, self.event)
else:
self.log('No lights defined', log='error_log')

Expand All @@ -100,6 +106,16 @@ def time_change(self, kwargs):
entities = self.all_lights
self.adjust_light(entities, threshold, transition)

def event_subscription(self, event, data, kwargs):
threshold = 255
if 'threshold' in data:
threshold = data['threshold']
transition = 0
if 'transition' in data:
transition = data['transition']
entities = self.all_lights
self.adjust_light(entities, threshold, transition)

def state_change(self, entity, attribute, old, new, kwargs):
threshold = 255
transition = 0
Expand Down

0 comments on commit 6daae4d

Please sign in to comment.