From f65d8e12544efc664e3fbe479cc2681aea71ec84 Mon Sep 17 00:00:00 2001 From: Ron Klinkien Date: Tue, 25 Apr 2017 06:57:38 +0200 Subject: [PATCH] Adding group control to tradfri light component (#7248) * Added initial support for tradfri group control * Tried to keep original variable structure * pylint and pep8 fixes * Fixed lint error about docstring * Removed unneeded stuff, renamed _light. Needs to be released pytradfri version. * Better naming of variables inside add_devices call. --- homeassistant/components/light/tradfri.py | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/homeassistant/components/light/tradfri.py b/homeassistant/components/light/tradfri.py index ca1d5a38330..fe30c0f370c 100644 --- a/homeassistant/components/light/tradfri.py +++ b/homeassistant/components/light/tradfri.py @@ -30,6 +30,53 @@ def setup_platform(hass, config, add_devices, discovery_info=None): lights = [dev for dev in devices if dev.has_light_control] add_devices(Tradfri(light) for light in lights) + groups = gateway.get_groups() + add_devices(TradfriGroup(group) for group in groups) + + +class TradfriGroup(Light): + """The platform class required by hass.""" + + def __init__(self, light): + """Initialize a Group.""" + self._group = light + self._name = light.name + + @property + def supported_features(self): + """Flag supported features.""" + return SUPPORT_BRIGHTNESS + + @property + def name(self): + """Return the display name of this group.""" + return self._name + + @property + def is_on(self): + """Return true if group lights are on.""" + return self._group.state + + @property + def brightness(self): + """Brightness of the group lights (an integer in the range 1-255).""" + return self._group.dimmer + + def turn_off(self, **kwargs): + """Instruct the group lights to turn off.""" + return self._group.set_state(0) + + def turn_on(self, **kwargs): + """Instruct the group lights to turn on, or dim.""" + if ATTR_BRIGHTNESS in kwargs: + self._group.set_dimmer(kwargs[ATTR_BRIGHTNESS]) + else: + self._group.set_state(1) + + def update(self): + """Fetch new state data for this group.""" + self._group.update() + class Tradfri(Light): """The platform class required by hass."""