Use entity category and state class in devolo Home Network (#59071)
* Use entity category and state class * Add testspull/59512/head
parent
10d6247fee
commit
620db191b1
|
@ -7,8 +7,13 @@ from typing import Any
|
|||
|
||||
from devolo_plc_api.device import Device
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
||||
from homeassistant.components.sensor import (
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
@ -39,6 +44,7 @@ class DevoloSensorEntityDescription(
|
|||
SENSOR_TYPES: dict[str, DevoloSensorEntityDescription] = {
|
||||
CONNECTED_PLC_DEVICES: DevoloSensorEntityDescription(
|
||||
key=CONNECTED_PLC_DEVICES,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
icon="mdi:lan",
|
||||
name="Connected PLC devices",
|
||||
|
@ -51,10 +57,12 @@ SENSOR_TYPES: dict[str, DevoloSensorEntityDescription] = {
|
|||
entity_registry_enabled_default=True,
|
||||
icon="mdi:wifi",
|
||||
name="Connected Wifi clients",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
value_func=lambda data: len(data["connected_stations"]),
|
||||
),
|
||||
NEIGHBORING_WIFI_NETWORKS: DevoloSensorEntityDescription(
|
||||
key=NEIGHBORING_WIFI_NETWORKS,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
icon="mdi:wifi-marker",
|
||||
name="Neighboring Wifi networks",
|
||||
|
|
|
@ -8,9 +8,10 @@ from homeassistant.components.devolo_home_network.const import (
|
|||
LONG_UPDATE_INTERVAL,
|
||||
SHORT_UPDATE_INTERVAL,
|
||||
)
|
||||
from homeassistant.components.sensor import DOMAIN
|
||||
from homeassistant.const import STATE_UNAVAILABLE
|
||||
from homeassistant.components.sensor import DOMAIN, STATE_CLASS_MEASUREMENT
|
||||
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC, STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry
|
||||
from homeassistant.util import dt
|
||||
|
||||
from . import configure_integration
|
||||
|
@ -46,6 +47,7 @@ async def test_update_connected_wifi_clients(hass: HomeAssistant):
|
|||
state = hass.states.get(state_key)
|
||||
assert state is not None
|
||||
assert state.state == "1"
|
||||
assert state.attributes["state_class"] == STATE_CLASS_MEASUREMENT
|
||||
|
||||
# Emulate device failure
|
||||
with patch(
|
||||
|
@ -86,6 +88,9 @@ async def test_update_neighboring_wifi_networks(hass: HomeAssistant):
|
|||
assert state is not None
|
||||
assert state.state == "1"
|
||||
|
||||
er = entity_registry.async_get(hass)
|
||||
assert er.async_get(state_key).entity_category == ENTITY_CATEGORY_DIAGNOSTIC
|
||||
|
||||
# Emulate device failure
|
||||
with patch(
|
||||
"devolo_plc_api.device_api.deviceapi.DeviceApi.async_get_wifi_neighbor_access_points",
|
||||
|
@ -125,6 +130,9 @@ async def test_update_connected_plc_devices(hass: HomeAssistant):
|
|||
assert state is not None
|
||||
assert state.state == "1"
|
||||
|
||||
er = entity_registry.async_get(hass)
|
||||
assert er.async_get(state_key).entity_category == ENTITY_CATEGORY_DIAGNOSTIC
|
||||
|
||||
# Emulate device failure
|
||||
with patch(
|
||||
"devolo_plc_api.plcnet_api.plcnetapi.PlcNetApi.async_get_network_overview",
|
||||
|
|
Loading…
Reference in New Issue