Migrate devolo Home Network to new entity naming (#74741)

This commit is contained in:
Guido Schmitz 2022-07-09 19:05:49 +02:00 committed by GitHub
parent 124c8e8f73
commit 72d134be52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 11 deletions

View file

@ -15,6 +15,8 @@ from .const import DOMAIN
class DevoloEntity(CoordinatorEntity):
"""Representation of a devolo home network device."""
_attr_has_entity_name = True
def __init__(
self, coordinator: DataUpdateCoordinator, device: Device, device_name: str
) -> None:

View file

@ -9,7 +9,12 @@ from homeassistant.components.devolo_home_network.const import (
CONNECTED_TO_ROUTER,
LONG_UPDATE_INTERVAL,
)
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE
from homeassistant.const import (
ATTR_FRIENDLY_NAME,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry
from homeassistant.helpers.entity import EntityCategory
@ -25,10 +30,11 @@ from tests.common import async_fire_time_changed
async def test_binary_sensor_setup(hass: HomeAssistant):
"""Test default setup of the binary sensor component."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert hass.states.get(f"{DOMAIN}.{CONNECTED_TO_ROUTER}") is None
assert hass.states.get(f"{DOMAIN}.{device_name}_{CONNECTED_TO_ROUTER}") is None
await hass.config_entries.async_unload(entry.entry_id)
@ -36,8 +42,9 @@ async def test_binary_sensor_setup(hass: HomeAssistant):
@pytest.mark.usefixtures("entity_registry_enabled_by_default", "mock_device")
async def test_update_attached_to_router(hass: HomeAssistant):
"""Test state change of a attached_to_router binary sensor device."""
state_key = f"{DOMAIN}.{CONNECTED_TO_ROUTER}"
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{DOMAIN}.{device_name}_{CONNECTED_TO_ROUTER}"
er = entity_registry.async_get(hass)
@ -47,6 +54,7 @@ async def test_update_attached_to_router(hass: HomeAssistant):
state = hass.states.get(state_key)
assert state is not None
assert state.state == STATE_OFF
assert state.attributes[ATTR_FRIENDLY_NAME] == f"{entry.title} Connected to router"
assert er.async_get(state_key).entity_category == EntityCategory.DIAGNOSTIC

View file

@ -9,7 +9,7 @@ from homeassistant.components.devolo_home_network.const import (
SHORT_UPDATE_INTERVAL,
)
from homeassistant.components.sensor import DOMAIN, SensorStateClass
from homeassistant.const import STATE_UNAVAILABLE
from homeassistant.const import ATTR_FRIENDLY_NAME, STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry
from homeassistant.helpers.entity import EntityCategory
@ -24,12 +24,13 @@ from tests.common import async_fire_time_changed
async def test_sensor_setup(hass: HomeAssistant):
"""Test default setup of the sensor component."""
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert hass.states.get(f"{DOMAIN}.connected_wifi_clients") is not None
assert hass.states.get(f"{DOMAIN}.connected_plc_devices") is None
assert hass.states.get(f"{DOMAIN}.neighboring_wifi_networks") is None
assert hass.states.get(f"{DOMAIN}.{device_name}_connected_wifi_clients") is not None
assert hass.states.get(f"{DOMAIN}.{device_name}_connected_plc_devices") is None
assert hass.states.get(f"{DOMAIN}.{device_name}_neighboring_wifi_networks") is None
await hass.config_entries.async_unload(entry.entry_id)
@ -37,15 +38,18 @@ async def test_sensor_setup(hass: HomeAssistant):
@pytest.mark.usefixtures("mock_device")
async def test_update_connected_wifi_clients(hass: HomeAssistant):
"""Test state change of a connected_wifi_clients sensor device."""
state_key = f"{DOMAIN}.connected_wifi_clients"
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{DOMAIN}.{device_name}_connected_wifi_clients"
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get(state_key)
assert state is not None
assert state.state == "1"
assert (
state.attributes[ATTR_FRIENDLY_NAME] == f"{entry.title} Connected Wifi clients"
)
assert state.attributes["state_class"] == SensorStateClass.MEASUREMENT
# Emulate device failure
@ -74,8 +78,9 @@ async def test_update_connected_wifi_clients(hass: HomeAssistant):
@pytest.mark.usefixtures("entity_registry_enabled_by_default", "mock_device")
async def test_update_neighboring_wifi_networks(hass: HomeAssistant):
"""Test state change of a neighboring_wifi_networks sensor device."""
state_key = f"{DOMAIN}.neighboring_wifi_networks"
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{DOMAIN}.{device_name}_neighboring_wifi_networks"
er = entity_registry.async_get(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
@ -83,6 +88,10 @@ async def test_update_neighboring_wifi_networks(hass: HomeAssistant):
state = hass.states.get(state_key)
assert state is not None
assert state.state == "1"
assert (
state.attributes[ATTR_FRIENDLY_NAME]
== f"{entry.title} Neighboring Wifi networks"
)
assert er.async_get(state_key).entity_category is EntityCategory.DIAGNOSTIC
# Emulate device failure
@ -111,8 +120,9 @@ async def test_update_neighboring_wifi_networks(hass: HomeAssistant):
@pytest.mark.usefixtures("entity_registry_enabled_by_default", "mock_device")
async def test_update_connected_plc_devices(hass: HomeAssistant):
"""Test state change of a connected_plc_devices sensor device."""
state_key = f"{DOMAIN}.connected_plc_devices"
entry = configure_integration(hass)
device_name = entry.title.replace(" ", "_").lower()
state_key = f"{DOMAIN}.{device_name}_connected_plc_devices"
er = entity_registry.async_get(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
@ -120,6 +130,9 @@ async def test_update_connected_plc_devices(hass: HomeAssistant):
state = hass.states.get(state_key)
assert state is not None
assert state.state == "1"
assert (
state.attributes[ATTR_FRIENDLY_NAME] == f"{entry.title} Connected PLC devices"
)
assert er.async_get(state_key).entity_category is EntityCategory.DIAGNOSTIC
# Emulate device failure