Skip to content

Commit

Permalink
feat: add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bramstroker committed Jan 1, 2025
1 parent eb57f6d commit 3b5f4ce
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions custom_components/powercalc/power_profile/power_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
72 changes: 72 additions & 0 deletions tests/power_profile/test_power_profile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

import pytest
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant, State
Expand Down Expand Up @@ -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

0 comments on commit 3b5f4ce

Please sign in to comment.