mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
Parameterize enphase_envoy number tests. (#136631)
This commit is contained in:
parent
52dc124cfe
commit
ae157e8592
@ -21,9 +21,9 @@ from tests.common import MockConfigEntry, snapshot_platform
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("mock_envoy"),
|
"mock_envoy",
|
||||||
["envoy_metered_batt_relay", "envoy_eu_batt"],
|
["envoy_metered_batt_relay", "envoy_eu_batt"],
|
||||||
indirect=["mock_envoy"],
|
indirect=True,
|
||||||
)
|
)
|
||||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||||
async def test_number(
|
async def test_number(
|
||||||
@ -40,14 +40,14 @@ async def test_number(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("mock_envoy"),
|
"mock_envoy",
|
||||||
[
|
[
|
||||||
"envoy",
|
"envoy",
|
||||||
"envoy_1p_metered",
|
"envoy_1p_metered",
|
||||||
"envoy_nobatt_metered_3p",
|
"envoy_nobatt_metered_3p",
|
||||||
"envoy_tot_cons_metered",
|
"envoy_tot_cons_metered",
|
||||||
],
|
],
|
||||||
indirect=["mock_envoy"],
|
indirect=True,
|
||||||
)
|
)
|
||||||
async def test_no_number(
|
async def test_no_number(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -62,10 +62,10 @@ async def test_no_number(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("mock_envoy", "use_serial"),
|
("mock_envoy", "use_serial", "expected_value", "test_value"),
|
||||||
[
|
[
|
||||||
("envoy_metered_batt_relay", "enpower_654321"),
|
("envoy_metered_batt_relay", "enpower_654321", 15.0, 30.0),
|
||||||
("envoy_eu_batt", "envoy_1234"),
|
("envoy_eu_batt", "envoy_1234", 0.0, 80.0),
|
||||||
],
|
],
|
||||||
indirect=["mock_envoy"],
|
indirect=["mock_envoy"],
|
||||||
)
|
)
|
||||||
@ -74,6 +74,8 @@ async def test_number_operation_storage(
|
|||||||
mock_envoy: AsyncMock,
|
mock_envoy: AsyncMock,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
use_serial: bool,
|
use_serial: bool,
|
||||||
|
expected_value: float,
|
||||||
|
test_value: float,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test enphase_envoy number storage entities operation."""
|
"""Test enphase_envoy number storage entities operation."""
|
||||||
with patch("homeassistant.components.enphase_envoy.PLATFORMS", [Platform.NUMBER]):
|
with patch("homeassistant.components.enphase_envoy.PLATFORMS", [Platform.NUMBER]):
|
||||||
@ -82,10 +84,8 @@ async def test_number_operation_storage(
|
|||||||
test_entity = f"{Platform.NUMBER}.{use_serial}_reserve_battery_level"
|
test_entity = f"{Platform.NUMBER}.{use_serial}_reserve_battery_level"
|
||||||
|
|
||||||
assert (entity_state := hass.states.get(test_entity))
|
assert (entity_state := hass.states.get(test_entity))
|
||||||
assert mock_envoy.data.tariff.storage_settings.reserved_soc == float(
|
assert float(entity_state.state) == expected_value
|
||||||
entity_state.state
|
|
||||||
)
|
|
||||||
test_value = 30.0
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
NUMBER_DOMAIN,
|
NUMBER_DOMAIN,
|
||||||
SERVICE_SET_VALUE,
|
SERVICE_SET_VALUE,
|
||||||
@ -99,13 +99,27 @@ async def test_number_operation_storage(
|
|||||||
mock_envoy.set_reserve_soc.assert_awaited_once_with(test_value)
|
mock_envoy.set_reserve_soc.assert_awaited_once_with(test_value)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("mock_envoy", ["envoy_metered_batt_relay"], indirect=True)
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("mock_envoy"), ["envoy_metered_batt_relay"], indirect=["mock_envoy"]
|
("relay", "target", "expected_value", "test_value", "test_field"),
|
||||||
|
[
|
||||||
|
("NC1", "cutoff_battery_level", 25.0, 15.0, "soc_low"),
|
||||||
|
("NC1", "restore_battery_level", 70.0, 75.0, "soc_high"),
|
||||||
|
("NC2", "cutoff_battery_level", 30.0, 25.0, "soc_low"),
|
||||||
|
("NC2", "restore_battery_level", 70.0, 80.0, "soc_high"),
|
||||||
|
("NC3", "cutoff_battery_level", 30.0, 45.0, "soc_low"),
|
||||||
|
("NC3", "restore_battery_level", 70.0, 90.0, "soc_high"),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
async def test_number_operation_relays(
|
async def test_number_operation_relays(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_envoy: AsyncMock,
|
mock_envoy: AsyncMock,
|
||||||
config_entry: MockConfigEntry,
|
config_entry: MockConfigEntry,
|
||||||
|
relay: str,
|
||||||
|
target: str,
|
||||||
|
expected_value: float,
|
||||||
|
test_value: float,
|
||||||
|
test_field: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test enphase_envoy number relay entities operation."""
|
"""Test enphase_envoy number relay entities operation."""
|
||||||
with patch("homeassistant.components.enphase_envoy.PLATFORMS", [Platform.NUMBER]):
|
with patch("homeassistant.components.enphase_envoy.PLATFORMS", [Platform.NUMBER]):
|
||||||
@ -113,48 +127,24 @@ async def test_number_operation_relays(
|
|||||||
|
|
||||||
entity_base = f"{Platform.NUMBER}."
|
entity_base = f"{Platform.NUMBER}."
|
||||||
|
|
||||||
for counter, (contact_id, dry_contact) in enumerate(
|
assert (dry_contact := mock_envoy.data.dry_contact_settings[relay])
|
||||||
mock_envoy.data.dry_contact_settings.items()
|
assert (name := dry_contact.load_name.lower().replace(" ", "_"))
|
||||||
):
|
|
||||||
name = dry_contact.load_name.lower().replace(" ", "_")
|
|
||||||
test_entity = f"{entity_base}{name}_cutoff_battery_level"
|
|
||||||
assert (entity_state := hass.states.get(test_entity))
|
|
||||||
assert mock_envoy.data.dry_contact_settings[contact_id].soc_low == float(
|
|
||||||
entity_state.state
|
|
||||||
)
|
|
||||||
test_value = 10.0 + counter
|
|
||||||
await hass.services.async_call(
|
|
||||||
NUMBER_DOMAIN,
|
|
||||||
SERVICE_SET_VALUE,
|
|
||||||
{
|
|
||||||
ATTR_ENTITY_ID: test_entity,
|
|
||||||
ATTR_VALUE: test_value,
|
|
||||||
},
|
|
||||||
blocking=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
mock_envoy.update_dry_contact.assert_awaited_once_with(
|
test_entity = f"{entity_base}{name}_{target}"
|
||||||
{"id": contact_id, "soc_low": test_value}
|
|
||||||
)
|
|
||||||
mock_envoy.update_dry_contact.reset_mock()
|
|
||||||
|
|
||||||
test_entity = f"{entity_base}{name}_restore_battery_level"
|
assert (entity_state := hass.states.get(test_entity))
|
||||||
assert (entity_state := hass.states.get(test_entity))
|
assert float(entity_state.state) == expected_value
|
||||||
assert mock_envoy.data.dry_contact_settings[contact_id].soc_high == float(
|
|
||||||
entity_state.state
|
|
||||||
)
|
|
||||||
test_value = 80.0 - counter
|
|
||||||
await hass.services.async_call(
|
|
||||||
NUMBER_DOMAIN,
|
|
||||||
SERVICE_SET_VALUE,
|
|
||||||
{
|
|
||||||
ATTR_ENTITY_ID: test_entity,
|
|
||||||
ATTR_VALUE: test_value,
|
|
||||||
},
|
|
||||||
blocking=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
mock_envoy.update_dry_contact.assert_awaited_once_with(
|
await hass.services.async_call(
|
||||||
{"id": contact_id, "soc_high": test_value}
|
NUMBER_DOMAIN,
|
||||||
)
|
SERVICE_SET_VALUE,
|
||||||
mock_envoy.update_dry_contact.reset_mock()
|
{
|
||||||
|
ATTR_ENTITY_ID: test_entity,
|
||||||
|
ATTR_VALUE: test_value,
|
||||||
|
},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
mock_envoy.update_dry_contact.assert_awaited_once_with(
|
||||||
|
{"id": relay, test_field: int(test_value)}
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user