Use shorthand attributes for Freebox (#99327)
This commit is contained in:
parent
587928223a
commit
e56db78b27
4 changed files with 7 additions and 23 deletions
|
@ -12,7 +12,6 @@ from homeassistant.components.button import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
|
@ -72,13 +71,9 @@ class FreeboxButton(ButtonEntity):
|
|||
"""Initialize a Freebox button."""
|
||||
self.entity_description = description
|
||||
self._router = router
|
||||
self._attr_device_info = router.device_info
|
||||
self._attr_unique_id = f"{router.mac} {description.name}"
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
"""Return the device information."""
|
||||
return self._router.device_info
|
||||
|
||||
async def async_press(self) -> None:
|
||||
"""Press the button."""
|
||||
await self.entity_description.async_press(self._router)
|
||||
|
|
|
@ -61,9 +61,9 @@ class FreeboxDevice(ScannerEntity):
|
|||
self._name = device["primary_name"].strip() or DEFAULT_DEVICE_NAME
|
||||
self._mac = device["l2ident"]["id"]
|
||||
self._manufacturer = device["vendor_name"]
|
||||
self._icon = icon_for_freebox_device(device)
|
||||
self._attr_icon = icon_for_freebox_device(device)
|
||||
self._active = False
|
||||
self._attrs: dict[str, Any] = {}
|
||||
self._attr_extra_state_attributes: dict[str, Any] = {}
|
||||
|
||||
@callback
|
||||
def async_update_state(self) -> None:
|
||||
|
@ -72,7 +72,7 @@ class FreeboxDevice(ScannerEntity):
|
|||
self._active = device["active"]
|
||||
if device.get("attrs") is None:
|
||||
# device
|
||||
self._attrs = {
|
||||
self._attr_extra_state_attributes = {
|
||||
"last_time_reachable": datetime.fromtimestamp(
|
||||
device["last_time_reachable"]
|
||||
),
|
||||
|
@ -80,7 +80,7 @@ class FreeboxDevice(ScannerEntity):
|
|||
}
|
||||
else:
|
||||
# router
|
||||
self._attrs = device["attrs"]
|
||||
self._attr_extra_state_attributes = device["attrs"]
|
||||
|
||||
@property
|
||||
def mac_address(self) -> str:
|
||||
|
@ -102,16 +102,6 @@ class FreeboxDevice(ScannerEntity):
|
|||
"""Return the source type."""
|
||||
return SourceType.ROUTER
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Return the icon."""
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
"""Return the attributes."""
|
||||
return self._attrs
|
||||
|
||||
@callback
|
||||
def async_on_demand_update(self):
|
||||
"""Update state."""
|
||||
|
|
|
@ -197,7 +197,6 @@ class FreeboxDiskSensor(FreeboxSensor):
|
|||
) -> None:
|
||||
"""Initialize a Freebox disk sensor."""
|
||||
super().__init__(router, description)
|
||||
self._disk = disk
|
||||
self._partition = partition
|
||||
self._attr_name = f"{partition['label']} {description.name}"
|
||||
self._attr_unique_id = (
|
||||
|
|
|
@ -48,8 +48,8 @@ class FreeboxSwitch(SwitchEntity):
|
|||
"""Initialize the switch."""
|
||||
self.entity_description = entity_description
|
||||
self._router = router
|
||||
self._attr_device_info = self._router.device_info
|
||||
self._attr_unique_id = f"{self._router.mac} {self.entity_description.name}"
|
||||
self._attr_device_info = router.device_info
|
||||
self._attr_unique_id = f"{router.mac} {entity_description.name}"
|
||||
|
||||
async def _async_set_state(self, enabled: bool):
|
||||
"""Turn the switch on or off."""
|
||||
|
|
Loading…
Add table
Reference in a new issue