Add color temp and brightness config to light
This commit is contained in:
committed by
rospogrigio
parent
8456c6039c
commit
792fcc5186
@@ -260,6 +260,14 @@ class LocalTuyaEntity(Entity):
|
||||
|
||||
return value
|
||||
|
||||
def dps_conf(self, conf_item):
|
||||
"""Return value of datapoint for user speified config item.
|
||||
|
||||
This method looks up which DP a certain config item uses based on
|
||||
user configuration and returns its value.
|
||||
"""
|
||||
return self.dps(self._config.get(conf_item))
|
||||
|
||||
def status_updated(self):
|
||||
"""Device status was updated.
|
||||
|
||||
|
@@ -2,6 +2,13 @@
|
||||
import logging
|
||||
from functools import partial
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (
|
||||
CONF_ID,
|
||||
CONF_BRIGHTNESS,
|
||||
CONF_COLOR_TEMP,
|
||||
)
|
||||
from homeassistant.components.light import (
|
||||
LightEntity,
|
||||
DOMAIN,
|
||||
@@ -20,16 +27,13 @@ MIN_MIRED = 153
|
||||
MAX_MIRED = 370
|
||||
UPDATE_RETRY_LIMIT = 3
|
||||
|
||||
DPS_INDEX_ON = "1"
|
||||
DPS_INDEX_MODE = "2"
|
||||
DPS_INDEX_BRIGHTNESS = "3"
|
||||
DPS_INDEX_COLOURTEMP = "4"
|
||||
DPS_INDEX_COLOUR = "5"
|
||||
|
||||
|
||||
def flow_schema(dps):
|
||||
"""Return schema used in config flow."""
|
||||
return {}
|
||||
return {
|
||||
vol.Optional(CONF_BRIGHTNESS): vol.In(dps),
|
||||
vol.Optional(CONF_COLOR_TEMP): vol.In(dps),
|
||||
}
|
||||
|
||||
|
||||
class LocaltuyaLight(LocalTuyaEntity, LightEntity):
|
||||
@@ -90,7 +94,7 @@ class LocaltuyaLight(LocalTuyaEntity, LightEntity):
|
||||
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
self._device.set_dps(
|
||||
max(int(kwargs[ATTR_BRIGHTNESS]), 25), DPS_INDEX_BRIGHTNESS
|
||||
max(int(kwargs[ATTR_BRIGHTNESS]), 25), self._config.get(CONF_BRIGHTNESS)
|
||||
)
|
||||
|
||||
if ATTR_HS_COLOR in kwargs:
|
||||
@@ -102,7 +106,7 @@ class LocaltuyaLight(LocalTuyaEntity, LightEntity):
|
||||
- (255 / (MAX_MIRED - MIN_MIRED))
|
||||
* (int(kwargs[ATTR_COLOR_TEMP]) - MIN_MIRED)
|
||||
)
|
||||
self._device.set_dps(color_temp, DPS_INDEX_COLOURTEMP)
|
||||
self._device.set_dps(color_temp, self._config.get(CONF_COLOR_TEMP))
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn Tuya light off."""
|
||||
@@ -112,13 +116,13 @@ class LocaltuyaLight(LocalTuyaEntity, LightEntity):
|
||||
"""Device status was updated."""
|
||||
self._state = self.dps(self._dps_id)
|
||||
|
||||
brightness = self.dps(DPS_INDEX_BRIGHTNESS)
|
||||
brightness = self.dps_conf(CONF_BRIGHTNESS)
|
||||
if brightness is not None:
|
||||
brightness = min(brightness, 255)
|
||||
brightness = max(brightness, 25)
|
||||
self._brightness = brightness
|
||||
|
||||
self._color_temp = self.dps(DPS_INDEX_COLOURTEMP)
|
||||
self._color_temp = self.dps_conf(CONF_COLOR_TEMP)
|
||||
|
||||
|
||||
async_setup_entry = partial(async_setup_entry, DOMAIN, LocaltuyaLight, flow_schema)
|
||||
|
@@ -55,7 +55,9 @@
|
||||
"device_class": "Device Class",
|
||||
"scaling": "Scaling Factor",
|
||||
"state_on": "On Value",
|
||||
"state_off": "Off Value"
|
||||
"state_off": "Off Value",
|
||||
"brightness": "Brightness",
|
||||
"color_temp": "Color Temperature"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +92,9 @@
|
||||
"device_class": "Device Class",
|
||||
"scaling": "Scaling Factor",
|
||||
"state_on": "On Value",
|
||||
"state_off": "Off Value"
|
||||
"state_off": "Off Value",
|
||||
"brightness": "Brightness",
|
||||
"color_temp": "Color Temperature"
|
||||
}
|
||||
},
|
||||
"yaml_import": {
|
||||
|
Reference in New Issue
Block a user