From f5d3495c62b17284301299d97f892cc06f332a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20Strandberg?= Date: Sat, 26 Apr 2025 09:55:11 +0200 Subject: [PATCH] Add properties to miele entity class (#143622) * Add properties to Entity class * Remove setter and most platform constructors --- homeassistant/components/miele/button.py | 12 +----------- homeassistant/components/miele/climate.py | 1 - homeassistant/components/miele/entity.py | 13 ++++++++++++- homeassistant/components/miele/light.py | 12 +----------- homeassistant/components/miele/switch.py | 12 +----------- 5 files changed, 15 insertions(+), 35 deletions(-) diff --git a/homeassistant/components/miele/button.py b/homeassistant/components/miele/button.py index f38b4de4b91..e4aacc5124c 100644 --- a/homeassistant/components/miele/button.py +++ b/homeassistant/components/miele/button.py @@ -14,7 +14,7 @@ from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from .const import DOMAIN, PROCESS_ACTION, MieleActions, MieleAppliance -from .coordinator import MieleConfigEntry, MieleDataUpdateCoordinator +from .coordinator import MieleConfigEntry from .entity import MieleEntity _LOGGER = logging.getLogger(__name__) @@ -125,16 +125,6 @@ class MieleButton(MieleEntity, ButtonEntity): entity_description: MieleButtonDescription - def __init__( - self, - coordinator: MieleDataUpdateCoordinator, - device_id: str, - description: MieleButtonDescription, - ) -> None: - """Initialize the button.""" - super().__init__(coordinator, device_id, description) - self.api = coordinator.api - @property def available(self) -> bool: """Return the availability of the entity.""" diff --git a/homeassistant/components/miele/climate.py b/homeassistant/components/miele/climate.py index 2808220cb35..3b591965d2f 100644 --- a/homeassistant/components/miele/climate.py +++ b/homeassistant/components/miele/climate.py @@ -167,7 +167,6 @@ class MieleClimate(MieleEntity, ClimateEntity): ) -> None: """Initialize the climate entity.""" super().__init__(coordinator, device_id, description) - self.api = coordinator.api t_key = self.entity_description.translation_key diff --git a/homeassistant/components/miele/entity.py b/homeassistant/components/miele/entity.py index 337f583cbff..a84c1f1108b 100644 --- a/homeassistant/components/miele/entity.py +++ b/homeassistant/components/miele/entity.py @@ -1,11 +1,12 @@ """Entity base class for the Miele integration.""" -from pymiele import MieleDevice +from pymiele import MieleAction, MieleDevice from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.entity import EntityDescription from homeassistant.helpers.update_coordinator import CoordinatorEntity +from .api import AsyncConfigEntryAuth from .const import DEVICE_TYPE_TAGS, DOMAIN, MANUFACTURER, MieleAppliance, StateStatus from .coordinator import MieleDataUpdateCoordinator @@ -45,6 +46,16 @@ class MieleEntity(CoordinatorEntity[MieleDataUpdateCoordinator]): """Return the device object.""" return self.coordinator.data.devices[self._device_id] + @property + def actions(self) -> MieleAction: + """Return the actions object.""" + return self.coordinator.data.actions[self._device_id] + + @property + def api(self) -> AsyncConfigEntryAuth: + """Return the api object.""" + return self.coordinator.api + @property def available(self) -> bool: """Return the availability of the entity.""" diff --git a/homeassistant/components/miele/light.py b/homeassistant/components/miele/light.py index 46d94e65511..0fbc8124be8 100644 --- a/homeassistant/components/miele/light.py +++ b/homeassistant/components/miele/light.py @@ -20,7 +20,7 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.helpers.typing import StateType from .const import AMBIENT_LIGHT, DOMAIN, LIGHT, LIGHT_OFF, LIGHT_ON, MieleAppliance -from .coordinator import MieleConfigEntry, MieleDataUpdateCoordinator +from .coordinator import MieleConfigEntry from .entity import MieleDevice, MieleEntity _LOGGER = logging.getLogger(__name__) @@ -101,16 +101,6 @@ class MieleLight(MieleEntity, LightEntity): _attr_color_mode = ColorMode.ONOFF _attr_supported_color_modes = {ColorMode.ONOFF} - def __init__( - self, - coordinator: MieleDataUpdateCoordinator, - device_id: str, - description: MieleLightDescription, - ) -> None: - """Initialize the light.""" - super().__init__(coordinator, device_id, description) - self.api = coordinator.api - @property def is_on(self) -> bool: """Return current on/off state.""" diff --git a/homeassistant/components/miele/switch.py b/homeassistant/components/miele/switch.py index 26615f289a5..74a9f0c4785 100644 --- a/homeassistant/components/miele/switch.py +++ b/homeassistant/components/miele/switch.py @@ -25,7 +25,7 @@ from .const import ( MieleAppliance, StateStatus, ) -from .coordinator import MieleConfigEntry, MieleDataUpdateCoordinator +from .coordinator import MieleConfigEntry from .entity import MieleEntity _LOGGER = logging.getLogger(__name__) @@ -139,16 +139,6 @@ class MieleSwitch(MieleEntity, SwitchEntity): entity_description: MieleSwitchDescription - def __init__( - self, - coordinator: MieleDataUpdateCoordinator, - device_id: str, - description: MieleSwitchDescription, - ) -> None: - """Initialize the switch.""" - super().__init__(coordinator, device_id, description) - self.api = coordinator.api - async def async_turn_on(self, **kwargs: Any) -> None: """Turn on the device.""" await self.async_turn_switch(self.entity_description.on_cmd_data)