Migrate Vilfo to has entity name (#99018)
This commit is contained in:
parent
202b0b5300
commit
cdf39ec365
1 changed files with 9 additions and 18 deletions
|
@ -9,6 +9,7 @@ from homeassistant.components.sensor import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import PERCENTAGE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import (
|
||||
|
@ -70,18 +71,19 @@ class VilfoRouterSensor(SensorEntity):
|
|||
"""Define a Vilfo Router Sensor."""
|
||||
|
||||
entity_description: VilfoSensorEntityDescription
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, api, description: VilfoSensorEntityDescription) -> None:
|
||||
"""Initialize."""
|
||||
self.entity_description = description
|
||||
self.api = api
|
||||
self._device_info = {
|
||||
"identifiers": {(DOMAIN, api.host, api.mac_address)},
|
||||
"name": ROUTER_DEFAULT_NAME,
|
||||
"manufacturer": ROUTER_MANUFACTURER,
|
||||
"model": ROUTER_DEFAULT_MODEL,
|
||||
"sw_version": api.firmware_version,
|
||||
}
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, api.host, api.mac_address)}, # type: ignore[arg-type]
|
||||
name=ROUTER_DEFAULT_NAME,
|
||||
manufacturer=ROUTER_MANUFACTURER,
|
||||
model=ROUTER_DEFAULT_MODEL,
|
||||
sw_version=api.firmware_version,
|
||||
)
|
||||
self._attr_unique_id = f"{api.unique_id}_{description.key}"
|
||||
|
||||
@property
|
||||
|
@ -89,17 +91,6 @@ class VilfoRouterSensor(SensorEntity):
|
|||
"""Return whether the sensor is available or not."""
|
||||
return self.api.available
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return the device info."""
|
||||
return self._device_info
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
parent_device_name = self._device_info["name"]
|
||||
return f"{parent_device_name} {self.entity_description.name}"
|
||||
|
||||
async def async_update(self) -> None:
|
||||
"""Update the router data."""
|
||||
await self.api.async_update()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue