tradfri: Improve color temp support detection (#7211)
parent
dafbdbd2d0
commit
80e9e9bfda
|
@ -13,13 +13,11 @@ from homeassistant.util import slugify
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['tradfri']
|
DEPENDENCIES = ['tradfri']
|
||||||
SUPPORTED_FEATURES = (SUPPORT_BRIGHTNESS | SUPPORT_RGB_COLOR)
|
|
||||||
SUPPORTED_FEATURES_IKEA = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP)
|
|
||||||
PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA
|
PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA
|
||||||
IKEA = 'ikea_of_sweden'
|
IKEA = 'IKEA of Sweden'
|
||||||
|
ALLOWED_TEMPERATURES = {
|
||||||
ALLOWED_TEMPERATURES = {IKEA: {2200: 'efd275', 2700: 'f1e0b5', 4000: 'f5faf6'}}
|
IKEA: {2200: 'efd275', 2700: 'f1e0b5', 4000: 'f5faf6'}
|
||||||
ALLOWED_FEATURES = {IKEA: SUPPORTED_FEATURES_IKEA}
|
}
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
@ -46,8 +44,14 @@ class Tradfri(Light):
|
||||||
self._light_data = light.light_control.lights[0]
|
self._light_data = light.light_control.lights[0]
|
||||||
self._name = light.name
|
self._name = light.name
|
||||||
self._rgb_color = None
|
self._rgb_color = None
|
||||||
self._features = ALLOWED_FEATURES.get(
|
self._features = SUPPORT_BRIGHTNESS
|
||||||
slugify(self._light.device_info.manufacturer), SUPPORTED_FEATURES)
|
|
||||||
|
if self._light_data.hex_color is not None:
|
||||||
|
if self._light.device_info.manufacturer == IKEA:
|
||||||
|
self._features &= SUPPORT_COLOR_TEMP
|
||||||
|
else:
|
||||||
|
self._features &= SUPPORT_RGB_COLOR
|
||||||
|
|
||||||
self._ok_temps = ALLOWED_TEMPERATURES.get(
|
self._ok_temps = ALLOWED_TEMPERATURES.get(
|
||||||
slugify(self._light.device_info.manufacturer))
|
slugify(self._light.device_info.manufacturer))
|
||||||
|
|
||||||
|
@ -74,16 +78,18 @@ class Tradfri(Light):
|
||||||
@property
|
@property
|
||||||
def color_temp(self):
|
def color_temp(self):
|
||||||
"""Return the CT color value in mireds."""
|
"""Return the CT color value in mireds."""
|
||||||
if not self.supported_features & SUPPORT_COLOR_TEMP or \
|
if (self._light_data.hex_color is None or
|
||||||
not self._ok_temps:
|
self.supported_features & SUPPORT_COLOR_TEMP == 0 or
|
||||||
return
|
not self._ok_temps):
|
||||||
|
return None
|
||||||
|
|
||||||
kelvin = next((
|
kelvin = next((
|
||||||
kelvin for kelvin, hex_color in self._ok_temps.items()
|
kelvin for kelvin, hex_color in self._ok_temps.items()
|
||||||
if hex_color == self._light_data.hex_color), None)
|
if hex_color == self._light_data.hex_color), None)
|
||||||
if kelvin is None:
|
if kelvin is None:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
'unexpected color temperature found %s',
|
'unexpected color temperature found for %s: %s',
|
||||||
self._light_data.hex_color)
|
self.name, self._light_data.hex_color)
|
||||||
return
|
return
|
||||||
return color_util.color_temperature_kelvin_to_mired(kelvin)
|
return color_util.color_temperature_kelvin_to_mired(kelvin)
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ else
|
||||||
-v /etc/localtime:/etc/localtime:ro \
|
-v /etc/localtime:/etc/localtime:ro \
|
||||||
-v `pwd`:/usr/src/app \
|
-v `pwd`:/usr/src/app \
|
||||||
-v `pwd`/config:/config \
|
-v `pwd`/config:/config \
|
||||||
|
--rm \
|
||||||
-t -i home-assistant-dev
|
-t -i home-assistant-dev
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -12,6 +12,7 @@ MAINTAINER Paulus Schoutsen <Paulus@PaulusSchoutsen.nl>
|
||||||
#ENV INSTALL_OPENZWAVE no
|
#ENV INSTALL_OPENZWAVE no
|
||||||
#ENV INSTALL_LIBCEC no
|
#ENV INSTALL_LIBCEC no
|
||||||
#ENV INSTALL_PHANTOMJS no
|
#ENV INSTALL_PHANTOMJS no
|
||||||
|
#ENV INSTALL_COAP_CLIENT no
|
||||||
|
|
||||||
VOLUME /config
|
VOLUME /config
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ RUN virtualization/Docker/setup_docker_prereqs
|
||||||
# Install hass component dependencies
|
# Install hass component dependencies
|
||||||
COPY requirements_all.txt requirements_all.txt
|
COPY requirements_all.txt requirements_all.txt
|
||||||
RUN pip3 install --no-cache-dir -r requirements_all.txt && \
|
RUN pip3 install --no-cache-dir -r requirements_all.txt && \
|
||||||
pip3 install --no-cache-dir mysqlclient psycopg2 uvloop
|
pip3 install --no-cache-dir mysqlclient psycopg2 uvloop cchardet
|
||||||
|
|
||||||
# BEGIN: Development additions
|
# BEGIN: Development additions
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue