mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add properties to miele entity class (#143622)
* Add properties to Entity class * Remove setter and most platform constructors
This commit is contained in:
parent
e14a356c24
commit
f5d3495c62
@ -14,7 +14,7 @@ from homeassistant.exceptions import HomeAssistantError
|
|||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN, PROCESS_ACTION, MieleActions, MieleAppliance
|
from .const import DOMAIN, PROCESS_ACTION, MieleActions, MieleAppliance
|
||||||
from .coordinator import MieleConfigEntry, MieleDataUpdateCoordinator
|
from .coordinator import MieleConfigEntry
|
||||||
from .entity import MieleEntity
|
from .entity import MieleEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -125,16 +125,6 @@ class MieleButton(MieleEntity, ButtonEntity):
|
|||||||
|
|
||||||
entity_description: MieleButtonDescription
|
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
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""Return the availability of the entity."""
|
"""Return the availability of the entity."""
|
||||||
|
@ -167,7 +167,6 @@ class MieleClimate(MieleEntity, ClimateEntity):
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the climate entity."""
|
"""Initialize the climate entity."""
|
||||||
super().__init__(coordinator, device_id, description)
|
super().__init__(coordinator, device_id, description)
|
||||||
self.api = coordinator.api
|
|
||||||
|
|
||||||
t_key = self.entity_description.translation_key
|
t_key = self.entity_description.translation_key
|
||||||
|
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
"""Entity base class for the Miele integration."""
|
"""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.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity import EntityDescription
|
from homeassistant.helpers.entity import EntityDescription
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from .api import AsyncConfigEntryAuth
|
||||||
from .const import DEVICE_TYPE_TAGS, DOMAIN, MANUFACTURER, MieleAppliance, StateStatus
|
from .const import DEVICE_TYPE_TAGS, DOMAIN, MANUFACTURER, MieleAppliance, StateStatus
|
||||||
from .coordinator import MieleDataUpdateCoordinator
|
from .coordinator import MieleDataUpdateCoordinator
|
||||||
|
|
||||||
@ -45,6 +46,16 @@ class MieleEntity(CoordinatorEntity[MieleDataUpdateCoordinator]):
|
|||||||
"""Return the device object."""
|
"""Return the device object."""
|
||||||
return self.coordinator.data.devices[self._device_id]
|
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
|
@property
|
||||||
def available(self) -> bool:
|
def available(self) -> bool:
|
||||||
"""Return the availability of the entity."""
|
"""Return the availability of the entity."""
|
||||||
|
@ -20,7 +20,7 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
|||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from .const import AMBIENT_LIGHT, DOMAIN, LIGHT, LIGHT_OFF, LIGHT_ON, MieleAppliance
|
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
|
from .entity import MieleDevice, MieleEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -101,16 +101,6 @@ class MieleLight(MieleEntity, LightEntity):
|
|||||||
_attr_color_mode = ColorMode.ONOFF
|
_attr_color_mode = ColorMode.ONOFF
|
||||||
_attr_supported_color_modes = {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
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return current on/off state."""
|
"""Return current on/off state."""
|
||||||
|
@ -25,7 +25,7 @@ from .const import (
|
|||||||
MieleAppliance,
|
MieleAppliance,
|
||||||
StateStatus,
|
StateStatus,
|
||||||
)
|
)
|
||||||
from .coordinator import MieleConfigEntry, MieleDataUpdateCoordinator
|
from .coordinator import MieleConfigEntry
|
||||||
from .entity import MieleEntity
|
from .entity import MieleEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -139,16 +139,6 @@ class MieleSwitch(MieleEntity, SwitchEntity):
|
|||||||
|
|
||||||
entity_description: MieleSwitchDescription
|
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:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn on the device."""
|
"""Turn on the device."""
|
||||||
await self.async_turn_switch(self.entity_description.on_cmd_data)
|
await self.async_turn_switch(self.entity_description.on_cmd_data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user