From 3b5f4ce10cbd8c10f484dfb456d04e4176637c98 Mon Sep 17 00:00:00 2001 From: Bram Date: Wed, 1 Jan 2025 17:44:03 +0100 Subject: [PATCH] feat: add test coverage --- .../powercalc/power_profile/power_profile.py | 3 + tests/power_profile/test_power_profile.py | 72 +++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/custom_components/powercalc/power_profile/power_profile.py b/custom_components/powercalc/power_profile/power_profile.py index bd2d82841..860e1060c 100644 --- a/custom_components/powercalc/power_profile/power_profile.py +++ b/custom_components/powercalc/power_profile/power_profile.py @@ -351,6 +351,9 @@ def _load_json() -> None: @property async def needs_user_configuration(self) -> bool: """Check whether this profile needs user configuration.""" + if self.calculation_strategy == CalculationStrategy.MULTI_SWITCH: + return True + if self.needs_fixed_config or self.needs_linear_config: return True diff --git a/tests/power_profile/test_power_profile.py b/tests/power_profile/test_power_profile.py index 8e9758f00..594f0ccb0 100644 --- a/tests/power_profile/test_power_profile.py +++ b/tests/power_profile/test_power_profile.py @@ -1,3 +1,5 @@ +from typing import Any + import pytest from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant, State @@ -309,3 +311,73 @@ async def test_device_type(hass: HomeAssistant) -> None: ) assert power_profile.device_type == DeviceType.SMART_SPEAKER + + +@pytest.mark.parametrize( + "json_data,expected_result", + [ + ( + { + "calculation_strategy": CalculationStrategy.FIXED, + }, + True, + ), + ( + { + "calculation_strategy": CalculationStrategy.LINEAR, + }, + True, + ), + ( + { + "calculation_strategy": CalculationStrategy.COMPOSITE, + "fields": { + "foo": { + "label": "Foo", + "selector": {"entity": {}}, + }, + }, + }, + True, + ), + ( + { + "calculation_strategy": CalculationStrategy.FIXED, + "fixed_config": { + "power": 50, + }, + }, + False, + ), + ( + { + "calculation_strategy": CalculationStrategy.LINEAR, + "linear_config": { + "min_power": 50, + "max_power": 100, + }, + }, + False, + ), + ( + { + "calculation_strategy": CalculationStrategy.MULTI_SWITCH, + "multi_switch_config": { + "power": 0.725, + "power_off": 0.225, + }, + }, + True, + ), + ], +) +async def test_needs_user_configuration(hass: HomeAssistant, json_data: dict[str, Any], expected_result: bool) -> None: + power_profile = PowerProfile( + hass, + manufacturer="test", + model="test", + directory=get_test_profile_dir("media_player"), + json_data=json_data, + ) + + assert await power_profile.needs_user_configuration == expected_result