Rename devolo test variables and aliases (#163175)

This commit is contained in:
epenet
2026-02-16 16:53:22 +01:00
committed by GitHub
parent aab4f57580
commit cbc2928c4a
8 changed files with 153 additions and 121 deletions

View File

@@ -7,7 +7,7 @@ from freezegun.api import FrozenDateTimeFactory
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.binary_sensor import DOMAIN as PLATFORM
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
from homeassistant.components.devolo_home_network.const import LONG_UPDATE_INTERVAL
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import STATE_ON, STATE_UNAVAILABLE
@@ -34,7 +34,7 @@ async def test_binary_sensor_setup(
assert entry.state is ConfigEntryState.LOADED
assert entity_registry.async_get(
f"{PLATFORM}.{device_name}_connected_to_router"
f"{BINARY_SENSOR_DOMAIN}.{device_name}_connected_to_router"
).disabled
@@ -49,13 +49,13 @@ async def test_update_attached_to_router(
"""Test state change of a attached_to_router binary sensor device."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_connected_to_router"
entity_id = f"{BINARY_SENSOR_DOMAIN}.{device_name}_connected_to_router"
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert hass.states.get(state_key) == snapshot
assert entity_registry.async_get(state_key) == snapshot
assert hass.states.get(entity_id) == snapshot
assert entity_registry.async_get(entity_id) == snapshot
# Emulate device failure
mock_device.plcnet.async_get_network_overview = AsyncMock(
@@ -65,7 +65,7 @@ async def test_update_attached_to_router(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_UNAVAILABLE
@@ -77,6 +77,6 @@ async def test_update_attached_to_router(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_ON

View File

@@ -6,7 +6,7 @@ from devolo_plc_api.exceptions.device import DevicePasswordProtected, DeviceUnav
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.button import DOMAIN as PLATFORM, SERVICE_PRESS
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
from homeassistant.components.devolo_home_network.const import DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
from homeassistant.const import ATTR_ENTITY_ID
@@ -31,15 +31,17 @@ async def test_button_setup(
assert entry.state is ConfigEntryState.LOADED
assert not entity_registry.async_get(
f"{PLATFORM}.{device_name}_identify_device_with_a_blinking_led"
f"{BUTTON_DOMAIN}.{device_name}_identify_device_with_a_blinking_led"
).disabled
assert not entity_registry.async_get(
f"{PLATFORM}.{device_name}_start_plc_pairing"
f"{BUTTON_DOMAIN}.{device_name}_start_plc_pairing"
).disabled
assert not entity_registry.async_get(
f"{PLATFORM}.{device_name}_restart_device"
f"{BUTTON_DOMAIN}.{device_name}_restart_device"
).disabled
assert not entity_registry.async_get(
f"{BUTTON_DOMAIN}.{device_name}_start_wps"
).disabled
assert not entity_registry.async_get(f"{PLATFORM}.{device_name}_start_wps").disabled
@pytest.mark.parametrize(
@@ -80,23 +82,23 @@ async def test_button(
"""Test a button."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_{name}"
entity_id = f"{BUTTON_DOMAIN}.{device_name}_{name}"
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert hass.states.get(state_key) == snapshot
assert entity_registry.async_get(state_key) == snapshot
assert hass.states.get(entity_id) == snapshot
assert entity_registry.async_get(entity_id) == snapshot
# Emulate button press
await hass.services.async_call(
PLATFORM,
BUTTON_DOMAIN,
SERVICE_PRESS,
{ATTR_ENTITY_ID: state_key},
{ATTR_ENTITY_ID: entity_id},
blocking=True,
)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state.state == "2023-01-13T12:00:00+00:00"
api = getattr(mock_device, api_name)
assert getattr(api, trigger_method).call_count == 1
@@ -106,9 +108,9 @@ async def test_button(
getattr(api, trigger_method).side_effect = DeviceUnavailable
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
PLATFORM,
BUTTON_DOMAIN,
SERVICE_PRESS,
{ATTR_ENTITY_ID: state_key},
{ATTR_ENTITY_ID: entity_id},
blocking=True,
)
@@ -117,7 +119,7 @@ async def test_auth_failed(hass: HomeAssistant, mock_device: MockDevice) -> None
"""Test setting unautherized triggers the reauth flow."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_start_wps"
entity_id = f"{BUTTON_DOMAIN}.{device_name}_start_wps"
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
@@ -126,9 +128,9 @@ async def test_auth_failed(hass: HomeAssistant, mock_device: MockDevice) -> None
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
PLATFORM,
BUTTON_DOMAIN,
SERVICE_PRESS,
{ATTR_ENTITY_ID: state_key},
{ATTR_ENTITY_ID: entity_id},
blocking=True,
)

View File

@@ -7,7 +7,7 @@ from freezegun.api import FrozenDateTimeFactory
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.device_tracker import DOMAIN as PLATFORM
from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER_DOMAIN
from homeassistant.components.devolo_home_network.const import (
DOMAIN,
LONG_UPDATE_INTERVAL,
@@ -34,14 +34,16 @@ async def test_device_tracker(
snapshot: SnapshotAssertion,
) -> None:
"""Test device tracker states."""
state_key = f"{PLATFORM}.{STATION.mac_address.lower().replace(':', '_')}"
entity_id = (
f"{DEVICE_TRACKER_DOMAIN}.{STATION.mac_address.lower().replace(':', '_')}"
)
entry = configure_integration(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
freezer.tick(LONG_UPDATE_INTERVAL)
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert hass.states.get(state_key) == snapshot
assert hass.states.get(entity_id) == snapshot
# Emulate state change
mock_device.device.async_get_wifi_connected_station = AsyncMock(
@@ -51,7 +53,7 @@ async def test_device_tracker(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_NOT_HOME
@@ -63,7 +65,7 @@ async def test_device_tracker(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_UNAVAILABLE
@@ -74,10 +76,12 @@ async def test_restoring_clients(
entity_registry: er.EntityRegistry,
) -> None:
"""Test restoring existing device_tracker entities."""
state_key = f"{PLATFORM}.{STATION.mac_address.lower().replace(':', '_')}"
entity_id = (
f"{DEVICE_TRACKER_DOMAIN}.{STATION.mac_address.lower().replace(':', '_')}"
)
entry = configure_integration(hass)
entity_registry.async_get_or_create(
PLATFORM,
DEVICE_TRACKER_DOMAIN,
DOMAIN,
f"{STATION.mac_address}",
config_entry=entry,
@@ -90,6 +94,6 @@ async def test_restoring_clients(
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_NOT_HOME

View File

@@ -9,7 +9,7 @@ import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.devolo_home_network.const import SHORT_UPDATE_INTERVAL
from homeassistant.components.image import DOMAIN as PLATFORM
from homeassistant.components.image import DOMAIN as IMAGE_DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
@@ -37,7 +37,7 @@ async def test_image_setup(
assert entry.state is ConfigEntryState.LOADED
assert not entity_registry.async_get(
f"{PLATFORM}.{device_name}_guest_wi_fi_credentials_as_qr_code"
f"{IMAGE_DOMAIN}.{device_name}_guest_wi_fi_credentials_as_qr_code"
).disabled
@@ -53,18 +53,18 @@ async def test_guest_wifi_qr(
"""Test showing a QR code of the guest wifi credentials."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_guest_wi_fi_credentials_as_qr_code"
entity_id = f"{IMAGE_DOMAIN}.{device_name}_guest_wi_fi_credentials_as_qr_code"
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state.name == "Mock Title Guest Wi-Fi credentials as QR code"
assert state.state == dt_util.utcnow().isoformat()
assert entity_registry.async_get(state_key) == snapshot
assert entity_registry.async_get(entity_id) == snapshot
client = await hass_client()
resp = await client.get(f"/api/image_proxy/{state_key}")
resp = await client.get(f"/api/image_proxy/{entity_id}")
assert resp.status == HTTPStatus.OK
body = await resp.read()
assert body == snapshot
@@ -75,7 +75,7 @@ async def test_guest_wifi_qr(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_UNAVAILABLE
@@ -87,11 +87,11 @@ async def test_guest_wifi_qr(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == dt_util.utcnow().isoformat()
client = await hass_client()
resp = await client.get(f"/api/image_proxy/{state_key}")
resp = await client.get(f"/api/image_proxy/{entity_id}")
assert resp.status == HTTPStatus.OK
assert await resp.read() != body

View File

@@ -6,14 +6,14 @@ from devolo_plc_api.exceptions.device import DeviceNotFound
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR
from homeassistant.components.button import DOMAIN as BUTTON
from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN
from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER_DOMAIN
from homeassistant.components.devolo_home_network.const import DOMAIN
from homeassistant.components.image import DOMAIN as IMAGE
from homeassistant.components.sensor import DOMAIN as SENSOR
from homeassistant.components.switch import DOMAIN as SWITCH
from homeassistant.components.update import DOMAIN as UPDATE
from homeassistant.components.image import DOMAIN as IMAGE_DOMAIN
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.components.update import DOMAIN as UPDATE_DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
from homeassistant.core import HomeAssistant
@@ -90,13 +90,37 @@ async def test_device(
[
(
"mock_device",
(BINARY_SENSOR, BUTTON, DEVICE_TRACKER, IMAGE, SENSOR, SWITCH, UPDATE),
(
BINARY_SENSOR_DOMAIN,
BUTTON_DOMAIN,
DEVICE_TRACKER_DOMAIN,
IMAGE_DOMAIN,
SENSOR_DOMAIN,
SWITCH_DOMAIN,
UPDATE_DOMAIN,
),
),
(
"mock_repeater_device",
(BUTTON, DEVICE_TRACKER, IMAGE, SENSOR, SWITCH, UPDATE),
(
BUTTON_DOMAIN,
DEVICE_TRACKER_DOMAIN,
IMAGE_DOMAIN,
SENSOR_DOMAIN,
SWITCH_DOMAIN,
UPDATE_DOMAIN,
),
),
(
"mock_nonwifi_device",
(
BINARY_SENSOR_DOMAIN,
BUTTON_DOMAIN,
SENSOR_DOMAIN,
SWITCH_DOMAIN,
UPDATE_DOMAIN,
),
),
("mock_nonwifi_device", (BINARY_SENSOR, BUTTON, SENSOR, SWITCH, UPDATE)),
],
)
async def test_platforms(

View File

@@ -13,7 +13,7 @@ from homeassistant.components.devolo_home_network.const import (
LONG_UPDATE_INTERVAL,
SHORT_UPDATE_INTERVAL,
)
from homeassistant.components.sensor import DOMAIN as PLATFORM
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
@@ -39,28 +39,28 @@ async def test_sensor_setup(
assert entry.state is ConfigEntryState.LOADED
assert not entity_registry.async_get(
f"{PLATFORM}.{device_name}_connected_wi_fi_clients"
f"{SENSOR_DOMAIN}.{device_name}_connected_wi_fi_clients"
).disabled
assert entity_registry.async_get(
f"{PLATFORM}.{device_name}_connected_plc_devices"
f"{SENSOR_DOMAIN}.{device_name}_connected_plc_devices"
).disabled
assert entity_registry.async_get(
f"{PLATFORM}.{device_name}_neighboring_wi_fi_networks"
f"{SENSOR_DOMAIN}.{device_name}_neighboring_wi_fi_networks"
).disabled
assert not entity_registry.async_get(
f"{PLATFORM}.{device_name}_plc_downlink_phy_rate_{PLCNET.devices[1].user_device_name}"
f"{SENSOR_DOMAIN}.{device_name}_plc_downlink_phy_rate_{PLCNET.devices[1].user_device_name}"
).disabled
assert not entity_registry.async_get(
f"{PLATFORM}.{device_name}_plc_uplink_phy_rate_{PLCNET.devices[1].user_device_name}"
f"{SENSOR_DOMAIN}.{device_name}_plc_uplink_phy_rate_{PLCNET.devices[1].user_device_name}"
).disabled
assert entity_registry.async_get(
f"{PLATFORM}.{device_name}_plc_downlink_phy_rate_{PLCNET.devices[2].user_device_name}"
f"{SENSOR_DOMAIN}.{device_name}_plc_downlink_phy_rate_{PLCNET.devices[2].user_device_name}"
).disabled
assert entity_registry.async_get(
f"{PLATFORM}.{device_name}_plc_uplink_phy_rate_{PLCNET.devices[2].user_device_name}"
f"{SENSOR_DOMAIN}.{device_name}_plc_uplink_phy_rate_{PLCNET.devices[2].user_device_name}"
).disabled
assert entity_registry.async_get(
f"{PLATFORM}.{device_name}_last_restart_of_the_device"
f"{SENSOR_DOMAIN}.{device_name}_last_restart_of_the_device"
).disabled
@@ -109,12 +109,12 @@ async def test_sensor(
"""Test state change of a sensor device."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_{name}"
entity_id = f"{SENSOR_DOMAIN}.{device_name}_{name}"
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert hass.states.get(state_key) == snapshot
assert entity_registry.async_get(state_key) == snapshot
assert hass.states.get(entity_id) == snapshot
assert entity_registry.async_get(entity_id) == snapshot
# Emulate device failure
setattr(mock_device.device, get_method, AsyncMock(side_effect=DeviceUnavailable))
@@ -123,7 +123,7 @@ async def test_sensor(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_UNAVAILABLE
@@ -133,7 +133,7 @@ async def test_sensor(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == expected_state
@@ -148,15 +148,15 @@ async def test_update_plc_phyrates(
"""Test state change of plc_downlink_phyrate and plc_uplink_phyrate sensor devices."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key_downlink = f"{PLATFORM}.{device_name}_plc_downlink_phy_rate_{PLCNET.devices[1].user_device_name}"
state_key_uplink = f"{PLATFORM}.{device_name}_plc_uplink_phy_rate_{PLCNET.devices[1].user_device_name}"
entity_id_downlink = f"{SENSOR_DOMAIN}.{device_name}_plc_downlink_phy_rate_{PLCNET.devices[1].user_device_name}"
entity_id_uplink = f"{SENSOR_DOMAIN}.{device_name}_plc_uplink_phy_rate_{PLCNET.devices[1].user_device_name}"
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert hass.states.get(state_key_downlink) == snapshot
assert entity_registry.async_get(state_key_downlink) == snapshot
assert hass.states.get(state_key_downlink) == snapshot
assert entity_registry.async_get(state_key_downlink) == snapshot
assert hass.states.get(entity_id_downlink) == snapshot
assert entity_registry.async_get(entity_id_downlink) == snapshot
assert hass.states.get(entity_id_downlink) == snapshot
assert entity_registry.async_get(entity_id_downlink) == snapshot
# Emulate device failure
mock_device.plcnet.async_get_network_overview = AsyncMock(
@@ -166,11 +166,11 @@ async def test_update_plc_phyrates(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get(state_key_downlink)
state = hass.states.get(entity_id_downlink)
assert state is not None
assert state.state == STATE_UNAVAILABLE
state = hass.states.get(state_key_uplink)
state = hass.states.get(entity_id_uplink)
assert state is not None
assert state.state == STATE_UNAVAILABLE
@@ -180,11 +180,11 @@ async def test_update_plc_phyrates(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get(state_key_downlink)
state = hass.states.get(entity_id_downlink)
assert state is not None
assert state.state == str(PLCNET.data_rates[0].rx_rate)
state = hass.states.get(state_key_uplink)
state = hass.states.get(entity_id_uplink)
assert state is not None
assert state.state == str(PLCNET.data_rates[0].tx_rate)

View File

@@ -13,7 +13,7 @@ from homeassistant.components.devolo_home_network.const import (
DOMAIN,
SHORT_UPDATE_INTERVAL,
)
from homeassistant.components.switch import DOMAIN as PLATFORM
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
from homeassistant.const import (
ATTR_ENTITY_ID,
@@ -47,10 +47,10 @@ async def test_switch_setup(
assert entry.state is ConfigEntryState.LOADED
assert not entity_registry.async_get(
f"{PLATFORM}.{device_name}_enable_guest_wi_fi"
f"{SWITCH_DOMAIN}.{device_name}_enable_guest_wi_fi"
).disabled
assert not entity_registry.async_get(
f"{PLATFORM}.{device_name}_enable_leds"
f"{SWITCH_DOMAIN}.{device_name}_enable_leds"
).disabled
@@ -87,13 +87,13 @@ async def test_update_enable_guest_wifi(
"""Test state change of a enable_guest_wifi switch device."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_enable_guest_wi_fi"
entity_id = f"{SWITCH_DOMAIN}.{device_name}_enable_guest_wi_fi"
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert hass.states.get(state_key) == snapshot
assert entity_registry.async_get(state_key) == snapshot
assert hass.states.get(entity_id) == snapshot
assert entity_registry.async_get(entity_id) == snapshot
# Emulate state change
mock_device.device.async_get_wifi_guest_access.return_value = WifiGuestAccessGet(
@@ -103,7 +103,7 @@ async def test_update_enable_guest_wifi(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_ON
@@ -112,10 +112,10 @@ async def test_update_enable_guest_wifi(
enabled=False
)
await hass.services.async_call(
PLATFORM, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: state_key}, blocking=True
SWITCH_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id}, blocking=True
)
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_OFF
mock_device.device.async_set_wifi_guest_access.assert_called_once_with(False)
@@ -130,10 +130,10 @@ async def test_update_enable_guest_wifi(
enabled=True
)
await hass.services.async_call(
PLATFORM, SERVICE_TURN_ON, {ATTR_ENTITY_ID: state_key}, blocking=True
SWITCH_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: entity_id}, blocking=True
)
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_ON
mock_device.device.async_set_wifi_guest_access.assert_called_once_with(True)
@@ -151,9 +151,9 @@ async def test_update_enable_guest_wifi(
HomeAssistantError, match=f"Device {entry.title} did not respond"
):
await hass.services.async_call(
PLATFORM, SERVICE_TURN_ON, {ATTR_ENTITY_ID: state_key}, blocking=True
SWITCH_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: entity_id}, blocking=True
)
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_UNAVAILABLE
@@ -168,13 +168,13 @@ async def test_update_enable_leds(
"""Test state change of a enable_leds switch device."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_enable_leds"
entity_id = f"{SWITCH_DOMAIN}.{device_name}_enable_leds"
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert hass.states.get(state_key) == snapshot
assert entity_registry.async_get(state_key) == snapshot
assert hass.states.get(entity_id) == snapshot
assert entity_registry.async_get(entity_id) == snapshot
# Emulate state change
mock_device.device.async_get_led_setting.return_value = True
@@ -182,17 +182,17 @@ async def test_update_enable_leds(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_ON
# Switch off
mock_device.device.async_get_led_setting.return_value = False
await hass.services.async_call(
PLATFORM, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: state_key}, blocking=True
SWITCH_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id}, blocking=True
)
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_OFF
mock_device.device.async_set_led_setting.assert_called_once_with(False)
@@ -205,10 +205,10 @@ async def test_update_enable_leds(
# Switch on
mock_device.device.async_get_led_setting.return_value = True
await hass.services.async_call(
PLATFORM, SERVICE_TURN_ON, {ATTR_ENTITY_ID: state_key}, blocking=True
SWITCH_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: entity_id}, blocking=True
)
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_ON
mock_device.device.async_set_led_setting.assert_called_once_with(True)
@@ -226,9 +226,9 @@ async def test_update_enable_leds(
HomeAssistantError, match=f"Device {entry.title} did not respond"
):
await hass.services.async_call(
PLATFORM, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: state_key}, blocking=True
SWITCH_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id}, blocking=True
)
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_UNAVAILABLE
@@ -251,12 +251,12 @@ async def test_device_failure(
"""Test device failure."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_{name}"
entity_id = f"{SWITCH_DOMAIN}.{device_name}_{name}"
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
api = getattr(mock_device.device, get_method)
@@ -265,7 +265,7 @@ async def test_device_failure(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_UNAVAILABLE
@@ -283,12 +283,12 @@ async def test_auth_failed(
"""Test setting unautherized triggers the reauth flow."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_{name}"
entity_id = f"{SWITCH_DOMAIN}.{device_name}_{name}"
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
setattr(mock_device.device, set_method, AsyncMock())
@@ -297,7 +297,7 @@ async def test_auth_failed(
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
PLATFORM, SERVICE_TURN_ON, {ATTR_ENTITY_ID: state_key}, blocking=True
SWITCH_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: entity_id}, blocking=True
)
await hass.async_block_till_done()
@@ -314,7 +314,7 @@ async def test_auth_failed(
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
PLATFORM, SERVICE_TURN_OFF, {"entity_id": state_key}, blocking=True
SWITCH_DOMAIN, SERVICE_TURN_OFF, {"entity_id": entity_id}, blocking=True
)
flows = hass.config_entries.flow.async_progress()
assert len(flows) == 1

View File

@@ -10,7 +10,7 @@ from homeassistant.components.devolo_home_network.const import (
DOMAIN,
FIRMWARE_UPDATE_INTERVAL,
)
from homeassistant.components.update import DOMAIN as PLATFORM, SERVICE_INSTALL
from homeassistant.components.update import DOMAIN as UPDATE_DOMAIN, SERVICE_INSTALL
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
@@ -36,7 +36,9 @@ async def test_update_setup(
await hass.async_block_till_done()
assert entry.state is ConfigEntryState.LOADED
assert not entity_registry.async_get(f"{PLATFORM}.{device_name}_firmware").disabled
assert not entity_registry.async_get(
f"{UPDATE_DOMAIN}.{device_name}_firmware"
).disabled
async def test_update_firmware(
@@ -50,18 +52,18 @@ async def test_update_firmware(
"""Test updating a device."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_firmware"
entity_id = f"{UPDATE_DOMAIN}.{device_name}_firmware"
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert hass.states.get(state_key) == snapshot
assert entity_registry.async_get(state_key) == snapshot
assert hass.states.get(entity_id) == snapshot
assert entity_registry.async_get(entity_id) == snapshot
await hass.services.async_call(
PLATFORM,
UPDATE_DOMAIN,
SERVICE_INSTALL,
{ATTR_ENTITY_ID: state_key},
{ATTR_ENTITY_ID: entity_id},
blocking=True,
)
assert mock_device.device.async_start_firmware_update.call_count == 1
@@ -77,7 +79,7 @@ async def test_update_firmware(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_OFF
@@ -96,12 +98,12 @@ async def test_device_failure_check(
"""Test device failure during check."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_firmware"
entity_id = f"{UPDATE_DOMAIN}.{device_name}_firmware"
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
mock_device.device.async_check_firmware_available.side_effect = DeviceUnavailable
@@ -109,7 +111,7 @@ async def test_device_failure_check(
async_fire_time_changed(hass)
await hass.async_block_till_done()
state = hass.states.get(state_key)
state = hass.states.get(entity_id)
assert state is not None
assert state.state == STATE_UNAVAILABLE
@@ -121,7 +123,7 @@ async def test_device_failure_update(
"""Test device failure when starting update."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_firmware"
entity_id = f"{UPDATE_DOMAIN}.{device_name}_firmware"
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
@@ -131,9 +133,9 @@ async def test_device_failure_update(
# Emulate update start
with pytest.raises(HomeAssistantError):
await hass.services.async_call(
PLATFORM,
UPDATE_DOMAIN,
SERVICE_INSTALL,
{ATTR_ENTITY_ID: state_key},
{ATTR_ENTITY_ID: entity_id},
blocking=True,
)
@@ -142,7 +144,7 @@ async def test_auth_failed(hass: HomeAssistant, mock_device: MockDevice) -> None
"""Test updating unauthorized triggers the reauth flow."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{PLATFORM}.{device_name}_firmware"
entity_id = f"{UPDATE_DOMAIN}.{device_name}_firmware"
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
@@ -151,9 +153,9 @@ async def test_auth_failed(hass: HomeAssistant, mock_device: MockDevice) -> None
with pytest.raises(HomeAssistantError):
assert await hass.services.async_call(
PLATFORM,
UPDATE_DOMAIN,
SERVICE_INSTALL,
{ATTR_ENTITY_ID: state_key},
{ATTR_ENTITY_ID: entity_id},
blocking=True,
)
await hass.async_block_till_done()