From e56db78b2714e07f5b361cd31514796aec45232b Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Wed, 30 Aug 2023 15:33:05 +0200 Subject: [PATCH] Use shorthand attributes for Freebox (#99327) --- homeassistant/components/freebox/button.py | 7 +------ .../components/freebox/device_tracker.py | 18 ++++-------------- homeassistant/components/freebox/sensor.py | 1 - homeassistant/components/freebox/switch.py | 4 ++-- 4 files changed, 7 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/freebox/button.py b/homeassistant/components/freebox/button.py index bc40d9560d6..e3a206b43a8 100644 --- a/homeassistant/components/freebox/button.py +++ b/homeassistant/components/freebox/button.py @@ -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) diff --git a/homeassistant/components/freebox/device_tracker.py b/homeassistant/components/freebox/device_tracker.py index 7232f16696e..42e028b881e 100644 --- a/homeassistant/components/freebox/device_tracker.py +++ b/homeassistant/components/freebox/device_tracker.py @@ -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.""" diff --git a/homeassistant/components/freebox/sensor.py b/homeassistant/components/freebox/sensor.py index d065907a914..901bfc63199 100644 --- a/homeassistant/components/freebox/sensor.py +++ b/homeassistant/components/freebox/sensor.py @@ -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 = ( diff --git a/homeassistant/components/freebox/switch.py b/homeassistant/components/freebox/switch.py index a0298a8bbd4..e7547b97d4e 100644 --- a/homeassistant/components/freebox/switch.py +++ b/homeassistant/components/freebox/switch.py @@ -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."""