5
5
from homeassistant .components .light import (
6
6
ATTR_BRIGHTNESS ,
7
7
ATTR_COLOR_MODE ,
8
- ATTR_COLOR_TEMP ,
9
8
ATTR_EFFECT ,
10
9
ATTR_HS_COLOR ,
11
10
ATTR_RGB_COLOR ,
15
14
LightEntityFeature ,
16
15
)
17
16
from homeassistant .helpers .restore_state import RestoreEntity
17
+ from homeassistant .util import color as color_util
18
18
19
19
from .core .gate .base import XGateway
20
20
from .hass .entity import XEntity
21
21
22
22
23
+ ATTR_COLOR_TEMP = "color_temp"
24
+
25
+
23
26
# noinspection PyUnusedLocal
24
27
async def async_setup_entry (hass , entry , async_add_entities ) -> None :
25
28
XEntity .ADD [entry .entry_id + "light" ] = async_add_entities
@@ -39,11 +42,11 @@ def on_init(self):
39
42
self ._attr_color_mode = ColorMode .COLOR_TEMP
40
43
modes .add (ColorMode .COLOR_TEMP )
41
44
if hasattr (conv , "minm" ) and hasattr (conv , "maxm" ):
42
- self ._attr_min_mireds = conv .minm
43
- self ._attr_max_mireds = conv .maxm
45
+ self ._attr_max_color_temp_kelvin = color_util . color_temperature_mired_to_kelvin ( conv .minm )
46
+ self ._attr_min_color_temp_kelvin = color_util . color_temperature_mired_to_kelvin ( conv .maxm )
44
47
elif hasattr (conv , "mink" ) and hasattr (conv , "maxk" ):
45
- self ._attr_min_mireds = int ( 1000000 / conv .maxk )
46
- self ._attr_max_mireds = int ( 1000000 / conv .mink )
48
+ self ._attr_max_color_temp_kelvin = conv .maxk
49
+ self ._attr_min_color_temp_kelvin = conv .mink
47
50
elif conv .attr == ATTR_HS_COLOR :
48
51
self .listen_attrs .add (conv .attr )
49
52
modes .add (ColorMode .HS )
@@ -65,7 +68,7 @@ def set_state(self, data: dict):
65
68
if ATTR_BRIGHTNESS in data :
66
69
self ._attr_brightness = data [ATTR_BRIGHTNESS ]
67
70
if ATTR_COLOR_TEMP in data :
68
- self ._attr_color_temp = data [ATTR_COLOR_TEMP ]
71
+ self ._attr_color_temp_kelvin = color_util . color_temperature_mired_to_kelvin ( data [ATTR_COLOR_TEMP ])
69
72
self ._attr_color_mode = ColorMode .COLOR_TEMP
70
73
if ATTR_HS_COLOR in data :
71
74
self ._attr_hs_color = data [ATTR_HS_COLOR ]
@@ -82,7 +85,7 @@ def get_state(self) -> dict:
82
85
return {
83
86
self .attr : self ._attr_is_on ,
84
87
ATTR_BRIGHTNESS : self ._attr_brightness ,
85
- ATTR_COLOR_TEMP : self ._attr_color_temp ,
88
+ ATTR_COLOR_TEMP : color_util . color_temperature_kelvin_to_mired ( self ._attr_color_temp_kelvin ) ,
86
89
}
87
90
88
91
async def async_turn_on (self , ** kwargs ):
0 commit comments