Fix colortemp conversion for osramlightify (#6516)
* Fix colortemp conversion for osramlightify
Copied from the LIFX fix in 75df4be733
.
* Fix style
* Updates from review
@armills:
While we're doing cleanup here, can you just change self._brightness,
self._rgb, self._name, self._temperature, and self._state assignments in
__init__ to None? These will get overwritten when self.update() is called, so
it's safer/cleaner to initialize them to None since it shouldn't matter if
everything is working.
This commit is contained in:
parent
32dd815852
commit
9a86ccaaea
1 changed files with 8 additions and 12 deletions
|
@ -17,6 +17,8 @@ from homeassistant.components.light import (
|
|||
Light, ATTR_BRIGHTNESS, ATTR_COLOR_TEMP, ATTR_EFFECT, ATTR_RGB_COLOR,
|
||||
ATTR_TRANSITION, EFFECT_RANDOM, SUPPORT_BRIGHTNESS, SUPPORT_EFFECT,
|
||||
SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR, SUPPORT_TRANSITION, PLATFORM_SCHEMA)
|
||||
from homeassistant.util.color import (
|
||||
color_temperature_mired_to_kelvin, color_temperature_kelvin_to_mired)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
REQUIREMENTS = ['https://github.com/tfriedel/python-lightify/archive/'
|
||||
|
@ -24,10 +26,6 @@ REQUIREMENTS = ['https://github.com/tfriedel/python-lightify/archive/'
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
TEMP_MIN = 2000 # lightify minimum temperature
|
||||
TEMP_MAX = 6500 # lightify maximum temperature
|
||||
TEMP_MIN_HASS = 154 # home assistant minimum temperature
|
||||
TEMP_MAX_HASS = 500 # home assistant maximum temperature
|
||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100)
|
||||
|
||||
|
@ -93,10 +91,10 @@ class OsramLightifyLight(Light):
|
|||
self._light = light
|
||||
self._light_id = light_id
|
||||
self.update_lights = update_lights
|
||||
self._brightness = 0
|
||||
self._rgb = (0, 0, 0)
|
||||
self._name = ""
|
||||
self._temperature = TEMP_MIN
|
||||
self._brightness = None
|
||||
self._rgb = None
|
||||
self._name = None
|
||||
self._temperature = None
|
||||
self._state = False
|
||||
self.update()
|
||||
|
||||
|
@ -164,8 +162,7 @@ class OsramLightifyLight(Light):
|
|||
|
||||
if ATTR_COLOR_TEMP in kwargs:
|
||||
color_t = kwargs[ATTR_COLOR_TEMP]
|
||||
kelvin = int(((TEMP_MAX - TEMP_MIN) * (color_t - TEMP_MIN_HASS) /
|
||||
(TEMP_MAX_HASS - TEMP_MIN_HASS)) + TEMP_MIN)
|
||||
kelvin = int(color_temperature_mired_to_kelvin(color_t))
|
||||
_LOGGER.debug("turn_on requested set_temperature for light:"
|
||||
" %s: %s ", self._name, kelvin)
|
||||
self._light.set_temperature(kelvin, transition)
|
||||
|
@ -218,6 +215,5 @@ class OsramLightifyLight(Light):
|
|||
self._name = self._light.name()
|
||||
self._rgb = self._light.rgb()
|
||||
o_temp = self._light.temp()
|
||||
self._temperature = int(TEMP_MIN_HASS + (TEMP_MAX_HASS - TEMP_MIN_HASS)
|
||||
* (o_temp - TEMP_MIN) / (TEMP_MAX - TEMP_MIN))
|
||||
self._temperature = color_temperature_kelvin_to_mired(o_temp)
|
||||
self._state = self._light.on()
|
||||
|
|
Loading…
Add table
Reference in a new issue