From e2a26f64709382c536476c2346d0a95792c7eaad Mon Sep 17 00:00:00 2001 From: Manuel Dipolt Date: Mon, 25 Mar 2024 14:28:07 +0100 Subject: [PATCH] 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> --- .coveragerc | 1 + homeassistant/components/romy/entity.py | 25 +++++++++++++++++++++++++ homeassistant/components/romy/vacuum.py | 20 ++++---------------- 3 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 homeassistant/components/romy/entity.py diff --git a/.coveragerc b/.coveragerc index 8b3067313d3..67c5887f2da 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1135,6 +1135,7 @@ omit = homeassistant/components/rocketchat/notify.py homeassistant/components/romy/__init__.py homeassistant/components/romy/coordinator.py + homeassistant/components/romy/entity.py homeassistant/components/romy/vacuum.py homeassistant/components/roomba/__init__.py homeassistant/components/roomba/binary_sensor.py diff --git a/homeassistant/components/romy/entity.py b/homeassistant/components/romy/entity.py new file mode 100644 index 00000000000..3fa6eefbe02 --- /dev/null +++ b/homeassistant/components/romy/entity.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, + ) diff --git a/homeassistant/components/romy/vacuum.py b/homeassistant/components/romy/vacuum.py index 90189da7e2f..de74d371f0e 100644 --- a/homeassistant/components/romy/vacuum.py +++ b/homeassistant/components/romy/vacuum.py @@ -6,17 +6,14 @@ https://home-assistant.io/components/vacuum.romy/. from typing import Any -from romy import RomyRobot - from homeassistant.components.vacuum import StateVacuumEntity, VacuumEntityFeature from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback -from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import DOMAIN, LOGGER from .coordinator import RomyVacuumCoordinator +from .entity import RomyEntity FAN_SPEED_NONE = "default" FAN_SPEED_NORMAL = "normal" @@ -55,32 +52,23 @@ async def async_setup_entry( """Set up ROMY vacuum cleaner.""" 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.""" - _attr_has_entity_name = True - _attr_name = None _attr_supported_features = SUPPORT_ROMY_ROBOT _attr_fan_speed_list = FAN_SPEEDS + _attr_name = None def __init__( self, coordinator: RomyVacuumCoordinator, - romy: RomyRobot, ) -> None: """Initialize the ROMY Robot.""" super().__init__(coordinator) - self.romy = romy 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 def _handle_coordinator_update(self) -> None: