Merge branch 'master' into master

This commit is contained in:
rospogrigio
2022-01-02 09:53:19 +01:00
committed by GitHub
5 changed files with 40 additions and 4 deletions

View File

@@ -73,6 +73,7 @@ localtuya:
color_mode: 21 # Optional, usually 2 or 21, default: "none" color_mode: 21 # Optional, usually 2 or 21, default: "none"
brightness: 22 # Optional, usually 3 or 22, default: "none" brightness: 22 # Optional, usually 3 or 22, default: "none"
color_temp: 23 # Optional, usually 4 or 23, default: "none" color_temp: 23 # Optional, usually 4 or 23, default: "none"
color_temp_reverse: false # Optional, default: false
color: 24 # Optional, usually 5 (RGB_HSV) or 24 (HSV), default: "none" color: 24 # Optional, usually 5 (RGB_HSV) or 24 (HSV), default: "none"
brightness_lower: 29 # Optional, usually 0 or 29, default: 29 brightness_lower: 29 # Optional, usually 0 or 29, default: 29
brightness_upper: 1000 # Optional, usually 255 or 1000, default: 1000 brightness_upper: 1000 # Optional, usually 255 or 1000, default: 1000
@@ -81,7 +82,6 @@ localtuya:
scene: 25 # Optional, usually 6 (RGB_HSV) or 25 (HSV), default: "none" scene: 25 # Optional, usually 6 (RGB_HSV) or 25 (HSV), default: "none"
music_mode: False # Optional, some use internal mic, others, phone mic. Only internal mic is supported, default: "False" music_mode: False # Optional, some use internal mic, others, phone mic. Only internal mic is supported, default: "False"
- platform: sensor - platform: sensor
friendly_name: Plug Voltage friendly_name: Plug Voltage
id: 20 id: 20

View File

@@ -16,6 +16,7 @@ CONF_COLOR = "color"
CONF_COLOR_MODE = "color_mode" CONF_COLOR_MODE = "color_mode"
CONF_COLOR_TEMP_MIN_KELVIN = "color_temp_min_kelvin" CONF_COLOR_TEMP_MIN_KELVIN = "color_temp_min_kelvin"
CONF_COLOR_TEMP_MAX_KELVIN = "color_temp_max_kelvin" CONF_COLOR_TEMP_MAX_KELVIN = "color_temp_max_kelvin"
CONF_COLOR_TEMP_REVERSE = "color_temp_reverse"
CONF_MUSIC_MODE = "music_mode" CONF_MUSIC_MODE = "music_mode"
# switch # switch

View File

@@ -27,6 +27,7 @@ from .const import (
CONF_COLOR_MODE, CONF_COLOR_MODE,
CONF_COLOR_TEMP_MAX_KELVIN, CONF_COLOR_TEMP_MAX_KELVIN,
CONF_COLOR_TEMP_MIN_KELVIN, CONF_COLOR_TEMP_MIN_KELVIN,
CONF_COLOR_TEMP_REVERSE,
CONF_MUSIC_MODE, CONF_MUSIC_MODE,
) )
@@ -36,6 +37,8 @@ MIRED_TO_KELVIN_CONST = 1000000
DEFAULT_MIN_KELVIN = 2700 # MIRED 370 DEFAULT_MIN_KELVIN = 2700 # MIRED 370
DEFAULT_MAX_KELVIN = 6500 # MIRED 153 DEFAULT_MAX_KELVIN = 6500 # MIRED 153
DEFAULT_COLOR_TEMP_REVERSE = False
DEFAULT_LOWER_BRIGHTNESS = 29 DEFAULT_LOWER_BRIGHTNESS = 29
DEFAULT_UPPER_BRIGHTNESS = 1000 DEFAULT_UPPER_BRIGHTNESS = 1000
@@ -117,6 +120,11 @@ def flow_schema(dps):
vol.Optional(CONF_COLOR_TEMP_MAX_KELVIN, default=DEFAULT_MAX_KELVIN): vol.All( vol.Optional(CONF_COLOR_TEMP_MAX_KELVIN, default=DEFAULT_MAX_KELVIN): vol.All(
vol.Coerce(int), vol.Range(min=1500, max=8000) vol.Coerce(int), vol.Range(min=1500, max=8000)
), ),
vol.Optional(
CONF_COLOR_TEMP_REVERSE,
default=DEFAULT_COLOR_TEMP_REVERSE,
description={"suggested_value": DEFAULT_COLOR_TEMP_REVERSE},
): bool,
vol.Optional(CONF_SCENE): vol.In(dps), vol.Optional(CONF_SCENE): vol.In(dps),
vol.Optional( vol.Optional(
CONF_MUSIC_MODE, default=False, description={"suggested_value": False} CONF_MUSIC_MODE, default=False, description={"suggested_value": False}
@@ -154,6 +162,9 @@ class LocaltuyaLight(LocalTuyaEntity, LightEntity):
MIRED_TO_KELVIN_CONST MIRED_TO_KELVIN_CONST
/ self._config.get(CONF_COLOR_TEMP_MAX_KELVIN, DEFAULT_MAX_KELVIN) / self._config.get(CONF_COLOR_TEMP_MAX_KELVIN, DEFAULT_MAX_KELVIN)
) )
self._color_temp_reverse = self._config.get(
CONF_COLOR_TEMP_REVERSE, DEFAULT_COLOR_TEMP_REVERSE
)
self._hs = None self._hs = None
self._effect = None self._effect = None
self._effect_list = [] self._effect_list = []
@@ -199,11 +210,16 @@ class LocaltuyaLight(LocalTuyaEntity, LightEntity):
def color_temp(self): def color_temp(self):
"""Return the color_temp of the light.""" """Return the color_temp of the light."""
if self.has_config(CONF_COLOR_TEMP) and self.is_white_mode: if self.has_config(CONF_COLOR_TEMP) and self.is_white_mode:
color_temp_value = (
self._upper_color_temp - self._color_temp
if self._color_temp_reverse
else self._color_temp
)
return int( return int(
self._max_mired self._max_mired
- ( - (
((self._max_mired - self._min_mired) / self._upper_color_temp) ((self._max_mired - self._min_mired) / self._upper_color_temp)
* self._color_temp * color_temp_value
) )
) )
return None return None
@@ -364,10 +380,16 @@ class LocaltuyaLight(LocalTuyaEntity, LightEntity):
if ATTR_COLOR_TEMP in kwargs and (features & SUPPORT_COLOR_TEMP): if ATTR_COLOR_TEMP in kwargs and (features & SUPPORT_COLOR_TEMP):
if brightness is None: if brightness is None:
brightness = self._brightness brightness = self._brightness
color_temp_value = (
(self._max_mired - self._min_mired)
- (int(kwargs[ATTR_COLOR_TEMP]) - self._min_mired)
if self._color_temp_reverse
else (int(kwargs[ATTR_COLOR_TEMP]) - self._min_mired)
)
color_temp = int( color_temp = int(
self._upper_color_temp self._upper_color_temp
- (self._upper_color_temp / (self._max_mired - self._min_mired)) - (self._upper_color_temp / (self._max_mired - self._min_mired))
* (int(kwargs[ATTR_COLOR_TEMP]) - self._min_mired) * color_temp_value
) )
states[self._config.get(CONF_COLOR_MODE)] = MODE_WHITE states[self._config.get(CONF_COLOR_MODE)] = MODE_WHITE
states[self._config.get(CONF_BRIGHTNESS)] = brightness states[self._config.get(CONF_BRIGHTNESS)] = brightness

View File

@@ -64,6 +64,7 @@
"brightness_lower": "Brightness Lower Value", "brightness_lower": "Brightness Lower Value",
"brightness_upper": "Brightness Upper Value", "brightness_upper": "Brightness Upper Value",
"color_temp": "Color Temperature", "color_temp": "Color Temperature",
"color_temp_reverse": "Color Temperature Reverse",
"color": "Color", "color": "Color",
"color_mode": "Color Mode", "color_mode": "Color Mode",
"color_temp_min_kelvin": "Minimum Color Temperature in K", "color_temp_min_kelvin": "Minimum Color Temperature in K",
@@ -120,6 +121,7 @@
"brightness_lower": "Brightness Lower Value", "brightness_lower": "Brightness Lower Value",
"brightness_upper": "Brightness Upper Value", "brightness_upper": "Brightness Upper Value",
"color_temp": "Color Temperature", "color_temp": "Color Temperature",
"color_temp_reverse": "Color Temperature Reverse",
"color": "Color", "color": "Color",
"color_mode": "Color Mode", "color_mode": "Color Mode",
"color_temp_min_kelvin": "Minimum Color Temperature in K", "color_temp_min_kelvin": "Minimum Color Temperature in K",

13
info.md
View File

@@ -68,7 +68,18 @@ localtuya:
- platform: light - platform: light
friendly_name: Device Light friendly_name: Device Light
id: 4 id: 4 # Usually 1 or 20
color_mode: 21 # Optional, usually 2 or 21, default: "none"
brightness: 22 # Optional, usually 3 or 22, default: "none"
color_temp: 23 # Optional, usually 4 or 23, default: "none"
color_temp_reverse: false # Optional, default: false
color: 24 # Optional, usually 5 (RGB_HSV) or 24 (HSV), default: "none"
brightness_lower: 29 # Optional, usually 0 or 29, default: 29
brightness_upper: 1000 # Optional, usually 255 or 1000, default: 1000
color_temp_min_kelvin: 2700 # Optional, default: 2700
color_temp_max_kelvin: 6500 # Optional, default: 6500
scene: 25 # Optional, usually 6 (RGB_HSV) or 25 (HSV), default: "none"
music_mode: False # Optional, some use internal mic, others, phone mic. Only internal mic is supported, default: "False"
- platform: sensor - platform: sensor
friendly_name: Plug Voltage friendly_name: Plug Voltage