Merge pull request #15 from trainman419/multi_room

Add support to device_sun_light_trigger to target specific device groups.
This commit is contained in:
Paulus Schoutsen 2014-12-15 18:57:12 -08:00
commit c18bb7dcad

View File

@ -21,6 +21,7 @@ LIGHT_PROFILE = 'relax'
CONF_LIGHT_PROFILE = 'light_profile' CONF_LIGHT_PROFILE = 'light_profile'
CONF_LIGHT_GROUP = 'light_group' CONF_LIGHT_GROUP = 'light_group'
CONF_DEVICE_GROUP = 'device_group'
# pylint: disable=too-many-branches # pylint: disable=too-many-branches
@ -30,13 +31,17 @@ def setup(hass, config):
disable_turn_off = 'disable_turn_off' in config[DOMAIN] disable_turn_off = 'disable_turn_off' in config[DOMAIN]
light_group = config[DOMAIN].get(CONF_LIGHT_GROUP, light_group = config[DOMAIN].get(CONF_LIGHT_GROUP,
light.GROUP_NAME_ALL_LIGHTS) light.ENTITY_ID_ALL_LIGHTS)
light_profile = config[DOMAIN].get(CONF_LIGHT_PROFILE, LIGHT_PROFILE) light_profile = config[DOMAIN].get(CONF_LIGHT_PROFILE, LIGHT_PROFILE)
device_group = config[DOMAIN].get(CONF_DEVICE_GROUP,
device_tracker.ENTITY_ID_ALL_DEVICES)
logger = logging.getLogger(__name__) 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: if not device_entity_ids:
logger.error("No devices found to track") logger.error("No devices found to track")
@ -142,7 +147,7 @@ def setup(hass, config):
break break
# Did all devices leave the house? # 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 new_state.state == STATE_NOT_HOME and lights_are_on
and not disable_turn_off): and not disable_turn_off):
@ -158,8 +163,7 @@ def setup(hass, config):
# Track when all devices are gone to shut down lights # Track when all devices are gone to shut down lights
hass.states.track_change( hass.states.track_change(
device_tracker.ENTITY_ID_ALL_DEVICES, device_group, check_light_on_dev_state_change,
check_light_on_dev_state_change,
STATE_HOME, STATE_NOT_HOME) STATE_HOME, STATE_NOT_HOME)
return True return True