From 0b1677de6d14f81ab947eed930f7aa8126dc778d Mon Sep 17 00:00:00 2001 From: Phil Cole Date: Tue, 5 Sep 2017 16:38:12 +0100 Subject: [PATCH] Expose hue group 0 (#8663) * Tado Fix #8606 Handle case where 'mode' and 'fanSpeed' are missing JSON. Based on changes in commit https://github.com/wmalgadey/tado_component/commit/adfb608f86b8bf4c1c43e71b4067cbfe1de9ba85 * Expose hue group 0 to HA #8652 If allow_hue_groups is set expose "All Hue Lights" group for "special group 0". This does add an additional Hue API call for every refresh (approx 30 secs) to get the status of the special group 0 because it's not included in the full API pull that currently occurs. * Revert "Expose hue group 0 to HA #8652" This reverts commit db7fe47ec72a4907f8a59ebfb47bc4a6dfa41e89. * Expose hue group 0 to HA #8652 If allow_hue_groups is set expose "All Hue Lights" group for "special group 0". This does add an additional Hue API call for every refresh (approx 30 secs) to get the status of the special group 0 because it's not included in the full API pull that currently occurs. * Changes per review by balloob 1) Use all_lights instead of all_lamps 2) Fix line lengths and trailing whitespace 3) Move "All Hue Lights" to GROUP_NAME_ALL_HUE_LIGHTS constant * Make "All Hue Lights" a constant * Fix trailing whitespace --- homeassistant/components/light/hue.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/homeassistant/components/light/hue.py b/homeassistant/components/light/hue.py index 746c6489c9e..79d80d2b8a0 100644 --- a/homeassistant/components/light/hue.py +++ b/homeassistant/components/light/hue.py @@ -83,6 +83,7 @@ SCENE_SCHEMA = vol.Schema({ }) ATTR_IS_HUE_GROUP = "is_hue_group" +GROUP_NAME_ALL_HUE_LIGHTS = "All Hue Lights" def _find_host_from_config(hass, filename=PHUE_CONFIG_FILE): @@ -203,6 +204,21 @@ def setup_bridge(host, hass, add_devices, filename, allow_unreachable, _LOGGER.error("Got unexpected result from Hue API") return + if not skip_groups: + # Group ID 0 is a special group in the hub for all lights, but it + # is not returned by get_api() so explicity get it and include it. + # See https://developers.meethue.com/documentation/ + # groups-api#21_get_all_groups + _LOGGER.debug("Getting group 0 from bridge") + all_lights = bridge.get_group(0) + if not isinstance(all_lights, dict): + _LOGGER.error("Got unexpected result from Hue API for group 0") + return + # Hue hub returns name of group 0 as "Group 0", so rename + # for ease of use in HA. + all_lights['name'] = GROUP_NAME_ALL_HUE_LIGHTS + api_groups["0"] = all_lights + new_lights = [] api_name = api.get('config').get('name')