mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Migrate Vilfo to has entity name (#99018)
This commit is contained in:
parent
202b0b5300
commit
cdf39ec365
@ -9,6 +9,7 @@ from homeassistant.components.sensor import (
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import PERCENTAGE
|
from homeassistant.const import PERCENTAGE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -70,18 +71,19 @@ class VilfoRouterSensor(SensorEntity):
|
|||||||
"""Define a Vilfo Router Sensor."""
|
"""Define a Vilfo Router Sensor."""
|
||||||
|
|
||||||
entity_description: VilfoSensorEntityDescription
|
entity_description: VilfoSensorEntityDescription
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(self, api, description: VilfoSensorEntityDescription) -> None:
|
def __init__(self, api, description: VilfoSensorEntityDescription) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self.api = api
|
self.api = api
|
||||||
self._device_info = {
|
self._attr_device_info = DeviceInfo(
|
||||||
"identifiers": {(DOMAIN, api.host, api.mac_address)},
|
identifiers={(DOMAIN, api.host, api.mac_address)}, # type: ignore[arg-type]
|
||||||
"name": ROUTER_DEFAULT_NAME,
|
name=ROUTER_DEFAULT_NAME,
|
||||||
"manufacturer": ROUTER_MANUFACTURER,
|
manufacturer=ROUTER_MANUFACTURER,
|
||||||
"model": ROUTER_DEFAULT_MODEL,
|
model=ROUTER_DEFAULT_MODEL,
|
||||||
"sw_version": api.firmware_version,
|
sw_version=api.firmware_version,
|
||||||
}
|
)
|
||||||
self._attr_unique_id = f"{api.unique_id}_{description.key}"
|
self._attr_unique_id = f"{api.unique_id}_{description.key}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -89,17 +91,6 @@ class VilfoRouterSensor(SensorEntity):
|
|||||||
"""Return whether the sensor is available or not."""
|
"""Return whether the sensor is available or not."""
|
||||||
return self.api.available
|
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:
|
async def async_update(self) -> None:
|
||||||
"""Update the router data."""
|
"""Update the router data."""
|
||||||
await self.api.async_update()
|
await self.api.async_update()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user