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.
This commit is contained in:
parent
fb297981af
commit
f65d8e1254
1 changed files with 47 additions and 0 deletions
|
@ -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."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue