def _create_light(knx_module: XKNX, config: ConfigType) -> XknxLight: """Return a KNX Light device to be used within XKNX.""" group_address_tunable_white = None group_address_tunable_white_state = None group_address_color_temp = None group_address_color_temp_state = None if config[LightSchema.CONF_COLOR_TEMP_MODE] == ColorTempModes.absolute: group_address_color_temp = config.get( LightSchema.CONF_COLOR_TEMP_ADDRESS) group_address_color_temp_state = config.get( LightSchema.CONF_COLOR_TEMP_STATE_ADDRESS) elif config[LightSchema.CONF_COLOR_TEMP_MODE] == ColorTempModes.relative: group_address_tunable_white = config.get( LightSchema.CONF_COLOR_TEMP_ADDRESS) group_address_tunable_white_state = config.get( LightSchema.CONF_COLOR_TEMP_STATE_ADDRESS) return XknxLight( knx_module, name=config[CONF_NAME], group_address_switch=config[CONF_ADDRESS], group_address_switch_state=config.get(LightSchema.CONF_STATE_ADDRESS), group_address_brightness=config.get( LightSchema.CONF_BRIGHTNESS_ADDRESS), group_address_brightness_state=config.get( LightSchema.CONF_BRIGHTNESS_STATE_ADDRESS), group_address_color=config.get(LightSchema.CONF_COLOR_ADDRESS), group_address_color_state=config.get( LightSchema.CONF_COLOR_STATE_ADDRESS), group_address_rgbw=config.get(LightSchema.CONF_RGBW_ADDRESS), group_address_rgbw_state=config.get( LightSchema.CONF_RGBW_STATE_ADDRESS), group_address_tunable_white=group_address_tunable_white, group_address_tunable_white_state=group_address_tunable_white_state, group_address_color_temperature=group_address_color_temp, group_address_color_temperature_state=group_address_color_temp_state, min_kelvin=config[LightSchema.CONF_MIN_KELVIN], max_kelvin=config[LightSchema.CONF_MAX_KELVIN], )
def async_add_entities_config(hass, config, async_add_entities): """Set up light for KNX platform configured within platform.""" group_address_tunable_white = None group_address_tunable_white_state = None group_address_color_temp = None group_address_color_temp_state = None if config[CONF_COLOR_TEMP_MODE] == ColorTempModes.absolute: group_address_color_temp = config.get(CONF_COLOR_TEMP_ADDRESS) group_address_color_temp_state = config.get( CONF_COLOR_TEMP_STATE_ADDRESS) elif config[CONF_COLOR_TEMP_MODE] == ColorTempModes.relative: group_address_tunable_white = config.get(CONF_COLOR_TEMP_ADDRESS) group_address_tunable_white_state = config.get( CONF_COLOR_TEMP_STATE_ADDRESS) light = XknxLight( hass.data[DATA_XKNX].xknx, name=config[CONF_NAME], group_address_switch=config[CONF_ADDRESS], group_address_switch_state=config.get(CONF_STATE_ADDRESS), group_address_brightness=config.get(CONF_BRIGHTNESS_ADDRESS), group_address_brightness_state=config.get( CONF_BRIGHTNESS_STATE_ADDRESS), group_address_color=config.get(CONF_COLOR_ADDRESS), group_address_color_state=config.get(CONF_COLOR_STATE_ADDRESS), group_address_rgbw=config.get(CONF_RGBW_ADDRESS), group_address_rgbw_state=config.get(CONF_RGBW_STATE_ADDRESS), group_address_tunable_white=group_address_tunable_white, group_address_tunable_white_state=group_address_tunable_white_state, group_address_color_temperature=group_address_color_temp, group_address_color_temperature_state=group_address_color_temp_state, min_kelvin=config[CONF_MIN_KELVIN], max_kelvin=config[CONF_MAX_KELVIN], ) hass.data[DATA_XKNX].xknx.devices.add(light) async_add_entities([KNXLight(light)])
def _create_light(xknx: XKNX, config: ConfigType) -> XknxLight: """Return a KNX Light device to be used within XKNX.""" def individual_color_addresses(color: str, feature: str) -> Any | None: """Load individual color address list from configuration structure.""" if ( LightSchema.CONF_INDIVIDUAL_COLORS not in config or color not in config[LightSchema.CONF_INDIVIDUAL_COLORS] ): return None return config[LightSchema.CONF_INDIVIDUAL_COLORS][color].get(feature) group_address_tunable_white = None group_address_tunable_white_state = None group_address_color_temp = None group_address_color_temp_state = None if config[LightSchema.CONF_COLOR_TEMP_MODE] == ColorTempModes.ABSOLUTE: group_address_color_temp = config.get(LightSchema.CONF_COLOR_TEMP_ADDRESS) group_address_color_temp_state = config.get( LightSchema.CONF_COLOR_TEMP_STATE_ADDRESS ) elif config[LightSchema.CONF_COLOR_TEMP_MODE] == ColorTempModes.RELATIVE: group_address_tunable_white = config.get(LightSchema.CONF_COLOR_TEMP_ADDRESS) group_address_tunable_white_state = config.get( LightSchema.CONF_COLOR_TEMP_STATE_ADDRESS ) return XknxLight( xknx, name=config[CONF_NAME], group_address_switch=config.get(KNX_ADDRESS), group_address_switch_state=config.get(LightSchema.CONF_STATE_ADDRESS), group_address_brightness=config.get(LightSchema.CONF_BRIGHTNESS_ADDRESS), group_address_brightness_state=config.get( LightSchema.CONF_BRIGHTNESS_STATE_ADDRESS ), group_address_color=config.get(LightSchema.CONF_COLOR_ADDRESS), group_address_color_state=config.get(LightSchema.CONF_COLOR_STATE_ADDRESS), group_address_rgbw=config.get(LightSchema.CONF_RGBW_ADDRESS), group_address_rgbw_state=config.get(LightSchema.CONF_RGBW_STATE_ADDRESS), group_address_tunable_white=group_address_tunable_white, group_address_tunable_white_state=group_address_tunable_white_state, group_address_color_temperature=group_address_color_temp, group_address_color_temperature_state=group_address_color_temp_state, group_address_switch_red=individual_color_addresses( LightSchema.CONF_RED, KNX_ADDRESS ), group_address_switch_red_state=individual_color_addresses( LightSchema.CONF_RED, LightSchema.CONF_STATE_ADDRESS ), group_address_brightness_red=individual_color_addresses( LightSchema.CONF_RED, LightSchema.CONF_BRIGHTNESS_ADDRESS ), group_address_brightness_red_state=individual_color_addresses( LightSchema.CONF_RED, LightSchema.CONF_BRIGHTNESS_STATE_ADDRESS ), group_address_switch_green=individual_color_addresses( LightSchema.CONF_RED, KNX_ADDRESS ), group_address_switch_green_state=individual_color_addresses( LightSchema.CONF_RED, LightSchema.CONF_STATE_ADDRESS ), group_address_brightness_green=individual_color_addresses( LightSchema.CONF_RED, LightSchema.CONF_BRIGHTNESS_ADDRESS ), group_address_brightness_green_state=individual_color_addresses( LightSchema.CONF_RED, LightSchema.CONF_BRIGHTNESS_STATE_ADDRESS ), group_address_switch_blue=individual_color_addresses( LightSchema.CONF_RED, KNX_ADDRESS ), group_address_switch_blue_state=individual_color_addresses( LightSchema.CONF_RED, LightSchema.CONF_STATE_ADDRESS ), group_address_brightness_blue=individual_color_addresses( LightSchema.CONF_RED, LightSchema.CONF_BRIGHTNESS_ADDRESS ), group_address_brightness_blue_state=individual_color_addresses( LightSchema.CONF_RED, LightSchema.CONF_BRIGHTNESS_STATE_ADDRESS ), group_address_switch_white=individual_color_addresses( LightSchema.CONF_RED, KNX_ADDRESS ), group_address_switch_white_state=individual_color_addresses( LightSchema.CONF_RED, LightSchema.CONF_STATE_ADDRESS ), group_address_brightness_white=individual_color_addresses( LightSchema.CONF_RED, LightSchema.CONF_BRIGHTNESS_ADDRESS ), group_address_brightness_white_state=individual_color_addresses( LightSchema.CONF_RED, LightSchema.CONF_BRIGHTNESS_STATE_ADDRESS ), min_kelvin=config[LightSchema.CONF_MIN_KELVIN], max_kelvin=config[LightSchema.CONF_MAX_KELVIN], )
def _create_light(knx_module: XKNX, config: ConfigType) -> XknxLight: """Return a KNX Light device to be used within XKNX.""" group_address_tunable_white = None group_address_tunable_white_state = None group_address_color_temp = None group_address_color_temp_state = None if config[LightSchema.CONF_COLOR_TEMP_MODE] == ColorTempModes.ABSOLUTE: group_address_color_temp = config.get( LightSchema.CONF_COLOR_TEMP_ADDRESS) group_address_color_temp_state = config.get( LightSchema.CONF_COLOR_TEMP_STATE_ADDRESS) elif config[LightSchema.CONF_COLOR_TEMP_MODE] == ColorTempModes.RELATIVE: group_address_tunable_white = config.get( LightSchema.CONF_COLOR_TEMP_ADDRESS) group_address_tunable_white_state = config.get( LightSchema.CONF_COLOR_TEMP_STATE_ADDRESS) ( red_switch, red_switch_state, red_brightness, red_brightness_state, ) = _create_light_color(LightSchema.CONF_RED, config) ( green_switch, green_switch_state, green_brightness, green_brightness_state, ) = _create_light_color(LightSchema.CONF_GREEN, config) ( blue_switch, blue_switch_state, blue_brightness, blue_brightness_state, ) = _create_light_color(LightSchema.CONF_BLUE, config) ( white_switch, white_switch_state, white_brightness, white_brightness_state, ) = _create_light_color(LightSchema.CONF_WHITE, config) return XknxLight( knx_module, name=config[CONF_NAME], group_address_switch=config.get(KNX_ADDRESS), group_address_switch_state=config.get(LightSchema.CONF_STATE_ADDRESS), group_address_brightness=config.get( LightSchema.CONF_BRIGHTNESS_ADDRESS), group_address_brightness_state=config.get( LightSchema.CONF_BRIGHTNESS_STATE_ADDRESS), group_address_color=config.get(LightSchema.CONF_COLOR_ADDRESS), group_address_color_state=config.get( LightSchema.CONF_COLOR_STATE_ADDRESS), group_address_rgbw=config.get(LightSchema.CONF_RGBW_ADDRESS), group_address_rgbw_state=config.get( LightSchema.CONF_RGBW_STATE_ADDRESS), group_address_tunable_white=group_address_tunable_white, group_address_tunable_white_state=group_address_tunable_white_state, group_address_color_temperature=group_address_color_temp, group_address_color_temperature_state=group_address_color_temp_state, group_address_switch_red=red_switch, group_address_switch_red_state=red_switch_state, group_address_brightness_red=red_brightness, group_address_brightness_red_state=red_brightness_state, group_address_switch_green=green_switch, group_address_switch_green_state=green_switch_state, group_address_brightness_green=green_brightness, group_address_brightness_green_state=green_brightness_state, group_address_switch_blue=blue_switch, group_address_switch_blue_state=blue_switch_state, group_address_brightness_blue=blue_brightness, group_address_brightness_blue_state=blue_brightness_state, group_address_switch_white=white_switch, group_address_switch_white_state=white_switch_state, group_address_brightness_white=white_brightness, group_address_brightness_white_state=white_brightness_state, min_kelvin=config[LightSchema.CONF_MIN_KELVIN], max_kelvin=config[LightSchema.CONF_MAX_KELVIN], )