|
35 | 35 | from .storage.const import ( |
36 | 36 | CONF_COLOR_TEMP_MAX, |
37 | 37 | CONF_COLOR_TEMP_MIN, |
38 | | - CONF_DPT, |
39 | 38 | CONF_ENTITY, |
40 | 39 | CONF_GA_BLUE_BRIGHTNESS, |
41 | 40 | CONF_GA_BLUE_SWITCH, |
|
45 | 44 | CONF_GA_GREEN_BRIGHTNESS, |
46 | 45 | CONF_GA_GREEN_SWITCH, |
47 | 46 | CONF_GA_HUE, |
48 | | - CONF_GA_PASSIVE, |
49 | 47 | CONF_GA_RED_BRIGHTNESS, |
50 | 48 | CONF_GA_RED_SWITCH, |
51 | 49 | CONF_GA_SATURATION, |
52 | | - CONF_GA_STATE, |
53 | 50 | CONF_GA_SWITCH, |
54 | 51 | CONF_GA_WHITE_BRIGHTNESS, |
55 | 52 | CONF_GA_WHITE_SWITCH, |
56 | | - CONF_GA_WRITE, |
57 | 53 | ) |
58 | 54 | from .storage.entity_store_schema import LightColorMode |
| 55 | +from .storage.util import ConfigExtractor |
59 | 56 |
|
60 | 57 |
|
61 | 58 | async def async_setup_entry( |
@@ -203,94 +200,92 @@ def individual_color_addresses(color: str, feature: str) -> Any | None: |
203 | 200 | def _create_ui_light(xknx: XKNX, knx_config: ConfigType, name: str) -> XknxLight: |
204 | 201 | """Return a KNX Light device to be used within XKNX.""" |
205 | 202 |
|
206 | | - def get_write(key: str) -> str | None: |
207 | | - """Get the write group address.""" |
208 | | - return knx_config[key][CONF_GA_WRITE] if key in knx_config else None |
209 | | - |
210 | | - def get_state(key: str) -> list[Any] | None: |
211 | | - """Get the state group address.""" |
212 | | - return ( |
213 | | - [knx_config[key][CONF_GA_STATE], *knx_config[key][CONF_GA_PASSIVE]] |
214 | | - if key in knx_config |
215 | | - else None |
216 | | - ) |
217 | | - |
218 | | - def get_dpt(key: str) -> str | None: |
219 | | - """Get the DPT.""" |
220 | | - return knx_config[key].get(CONF_DPT) if key in knx_config else None |
| 203 | + conf = ConfigExtractor(knx_config) |
221 | 204 |
|
222 | 205 | group_address_tunable_white = None |
223 | 206 | group_address_tunable_white_state = None |
224 | 207 | group_address_color_temp = None |
225 | 208 | group_address_color_temp_state = None |
| 209 | + |
226 | 210 | color_temperature_type = ColorTemperatureType.UINT_2_BYTE |
227 | | - if ga_color_temp := knx_config.get(CONF_GA_COLOR_TEMP): |
228 | | - if ga_color_temp[CONF_DPT] == ColorTempModes.RELATIVE.value: |
229 | | - group_address_tunable_white = ga_color_temp[CONF_GA_WRITE] |
230 | | - group_address_tunable_white_state = [ |
231 | | - ga_color_temp[CONF_GA_STATE], |
232 | | - *ga_color_temp[CONF_GA_PASSIVE], |
233 | | - ] |
| 211 | + if _color_temp_dpt := conf.get_dpt(CONF_GA_COLOR_TEMP): |
| 212 | + if _color_temp_dpt == ColorTempModes.RELATIVE.value: |
| 213 | + group_address_tunable_white = conf.get_write(CONF_GA_COLOR_TEMP) |
| 214 | + group_address_tunable_white_state = conf.get_state_and_passive( |
| 215 | + CONF_GA_COLOR_TEMP |
| 216 | + ) |
234 | 217 | else: |
235 | 218 | # absolute uint or float |
236 | | - group_address_color_temp = ga_color_temp[CONF_GA_WRITE] |
237 | | - group_address_color_temp_state = [ |
238 | | - ga_color_temp[CONF_GA_STATE], |
239 | | - *ga_color_temp[CONF_GA_PASSIVE], |
240 | | - ] |
241 | | - if ga_color_temp[CONF_DPT] == ColorTempModes.ABSOLUTE_FLOAT.value: |
| 219 | + group_address_color_temp = conf.get_write(CONF_GA_COLOR_TEMP) |
| 220 | + group_address_color_temp_state = conf.get_state_and_passive( |
| 221 | + CONF_GA_COLOR_TEMP |
| 222 | + ) |
| 223 | + if _color_temp_dpt == ColorTempModes.ABSOLUTE_FLOAT.value: |
242 | 224 | color_temperature_type = ColorTemperatureType.FLOAT_2_BYTE |
243 | 225 |
|
244 | | - _color_dpt = get_dpt(CONF_GA_COLOR) |
| 226 | + color_dpt = conf.get_dpt(CONF_GA_COLOR) |
| 227 | + |
245 | 228 | return XknxLight( |
246 | 229 | xknx, |
247 | 230 | name=name, |
248 | | - group_address_switch=get_write(CONF_GA_SWITCH), |
249 | | - group_address_switch_state=get_state(CONF_GA_SWITCH), |
250 | | - group_address_brightness=get_write(CONF_GA_BRIGHTNESS), |
251 | | - group_address_brightness_state=get_state(CONF_GA_BRIGHTNESS), |
252 | | - group_address_color=get_write(CONF_GA_COLOR) |
253 | | - if _color_dpt == LightColorMode.RGB |
| 231 | + group_address_switch=conf.get_write(CONF_GA_SWITCH), |
| 232 | + group_address_switch_state=conf.get_state_and_passive(CONF_GA_SWITCH), |
| 233 | + group_address_brightness=conf.get_write(CONF_GA_BRIGHTNESS), |
| 234 | + group_address_brightness_state=conf.get_state_and_passive(CONF_GA_BRIGHTNESS), |
| 235 | + group_address_color=conf.get_write(CONF_GA_COLOR) |
| 236 | + if color_dpt == LightColorMode.RGB |
254 | 237 | else None, |
255 | | - group_address_color_state=get_state(CONF_GA_COLOR) |
256 | | - if _color_dpt == LightColorMode.RGB |
| 238 | + group_address_color_state=conf.get_state_and_passive(CONF_GA_COLOR) |
| 239 | + if color_dpt == LightColorMode.RGB |
257 | 240 | else None, |
258 | | - group_address_rgbw=get_write(CONF_GA_COLOR) |
259 | | - if _color_dpt == LightColorMode.RGBW |
| 241 | + group_address_rgbw=conf.get_write(CONF_GA_COLOR) |
| 242 | + if color_dpt == LightColorMode.RGBW |
260 | 243 | else None, |
261 | | - group_address_rgbw_state=get_state(CONF_GA_COLOR) |
262 | | - if _color_dpt == LightColorMode.RGBW |
| 244 | + group_address_rgbw_state=conf.get_state_and_passive(CONF_GA_COLOR) |
| 245 | + if color_dpt == LightColorMode.RGBW |
263 | 246 | else None, |
264 | | - group_address_hue=get_write(CONF_GA_HUE), |
265 | | - group_address_hue_state=get_state(CONF_GA_HUE), |
266 | | - group_address_saturation=get_write(CONF_GA_SATURATION), |
267 | | - group_address_saturation_state=get_state(CONF_GA_SATURATION), |
268 | | - group_address_xyy_color=get_write(CONF_GA_COLOR) |
269 | | - if _color_dpt == LightColorMode.XYY |
| 247 | + group_address_hue=conf.get_write(CONF_GA_HUE), |
| 248 | + group_address_hue_state=conf.get_state_and_passive(CONF_GA_HUE), |
| 249 | + group_address_saturation=conf.get_write(CONF_GA_SATURATION), |
| 250 | + group_address_saturation_state=conf.get_state_and_passive(CONF_GA_SATURATION), |
| 251 | + group_address_xyy_color=conf.get_write(CONF_GA_COLOR) |
| 252 | + if color_dpt == LightColorMode.XYY |
270 | 253 | else None, |
271 | | - group_address_xyy_color_state=get_write(CONF_GA_COLOR) |
272 | | - if _color_dpt == LightColorMode.XYY |
| 254 | + group_address_xyy_color_state=conf.get_write(CONF_GA_COLOR) |
| 255 | + if color_dpt == LightColorMode.XYY |
273 | 256 | else None, |
274 | 257 | group_address_tunable_white=group_address_tunable_white, |
275 | 258 | group_address_tunable_white_state=group_address_tunable_white_state, |
276 | 259 | group_address_color_temperature=group_address_color_temp, |
277 | 260 | group_address_color_temperature_state=group_address_color_temp_state, |
278 | | - group_address_switch_red=get_write(CONF_GA_RED_SWITCH), |
279 | | - group_address_switch_red_state=get_state(CONF_GA_RED_SWITCH), |
280 | | - group_address_brightness_red=get_write(CONF_GA_RED_BRIGHTNESS), |
281 | | - group_address_brightness_red_state=get_state(CONF_GA_RED_BRIGHTNESS), |
282 | | - group_address_switch_green=get_write(CONF_GA_GREEN_SWITCH), |
283 | | - group_address_switch_green_state=get_state(CONF_GA_GREEN_SWITCH), |
284 | | - group_address_brightness_green=get_write(CONF_GA_GREEN_BRIGHTNESS), |
285 | | - group_address_brightness_green_state=get_state(CONF_GA_GREEN_BRIGHTNESS), |
286 | | - group_address_switch_blue=get_write(CONF_GA_BLUE_SWITCH), |
287 | | - group_address_switch_blue_state=get_state(CONF_GA_BLUE_SWITCH), |
288 | | - group_address_brightness_blue=get_write(CONF_GA_BLUE_BRIGHTNESS), |
289 | | - group_address_brightness_blue_state=get_state(CONF_GA_BLUE_BRIGHTNESS), |
290 | | - group_address_switch_white=get_write(CONF_GA_WHITE_SWITCH), |
291 | | - group_address_switch_white_state=get_state(CONF_GA_WHITE_SWITCH), |
292 | | - group_address_brightness_white=get_write(CONF_GA_WHITE_BRIGHTNESS), |
293 | | - group_address_brightness_white_state=get_state(CONF_GA_WHITE_BRIGHTNESS), |
| 261 | + group_address_switch_red=conf.get_write(CONF_GA_RED_SWITCH), |
| 262 | + group_address_switch_red_state=conf.get_state_and_passive(CONF_GA_RED_SWITCH), |
| 263 | + group_address_brightness_red=conf.get_write(CONF_GA_RED_BRIGHTNESS), |
| 264 | + group_address_brightness_red_state=conf.get_state_and_passive( |
| 265 | + CONF_GA_RED_BRIGHTNESS |
| 266 | + ), |
| 267 | + group_address_switch_green=conf.get_write(CONF_GA_GREEN_SWITCH), |
| 268 | + group_address_switch_green_state=conf.get_state_and_passive( |
| 269 | + CONF_GA_GREEN_SWITCH |
| 270 | + ), |
| 271 | + group_address_brightness_green=conf.get_write(CONF_GA_GREEN_BRIGHTNESS), |
| 272 | + group_address_brightness_green_state=conf.get_state_and_passive( |
| 273 | + CONF_GA_GREEN_BRIGHTNESS |
| 274 | + ), |
| 275 | + group_address_switch_blue=conf.get_write(CONF_GA_BLUE_SWITCH), |
| 276 | + group_address_switch_blue_state=conf.get_state_and_passive(CONF_GA_BLUE_SWITCH), |
| 277 | + group_address_brightness_blue=conf.get_write(CONF_GA_BLUE_BRIGHTNESS), |
| 278 | + group_address_brightness_blue_state=conf.get_state_and_passive( |
| 279 | + CONF_GA_BLUE_BRIGHTNESS |
| 280 | + ), |
| 281 | + group_address_switch_white=conf.get_write(CONF_GA_WHITE_SWITCH), |
| 282 | + group_address_switch_white_state=conf.get_state_and_passive( |
| 283 | + CONF_GA_WHITE_SWITCH |
| 284 | + ), |
| 285 | + group_address_brightness_white=conf.get_write(CONF_GA_WHITE_BRIGHTNESS), |
| 286 | + group_address_brightness_white_state=conf.get_state_and_passive( |
| 287 | + CONF_GA_WHITE_BRIGHTNESS |
| 288 | + ), |
294 | 289 | color_temperature_type=color_temperature_type, |
295 | 290 | min_kelvin=knx_config[CONF_COLOR_TEMP_MIN], |
296 | 291 | max_kelvin=knx_config[CONF_COLOR_TEMP_MAX], |
|
0 commit comments