diff --git a/custom_components/powercalc/power_profile/library.py b/custom_components/powercalc/power_profile/library.py index 2df7d9372..efc4572d6 100644 --- a/custom_components/powercalc/power_profile/library.py +++ b/custom_components/powercalc/power_profile/library.py @@ -137,6 +137,10 @@ async def _create_power_profile( directory=directory, json_data=json_data, ) + # When the power profile supplies multiple sub profiles we select one by default + if not profile.sub_profile and profile.sub_profile_select: + profile.select_sub_profile(profile.sub_profile_select["default"]) + except FileNotFoundError: _LOGGER.error("model.json file not found in directory %s", directory) return None diff --git a/tests/power_profile/device_types/test_infrared_light.py b/tests/power_profile/device_types/test_infrared_light.py new file mode 100644 index 000000000..94dc0f2ef --- /dev/null +++ b/tests/power_profile/device_types/test_infrared_light.py @@ -0,0 +1,70 @@ +from homeassistant.const import CONF_ENTITY_ID, STATE_OFF, STATE_ON +from homeassistant.core import HomeAssistant +from homeassistant.components.light import ColorMode, ATTR_BRIGHTNESS, ATTR_COLOR_MODE, ATTR_COLOR_TEMP +from custom_components.test.light import MockLight + +from ...common import create_mock_light_entity + +from custom_components.powercalc.const import ( + CONF_CUSTOM_MODEL_DIRECTORY, + CONF_MANUFACTURER, + CONF_MODEL, +) +from tests.common import get_test_profile_dir, run_powercalc_setup_yaml_config + + +async def test_infrared_light(hass: HomeAssistant): + """ + Infrared capable light with several sub profiles + """ + power_sensor_id = "sensor.test_power" + light_id = "light.test" + + light_mock = MockLight("test") + light_mock.manufacturer = "LIFX" + light_mock.model = "LIFX A19 Night Vision" + light_mock.supported_color_modes = [ColorMode.HS, ColorMode.COLOR_TEMP] + + await create_mock_light_entity(hass, light_mock) + + await run_powercalc_setup_yaml_config( + hass, + { + CONF_ENTITY_ID: light_id, + CONF_MANUFACTURER: light_mock.manufacturer, + CONF_MODEL: light_mock.model, + CONF_CUSTOM_MODEL_DIRECTORY: get_test_profile_dir("infrared_light"), + }, + ) + + power_state = hass.states.get(power_sensor_id) + assert power_state + + hass.states.async_set( + light_id, + STATE_ON, + { + "infrared_brightness": "50%", + ATTR_BRIGHTNESS: 11, + ATTR_COLOR_MODE: ColorMode.COLOR_TEMP, + ATTR_COLOR_TEMP: 601 + } + ) + await hass.async_block_till_done() + + assert hass.states.get(power_sensor_id).state == "4.37" + + hass.states.async_set( + light_id, + STATE_ON, + { + "infrared_brightness": "25%", + ATTR_BRIGHTNESS: 11, + ATTR_COLOR_MODE: ColorMode.COLOR_TEMP, + ATTR_COLOR_TEMP: 601 + } + ) + await hass.async_block_till_done() + + assert hass.states.get(power_sensor_id).state == "2.59" + diff --git a/tests/testing_config/powercalc_profiles/infrared_light/infrared_100/color_temp.csv.gz b/tests/testing_config/powercalc_profiles/infrared_light/infrared_100/color_temp.csv.gz new file mode 100644 index 000000000..d4bca0988 Binary files /dev/null and b/tests/testing_config/powercalc_profiles/infrared_light/infrared_100/color_temp.csv.gz differ diff --git a/tests/testing_config/powercalc_profiles/infrared_light/infrared_100/hs.csv.gz b/tests/testing_config/powercalc_profiles/infrared_light/infrared_100/hs.csv.gz new file mode 100644 index 000000000..33bcb45fe Binary files /dev/null and b/tests/testing_config/powercalc_profiles/infrared_light/infrared_100/hs.csv.gz differ diff --git a/tests/testing_config/powercalc_profiles/infrared_light/infrared_100/model.json b/tests/testing_config/powercalc_profiles/infrared_light/infrared_100/model.json new file mode 100644 index 000000000..88c5a92c8 --- /dev/null +++ b/tests/testing_config/powercalc_profiles/infrared_light/infrared_100/model.json @@ -0,0 +1,3 @@ +{ + "standby_power": 8.37 +} \ No newline at end of file diff --git a/tests/testing_config/powercalc_profiles/infrared_light/infrared_25/color_temp.csv.gz b/tests/testing_config/powercalc_profiles/infrared_light/infrared_25/color_temp.csv.gz new file mode 100644 index 000000000..2b81f35db Binary files /dev/null and b/tests/testing_config/powercalc_profiles/infrared_light/infrared_25/color_temp.csv.gz differ diff --git a/tests/testing_config/powercalc_profiles/infrared_light/infrared_25/hs.csv.gz b/tests/testing_config/powercalc_profiles/infrared_light/infrared_25/hs.csv.gz new file mode 100644 index 000000000..1664e8f84 Binary files /dev/null and b/tests/testing_config/powercalc_profiles/infrared_light/infrared_25/hs.csv.gz differ diff --git a/tests/testing_config/powercalc_profiles/infrared_light/infrared_25/model.json b/tests/testing_config/powercalc_profiles/infrared_light/infrared_25/model.json new file mode 100644 index 000000000..f447c3ec4 --- /dev/null +++ b/tests/testing_config/powercalc_profiles/infrared_light/infrared_25/model.json @@ -0,0 +1,3 @@ +{ + "standby_power": 2.38 +} \ No newline at end of file diff --git a/tests/testing_config/powercalc_profiles/infrared_light/infrared_50/color_temp.csv.gz b/tests/testing_config/powercalc_profiles/infrared_light/infrared_50/color_temp.csv.gz new file mode 100644 index 000000000..64e764e6a Binary files /dev/null and b/tests/testing_config/powercalc_profiles/infrared_light/infrared_50/color_temp.csv.gz differ diff --git a/tests/testing_config/powercalc_profiles/infrared_light/infrared_off/color_temp.csv.gz b/tests/testing_config/powercalc_profiles/infrared_light/infrared_off/color_temp.csv.gz new file mode 100644 index 000000000..938bf7149 Binary files /dev/null and b/tests/testing_config/powercalc_profiles/infrared_light/infrared_off/color_temp.csv.gz differ