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
Manuel Dipolt 2024-03-25 14:28:07 +01:00 committed by GitHub
parent d398eb1f2c
commit e2a26f6470
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 16 deletions

View File

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

View File

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

View File

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