Add properties to miele entity class (#143622)

* Add properties to Entity class

* Remove setter and most platform constructors
This commit is contained in:
Åke Strandberg 2025-04-26 09:55:11 +02:00 committed by GitHub
parent e14a356c24
commit f5d3495c62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 15 additions and 35 deletions

View File

@ -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."""

View File

@ -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

View File

@ -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."""

View File

@ -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."""

View File

@ -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)