From cec5ca8ba2dcb0a05a904681e7c84ec4bb6c0332 Mon Sep 17 00:00:00 2001 From: trainman419 Date: Mon, 15 Dec 2014 00:14:10 -0800 Subject: [PATCH 1/4] Specify devices for trigger --- homeassistant/components/device_sun_light_trigger.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/device_sun_light_trigger.py b/homeassistant/components/device_sun_light_trigger.py index 5136340832f..a8f8fd11519 100644 --- a/homeassistant/components/device_sun_light_trigger.py +++ b/homeassistant/components/device_sun_light_trigger.py @@ -21,6 +21,7 @@ LIGHT_PROFILE = 'relax' CONF_LIGHT_PROFILE = 'light_profile' CONF_LIGHT_GROUP = 'light_group' +CONF_DEVICE_GROUP = 'device_group' # pylint: disable=too-many-branches @@ -34,9 +35,13 @@ def setup(hass, config): light_profile = config[DOMAIN].get(CONF_LIGHT_PROFILE, LIGHT_PROFILE) + device_group = config[DOMAIN].get(CONF_LIGHT_GROUP, + device_tracker.GROUP_NAME_ALL_DEVICES) + logger = logging.getLogger(__name__) - device_entity_ids = hass.states.entity_ids(device_tracker.DOMAIN) + device_entity_ids = group.get_entity_ids(hass, device_group, + device_tracker.DOMAIN) if not device_entity_ids: logger.error("No devices found to track") From 18396d2ee5d7761eba441ab72f22e8a7322da77b Mon Sep 17 00:00:00 2001 From: trainman419 Date: Mon, 15 Dec 2014 00:49:56 -0800 Subject: [PATCH 2/4] Fix typo and default groups --- homeassistant/components/device_sun_light_trigger.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/device_sun_light_trigger.py b/homeassistant/components/device_sun_light_trigger.py index a8f8fd11519..a5dc5b2e302 100644 --- a/homeassistant/components/device_sun_light_trigger.py +++ b/homeassistant/components/device_sun_light_trigger.py @@ -31,11 +31,12 @@ def setup(hass, config): disable_turn_off = 'disable_turn_off' in config[DOMAIN] light_group = config[DOMAIN].get(CONF_LIGHT_GROUP, - light.GROUP_NAME_ALL_LIGHTS) + 'group.' + light.GROUP_NAME_ALL_LIGHTS) light_profile = config[DOMAIN].get(CONF_LIGHT_PROFILE, LIGHT_PROFILE) - device_group = config[DOMAIN].get(CONF_LIGHT_GROUP, + device_group = config[DOMAIN].get(CONF_DEVICE_GROUP, + 'group.' + device_tracker.GROUP_NAME_ALL_DEVICES) logger = logging.getLogger(__name__) From 69a616a0ba31960a4f1e4f8918ba6bd72cdccb49 Mon Sep 17 00:00:00 2001 From: trainman419 Date: Mon, 15 Dec 2014 11:29:22 -0800 Subject: [PATCH 3/4] Fix default light and device group IDs --- homeassistant/components/device_sun_light_trigger.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/device_sun_light_trigger.py b/homeassistant/components/device_sun_light_trigger.py index a5dc5b2e302..0d0d14337b0 100644 --- a/homeassistant/components/device_sun_light_trigger.py +++ b/homeassistant/components/device_sun_light_trigger.py @@ -31,13 +31,12 @@ def setup(hass, config): disable_turn_off = 'disable_turn_off' in config[DOMAIN] light_group = config[DOMAIN].get(CONF_LIGHT_GROUP, - 'group.' + light.GROUP_NAME_ALL_LIGHTS) + light.ENTITY_ID_ALL_LIGHTS) light_profile = config[DOMAIN].get(CONF_LIGHT_PROFILE, LIGHT_PROFILE) device_group = config[DOMAIN].get(CONF_DEVICE_GROUP, - 'group.' + - device_tracker.GROUP_NAME_ALL_DEVICES) + device_tracker.ENTITY_ID_ALL_DEVICES) logger = logging.getLogger(__name__) From 1c1d075c12e60b974c1a6aff8a202e77f6f31d29 Mon Sep 17 00:00:00 2001 From: trainman419 Date: Mon, 15 Dec 2014 11:29:48 -0800 Subject: [PATCH 4/4] Only turn off the specified lights --- homeassistant/components/device_sun_light_trigger.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/device_sun_light_trigger.py b/homeassistant/components/device_sun_light_trigger.py index 0d0d14337b0..c9668853c73 100644 --- a/homeassistant/components/device_sun_light_trigger.py +++ b/homeassistant/components/device_sun_light_trigger.py @@ -147,7 +147,7 @@ def setup(hass, config): break # Did all devices leave the house? - elif (entity == device_tracker.ENTITY_ID_ALL_DEVICES and + elif (entity == device_group and new_state.state == STATE_NOT_HOME and lights_are_on and not disable_turn_off): @@ -163,8 +163,7 @@ def setup(hass, config): # Track when all devices are gone to shut down lights hass.states.track_change( - device_tracker.ENTITY_ID_ALL_DEVICES, - check_light_on_dev_state_change, + device_group, check_light_on_dev_state_change, STATE_HOME, STATE_NOT_HOME) return True