mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Make FutureNow light remember last brightness when turning on (#15733)
* Remember last brightness value and use it on turn_on() * Pyfnip-0.2 now returns state reliably, no manual changes needed. * Split too long line of code * Updated pyfnip library version
This commit is contained in:
parent
48ba13bc6c
commit
3959f82030
@ -16,7 +16,7 @@ from homeassistant.components.light import (
|
|||||||
PLATFORM_SCHEMA)
|
PLATFORM_SCHEMA)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['pyfnip==0.1']
|
REQUIREMENTS = ['pyfnip==0.2']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -75,8 +75,8 @@ class FutureNowLight(Light):
|
|||||||
self._dimmable = device['dimmable']
|
self._dimmable = device['dimmable']
|
||||||
self._channel = device['channel']
|
self._channel = device['channel']
|
||||||
self._brightness = None
|
self._brightness = None
|
||||||
|
self._last_brightness = 255
|
||||||
self._state = None
|
self._state = None
|
||||||
self._skip_update = False
|
|
||||||
|
|
||||||
if device['driver'] == CONF_DRIVER_FNIP6X10AD:
|
if device['driver'] == CONF_DRIVER_FNIP6X10AD:
|
||||||
self._light = pyfnip.FNIP6x2adOutput(device['host'],
|
self._light = pyfnip.FNIP6x2adOutput(device['host'],
|
||||||
@ -111,25 +111,20 @@ class FutureNowLight(Light):
|
|||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Turn the light on."""
|
"""Turn the light on."""
|
||||||
level = kwargs.get(ATTR_BRIGHTNESS, 255) if self._dimmable else 255
|
if self._dimmable:
|
||||||
|
level = kwargs.get(ATTR_BRIGHTNESS, self._last_brightness)
|
||||||
|
else:
|
||||||
|
level = 255
|
||||||
self._light.turn_on(to_futurenow_level(level))
|
self._light.turn_on(to_futurenow_level(level))
|
||||||
self._brightness = level
|
|
||||||
self._state = True
|
|
||||||
self._skip_update = True
|
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
"""Turn the light off."""
|
"""Turn the light off."""
|
||||||
self._light.turn_off()
|
self._light.turn_off()
|
||||||
self._brightness = 0
|
if self._brightness:
|
||||||
self._state = False
|
self._last_brightness = self._brightness
|
||||||
self._skip_update = True
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Fetch new state data for this light."""
|
"""Fetch new state data for this light."""
|
||||||
if self._skip_update:
|
|
||||||
self._skip_update = False
|
|
||||||
return
|
|
||||||
|
|
||||||
state = int(self._light.is_on())
|
state = int(self._light.is_on())
|
||||||
self._state = bool(state)
|
self._state = bool(state)
|
||||||
self._brightness = to_hass_level(state)
|
self._brightness = to_hass_level(state)
|
||||||
|
@ -829,7 +829,7 @@ pyflexit==0.3
|
|||||||
pyflic-homeassistant==0.4.dev0
|
pyflic-homeassistant==0.4.dev0
|
||||||
|
|
||||||
# homeassistant.components.light.futurenow
|
# homeassistant.components.light.futurenow
|
||||||
pyfnip==0.1
|
pyfnip==0.2
|
||||||
|
|
||||||
# homeassistant.components.fritzbox
|
# homeassistant.components.fritzbox
|
||||||
pyfritzhome==0.3.7
|
pyfritzhome==0.3.7
|
||||||
|
Loading…
x
Reference in New Issue
Block a user