Add base entity to romy integration (#113750)
* cherry picked base entity changes from the branches romy_binary_sensor & romy_sensor * Update homeassistant/components/romy/entity.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/romy/vacuum.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/romy/entity.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/romy/vacuum.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Update homeassistant/components/romy/vacuum.py Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * code review changes, base entity/coordinator cleanup --------- Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com>pull/114000/head
parent
d398eb1f2c
commit
e2a26f6470
|
@ -1135,6 +1135,7 @@ omit =
|
||||||
homeassistant/components/rocketchat/notify.py
|
homeassistant/components/rocketchat/notify.py
|
||||||
homeassistant/components/romy/__init__.py
|
homeassistant/components/romy/__init__.py
|
||||||
homeassistant/components/romy/coordinator.py
|
homeassistant/components/romy/coordinator.py
|
||||||
|
homeassistant/components/romy/entity.py
|
||||||
homeassistant/components/romy/vacuum.py
|
homeassistant/components/romy/vacuum.py
|
||||||
homeassistant/components/roomba/__init__.py
|
homeassistant/components/roomba/__init__.py
|
||||||
homeassistant/components/roomba/binary_sensor.py
|
homeassistant/components/roomba/binary_sensor.py
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
"""Base entity for ROMY."""
|
||||||
|
|
||||||
|
|
||||||
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
from .coordinator import RomyVacuumCoordinator
|
||||||
|
|
||||||
|
|
||||||
|
class RomyEntity(CoordinatorEntity[RomyVacuumCoordinator]):
|
||||||
|
"""Base ROMY entity."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
|
def __init__(self, coordinator: RomyVacuumCoordinator) -> None:
|
||||||
|
"""Initialize ROMY entity."""
|
||||||
|
super().__init__(coordinator)
|
||||||
|
self.romy = coordinator.romy
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, self.romy.unique_id)},
|
||||||
|
manufacturer="ROMY",
|
||||||
|
name=self.romy.name,
|
||||||
|
model=self.romy.model,
|
||||||
|
)
|
|
@ -6,17 +6,14 @@ https://home-assistant.io/components/vacuum.romy/.
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from romy import RomyRobot
|
|
||||||
|
|
||||||
from homeassistant.components.vacuum import StateVacuumEntity, VacuumEntityFeature
|
from homeassistant.components.vacuum import StateVacuumEntity, VacuumEntityFeature
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
||||||
|
|
||||||
from .const import DOMAIN, LOGGER
|
from .const import DOMAIN, LOGGER
|
||||||
from .coordinator import RomyVacuumCoordinator
|
from .coordinator import RomyVacuumCoordinator
|
||||||
|
from .entity import RomyEntity
|
||||||
|
|
||||||
FAN_SPEED_NONE = "default"
|
FAN_SPEED_NONE = "default"
|
||||||
FAN_SPEED_NORMAL = "normal"
|
FAN_SPEED_NORMAL = "normal"
|
||||||
|
@ -55,32 +52,23 @@ async def async_setup_entry(
|
||||||
"""Set up ROMY vacuum cleaner."""
|
"""Set up ROMY vacuum cleaner."""
|
||||||
|
|
||||||
coordinator: RomyVacuumCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator: RomyVacuumCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
async_add_entities([RomyVacuumEntity(coordinator, coordinator.romy)], True)
|
async_add_entities([RomyVacuumEntity(coordinator)])
|
||||||
|
|
||||||
|
|
||||||
class RomyVacuumEntity(CoordinatorEntity[RomyVacuumCoordinator], StateVacuumEntity):
|
class RomyVacuumEntity(RomyEntity, StateVacuumEntity):
|
||||||
"""Representation of a ROMY vacuum cleaner robot."""
|
"""Representation of a ROMY vacuum cleaner robot."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
|
||||||
_attr_name = None
|
|
||||||
_attr_supported_features = SUPPORT_ROMY_ROBOT
|
_attr_supported_features = SUPPORT_ROMY_ROBOT
|
||||||
_attr_fan_speed_list = FAN_SPEEDS
|
_attr_fan_speed_list = FAN_SPEEDS
|
||||||
|
_attr_name = None
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: RomyVacuumCoordinator,
|
coordinator: RomyVacuumCoordinator,
|
||||||
romy: RomyRobot,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the ROMY Robot."""
|
"""Initialize the ROMY Robot."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self.romy = romy
|
|
||||||
self._attr_unique_id = self.romy.unique_id
|
self._attr_unique_id = self.romy.unique_id
|
||||||
self._device_info = DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, romy.unique_id)},
|
|
||||||
manufacturer="ROMY",
|
|
||||||
name=romy.name,
|
|
||||||
model=romy.model,
|
|
||||||
)
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _handle_coordinator_update(self) -> None:
|
def _handle_coordinator_update(self) -> None:
|
||||||
|
|
Loading…
Reference in New Issue