Change Eufy brightness handling (#14111)

Eufy device state isn't reported if the bulb is off, so avoid stamping on
the previous values if the bulb isn't going to give us useful information.
In addition, improve handling of bulb turn on if we aren't provided with a
brightness - this should avoid the bulb tending to end up with a brightness of
1 after power cycling.
This commit is contained in:
Matthew Garrett 2018-04-27 13:39:07 -07:00 committed by Paulus Schoutsen
parent 0b350993b5
commit 7e39a5c4d5

View File

@ -61,13 +61,14 @@ class EufyLight(Light):
def update(self): def update(self):
"""Synchronise state from the bulb.""" """Synchronise state from the bulb."""
self._bulb.update() self._bulb.update()
self._brightness = self._bulb.brightness if self._bulb.power:
self._temp = self._bulb.temperature self._brightness = self._bulb.brightness
if self._bulb.colors: self._temp = self._bulb.temperature
self._colormode = True if self._bulb.colors:
self._hs = color_util.color_RGB_to_hs(*self._bulb.colors) self._colormode = True
else: self._hs = color_util.color_RGB_to_hs(*self._bulb.colors)
self._colormode = False else:
self._colormode = False
self._state = self._bulb.power self._state = self._bulb.power
@property @property
@ -130,7 +131,9 @@ class EufyLight(Light):
if brightness is not None: if brightness is not None:
brightness = int(brightness * 100 / 255) brightness = int(brightness * 100 / 255)
else: else:
brightness = max(1, self._brightness) if self._brightness is None:
self._brightness = 100
brightness = self._brightness
if colortemp is not None: if colortemp is not None:
self._colormode = False self._colormode = False