From 478d4ad93a6bd3e2d4c35301ed197be213459cce Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 12 Jan 2014 11:29:30 -0800 Subject: [PATCH] Light trigger now looks if the target light group is on to turn on lights instead of all lights. --- .../components/device_sun_light_trigger.py | 2 +- homeassistant/components/group.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/device_sun_light_trigger.py b/homeassistant/components/device_sun_light_trigger.py index 1158b051445..5c7d6fd63d7 100644 --- a/homeassistant/components/device_sun_light_trigger.py +++ b/homeassistant/components/device_sun_light_trigger.py @@ -86,7 +86,7 @@ def setup(bus, statemachine, light_group=None): def handle_device_state_change(category, old_state, new_state): """ Function to handle tracked device state changes. """ - lights_are_on = light.is_on(statemachine) + lights_are_on = group.is_on(statemachine, light_group) light_needed = not (lights_are_on or sun.is_up(statemachine)) diff --git a/homeassistant/components/group.py b/homeassistant/components/group.py index ff1ef2ed1bd..fc2b0fd4148 100644 --- a/homeassistant/components/group.py +++ b/homeassistant/components/group.py @@ -30,6 +30,23 @@ def _get_group_type(state): return None +def is_on(statemachine, group): + """ Returns if the group state is in its ON-state. """ + state = statemachine.get_state(group) + + if state: + group_type = _get_group_type(state['state']) + + if group_type: + group_on = _GROUP_TYPES[group_type][0] + + return state['state'] == group_on + else: + return False + else: + return False + + def get_categories(statemachine, group_name): """ Get the categories that make up this group. """ state = statemachine.get_state(STATE_CATEGORY_FORMAT.format(group_name))