Update pyhomematic to 0.1.52 and add features for lights (#18499)
* Update pyhomematic and add features for lights * Lint * Lint * Update homematic.py * Update homematic.py
This commit is contained in:
1 parent
90f3f2b1e7
commit
fc4dd4e51f
4 files changed
+48
-13
No files matched your search
@@ -8,8 +8,8 @@ import logging
|
||||
|
||||
from homeassistant.components.homematic import ATTR_DISCOVER_DEVICES, HMDevice
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, Light)
|
||||
from homeassistant.const import STATE_UNKNOWN
|
||||
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, ATTR_HS_COLOR, SUPPORT_COLOR,
|
||||
ATTR_EFFECT, SUPPORT_EFFECT, Light)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -38,7 +38,7 @@ class HMLight(HMDevice, Light):
|
||||
def brightness(self):
|
||||
"""Return the brightness of this light between 0..255."""
|
||||
# Is dimmer?
|
||||
if self._state == "LEVEL":
|
||||
if self._state == 'LEVEL':
|
||||
return int(self._hm_get_state() * 255)
|
||||
return None
|
||||
|
||||
@@ -53,16 +53,47 @@ class HMLight(HMDevice, Light):
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Flag supported features."""
|
||||
return SUPPORT_HOMEMATIC
|
||||
if 'COLOR' in self._hmdevice.WRITENODE:
|
||||
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_EFFECT
|
||||
return SUPPORT_BRIGHTNESS
|
||||
|
||||
@property
|
||||
def hs_color(self):
|
||||
"""Return the hue and saturation color value [float, float]."""
|
||||
if not self.supported_features & SUPPORT_COLOR:
|
||||
return None
|
||||
hue, sat = self._hmdevice.get_hs_color()
|
||||
return hue*360.0, sat*100.0
|
||||
|
||||
@property
|
||||
def effect_list(self):
|
||||
"""Return the list of supported effects."""
|
||||
if not self.supported_features & SUPPORT_EFFECT:
|
||||
return None
|
||||
return self._hmdevice.get_effect_list()
|
||||
|
||||
@property
|
||||
def effect(self):
|
||||
"""Return the current color change program of the light."""
|
||||
if not self.supported_features & SUPPORT_EFFECT:
|
||||
return None
|
||||
return self._hmdevice.get_effect()
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the light on."""
|
||||
"""Turn the light on and/or change color or color effect settings."""
|
||||
if ATTR_BRIGHTNESS in kwargs and self._state == "LEVEL":
|
||||
percent_bright = float(kwargs[ATTR_BRIGHTNESS]) / 255
|
||||
self._hmdevice.set_level(percent_bright, self._channel)
|
||||
else:
|
||||
elif ATTR_HS_COLOR not in kwargs and ATTR_EFFECT not in kwargs:
|
||||
self._hmdevice.on(self._channel)
|
||||
|
||||
if ATTR_HS_COLOR in kwargs:
|
||||
self._hmdevice.set_hs_color(
|
||||
hue=kwargs[ATTR_HS_COLOR][0]/360.0,
|
||||
saturation=kwargs[ATTR_HS_COLOR][1]/100.0)
|
||||
if ATTR_EFFECT in kwargs:
|
||||
self._hmdevice.set_effect(kwargs[ATTR_EFFECT])
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn the light off."""
|
||||
self._hmdevice.off(self._channel)
|
||||
@@ -71,4 +102,7 @@ class HMLight(HMDevice, Light):
|
||||
"""Generate a data dict (self._data) from the Homematic metadata."""
|
||||
# Use LEVEL
|
||||
self._state = "LEVEL"
|
||||
self._data.update({self._state: STATE_UNKNOWN})
|
||||
self._data[self._state] = None
|
||||
|
||||
if self.supported_features & SUPPORT_COLOR:
|
||||
self._data.update({"COLOR": None, "PROGRAM": None})
|
||||
Reference in new issue
Block a user