Communication reduced. Setting brightness and/or color temperature will turn on the device. (#12343)

This commit is contained in:
Sebastian Muszynski 2018-02-12 20:24:48 +01:00 committed by Paulus Schoutsen
parent 2d77a2bb39
commit 04bde68db3

View File

@ -289,6 +289,28 @@ class XiaomiPhilipsLightBall(XiaomiPhilipsGenericLight, Light):
color_temp, self.max_mireds, color_temp, self.max_mireds,
self.min_mireds, CCT_MIN, CCT_MAX) self.min_mireds, CCT_MIN, CCT_MAX)
if ATTR_BRIGHTNESS in kwargs:
brightness = kwargs[ATTR_BRIGHTNESS]
percent_brightness = ceil(100 * brightness / 255.0)
if ATTR_BRIGHTNESS in kwargs and ATTR_COLOR_TEMP in kwargs:
_LOGGER.debug(
"Setting brightness and color temperature: "
"%s %s%%, %s mireds, %s%% cct",
brightness, percent_brightness,
color_temp, percent_color_temp)
result = yield from self._try_command(
"Setting brightness and color temperature failed: "
"%s bri, %s cct",
self._light.set_brightness_and_color_temperature,
percent_brightness, percent_color_temp)
if result:
self._color_temp = color_temp
self._brightness = brightness
elif ATTR_COLOR_TEMP in kwargs:
_LOGGER.debug( _LOGGER.debug(
"Setting color temperature: " "Setting color temperature: "
"%s mireds, %s%% cct", "%s mireds, %s%% cct",
@ -301,7 +323,7 @@ class XiaomiPhilipsLightBall(XiaomiPhilipsGenericLight, Light):
if result: if result:
self._color_temp = color_temp self._color_temp = color_temp
if ATTR_BRIGHTNESS in kwargs: elif ATTR_BRIGHTNESS in kwargs:
brightness = kwargs[ATTR_BRIGHTNESS] brightness = kwargs[ATTR_BRIGHTNESS]
percent_brightness = ceil(100 * brightness / 255.0) percent_brightness = ceil(100 * brightness / 255.0)
@ -316,8 +338,9 @@ class XiaomiPhilipsLightBall(XiaomiPhilipsGenericLight, Light):
if result: if result:
self._brightness = brightness self._brightness = brightness
self._state = yield from self._try_command( else:
"Turning the light on failed.", self._light.on) self._state = yield from self._try_command(
"Turning the light on failed.", self._light.on)
@asyncio.coroutine @asyncio.coroutine
def async_update(self): def async_update(self):