Remove conditions from enphase_envoy test_switch (#122693)

This commit is contained in:
Arie Catsman 2024-07-27 14:32:37 +02:00 committed by GitHub
parent 02a5df0aee
commit b0780e1db5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,7 +12,6 @@ from homeassistant.const import (
SERVICE_TOGGLE, SERVICE_TOGGLE,
SERVICE_TURN_OFF, SERVICE_TURN_OFF,
SERVICE_TURN_ON, SERVICE_TURN_ON,
STATE_CLOSED,
STATE_OFF, STATE_OFF,
STATE_ON, STATE_ON,
) )
@ -146,12 +145,24 @@ async def test_switch_grid_operation(
@pytest.mark.parametrize( @pytest.mark.parametrize(
("mock_envoy"), ["envoy_metered_batt_relay"], indirect=["mock_envoy"] ("mock_envoy", "entity_states"),
[
(
"envoy_metered_batt_relay",
{
"NC1": (STATE_OFF, 0, 1),
"NC2": (STATE_ON, 1, 0),
"NC3": (STATE_OFF, 0, 1),
},
)
],
indirect=["mock_envoy"],
) )
async def test_switch_relay_operation( async def test_switch_relay_operation(
hass: HomeAssistant, hass: HomeAssistant,
mock_envoy: AsyncMock, mock_envoy: AsyncMock,
config_entry: MockConfigEntry, config_entry: MockConfigEntry,
entity_states: dict[str, tuple[str, int, int]],
) -> None: ) -> None:
"""Test enphase_envoy switch relay entities operation.""" """Test enphase_envoy switch relay entities operation."""
with patch("homeassistant.components.enphase_envoy.PLATFORMS", [Platform.SWITCH]): with patch("homeassistant.components.enphase_envoy.PLATFORMS", [Platform.SWITCH]):
@ -162,13 +173,10 @@ async def test_switch_relay_operation(
for contact_id, dry_contact in mock_envoy.data.dry_contact_settings.items(): for contact_id, dry_contact in mock_envoy.data.dry_contact_settings.items():
name = dry_contact.load_name.lower().replace(" ", "_") name = dry_contact.load_name.lower().replace(" ", "_")
test_entity = f"{entity_base}{name}" test_entity = f"{entity_base}{name}"
target_value = mock_envoy.data.dry_contact_status[contact_id].status
assert (entity_state := hass.states.get(test_entity)) assert (entity_state := hass.states.get(test_entity))
assert ( assert entity_state.state == entity_states[contact_id][0]
entity_state.state == STATE_ON open_count = entity_states[contact_id][1]
if target_value == STATE_CLOSED close_count = entity_states[contact_id][2]
else STATE_OFF
)
await hass.services.async_call( await hass.services.async_call(
SWITCH_DOMAIN, SWITCH_DOMAIN,
@ -199,15 +207,7 @@ async def test_switch_relay_operation(
blocking=True, blocking=True,
) )
assert ( assert mock_envoy.open_dry_contact.await_count == open_count
mock_envoy.open_dry_contact.await_count assert mock_envoy.close_dry_contact.await_count == close_count
if target_value == STATE_CLOSED
else mock_envoy.close_dry_contact.await_count
) == 1
assert (
mock_envoy.close_dry_contact.await_count
if target_value == STATE_CLOSED
else mock_envoy.open_dry_contact.await_count
) == 0
mock_envoy.open_dry_contact.reset_mock() mock_envoy.open_dry_contact.reset_mock()
mock_envoy.close_dry_contact.reset_mock() mock_envoy.close_dry_contact.reset_mock()