Change Reolink test switch entity ID (#134339)

This commit is contained in:
starkillerOG 2024-12-31 22:57:43 +01:00 committed by GitHub
parent c8276ec325
commit 1d6ecbd1d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -248,16 +248,17 @@ async def test_switch(
) -> None: ) -> None:
"""Test switch entity.""" """Test switch entity."""
reolink_connect.camera_name.return_value = TEST_CAM_NAME reolink_connect.camera_name.return_value = TEST_CAM_NAME
reolink_connect.audio_record.return_value = True
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.SWITCH]): with patch("homeassistant.components.reolink.PLATFORMS", [Platform.SWITCH]):
assert await hass.config_entries.async_setup(config_entry.entry_id) assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.LOADED assert config_entry.state is ConfigEntryState.LOADED
entity_id = f"{Platform.SWITCH}.{TEST_CAM_NAME}_record" entity_id = f"{Platform.SWITCH}.{TEST_CAM_NAME}_record_audio"
assert hass.states.get(entity_id).state == STATE_ON assert hass.states.get(entity_id).state == STATE_ON
reolink_connect.recording_enabled.return_value = False reolink_connect.audio_record.return_value = False
freezer.tick(DEVICE_UPDATE_INTERVAL) freezer.tick(DEVICE_UPDATE_INTERVAL)
async_fire_time_changed(hass) async_fire_time_changed(hass)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -271,9 +272,9 @@ async def test_switch(
{ATTR_ENTITY_ID: entity_id}, {ATTR_ENTITY_ID: entity_id},
blocking=True, blocking=True,
) )
reolink_connect.set_recording.assert_called_with(0, True) reolink_connect.set_audio.assert_called_with(0, True)
reolink_connect.set_recording.side_effect = ReolinkError("Test error") reolink_connect.set_audio.side_effect = ReolinkError("Test error")
with pytest.raises(HomeAssistantError): with pytest.raises(HomeAssistantError):
await hass.services.async_call( await hass.services.async_call(
SWITCH_DOMAIN, SWITCH_DOMAIN,
@ -283,16 +284,16 @@ async def test_switch(
) )
# test switch turn off # test switch turn off
reolink_connect.set_recording.reset_mock(side_effect=True) reolink_connect.set_audio.reset_mock(side_effect=True)
await hass.services.async_call( await hass.services.async_call(
SWITCH_DOMAIN, SWITCH_DOMAIN,
SERVICE_TURN_OFF, SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: entity_id}, {ATTR_ENTITY_ID: entity_id},
blocking=True, blocking=True,
) )
reolink_connect.set_recording.assert_called_with(0, False) reolink_connect.set_audio.assert_called_with(0, False)
reolink_connect.set_recording.side_effect = ReolinkError("Test error") reolink_connect.set_audio.side_effect = ReolinkError("Test error")
with pytest.raises(HomeAssistantError): with pytest.raises(HomeAssistantError):
await hass.services.async_call( await hass.services.async_call(
SWITCH_DOMAIN, SWITCH_DOMAIN,
@ -301,7 +302,7 @@ async def test_switch(
blocking=True, blocking=True,
) )
reolink_connect.set_recording.reset_mock(side_effect=True) reolink_connect.set_audio.reset_mock(side_effect=True)
reolink_connect.camera_online.return_value = False reolink_connect.camera_online.return_value = False
freezer.tick(DEVICE_UPDATE_INTERVAL) freezer.tick(DEVICE_UPDATE_INTERVAL)
@ -321,17 +322,17 @@ async def test_host_switch(
) -> None: ) -> None:
"""Test host switch entity.""" """Test host switch entity."""
reolink_connect.camera_name.return_value = TEST_CAM_NAME reolink_connect.camera_name.return_value = TEST_CAM_NAME
reolink_connect.recording_enabled.return_value = True reolink_connect.email_enabled.return_value = True
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.SWITCH]): with patch("homeassistant.components.reolink.PLATFORMS", [Platform.SWITCH]):
assert await hass.config_entries.async_setup(config_entry.entry_id) assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
assert config_entry.state is ConfigEntryState.LOADED assert config_entry.state is ConfigEntryState.LOADED
entity_id = f"{Platform.SWITCH}.{TEST_NVR_NAME}_record" entity_id = f"{Platform.SWITCH}.{TEST_NVR_NAME}_email_on_event"
assert hass.states.get(entity_id).state == STATE_ON assert hass.states.get(entity_id).state == STATE_ON
reolink_connect.recording_enabled.return_value = False reolink_connect.email_enabled.return_value = False
freezer.tick(DEVICE_UPDATE_INTERVAL) freezer.tick(DEVICE_UPDATE_INTERVAL)
async_fire_time_changed(hass) async_fire_time_changed(hass)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -345,9 +346,9 @@ async def test_host_switch(
{ATTR_ENTITY_ID: entity_id}, {ATTR_ENTITY_ID: entity_id},
blocking=True, blocking=True,
) )
reolink_connect.set_recording.assert_called_with(None, True) reolink_connect.set_email.assert_called_with(None, True)
reolink_connect.set_recording.side_effect = ReolinkError("Test error") reolink_connect.set_email.side_effect = ReolinkError("Test error")
with pytest.raises(HomeAssistantError): with pytest.raises(HomeAssistantError):
await hass.services.async_call( await hass.services.async_call(
SWITCH_DOMAIN, SWITCH_DOMAIN,
@ -357,16 +358,16 @@ async def test_host_switch(
) )
# test switch turn off # test switch turn off
reolink_connect.set_recording.reset_mock(side_effect=True) reolink_connect.set_email.reset_mock(side_effect=True)
await hass.services.async_call( await hass.services.async_call(
SWITCH_DOMAIN, SWITCH_DOMAIN,
SERVICE_TURN_OFF, SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: entity_id}, {ATTR_ENTITY_ID: entity_id},
blocking=True, blocking=True,
) )
reolink_connect.set_recording.assert_called_with(None, False) reolink_connect.set_email.assert_called_with(None, False)
reolink_connect.set_recording.side_effect = ReolinkError("Test error") reolink_connect.set_email.side_effect = ReolinkError("Test error")
with pytest.raises(HomeAssistantError): with pytest.raises(HomeAssistantError):
await hass.services.async_call( await hass.services.async_call(
SWITCH_DOMAIN, SWITCH_DOMAIN,
@ -375,7 +376,7 @@ async def test_host_switch(
blocking=True, blocking=True,
) )
reolink_connect.set_recording.reset_mock(side_effect=True) reolink_connect.set_email.reset_mock(side_effect=True)
async def test_chime_switch( async def test_chime_switch(