From 8b379254c33e8f0b8fbb76753488160f89035be5 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 11 Jul 2023 20:27:31 +0200 Subject: [PATCH] Migrate Roomba to has entity name (#96085) --- .../components/roomba/binary_sensor.py | 6 +--- .../components/roomba/irobot_base.py | 8 ++---- homeassistant/components/roomba/sensor.py | 28 ++----------------- homeassistant/components/roomba/strings.json | 7 +++++ 4 files changed, 13 insertions(+), 36 deletions(-) diff --git a/homeassistant/components/roomba/binary_sensor.py b/homeassistant/components/roomba/binary_sensor.py index 0acd655363f..f480839388c 100644 --- a/homeassistant/components/roomba/binary_sensor.py +++ b/homeassistant/components/roomba/binary_sensor.py @@ -28,11 +28,7 @@ class RoombaBinStatus(IRobotEntity, BinarySensorEntity): """Class to hold Roomba Sensor basic info.""" ICON = "mdi:delete-variant" - - @property - def name(self): - """Return the name of the sensor.""" - return f"{self._name} Bin Full" + _attr_translation_key = "bin_full" @property def unique_id(self): diff --git a/homeassistant/components/roomba/irobot_base.py b/homeassistant/components/roomba/irobot_base.py index 317209886bd..5dbd1e986f3 100644 --- a/homeassistant/components/roomba/irobot_base.py +++ b/homeassistant/components/roomba/irobot_base.py @@ -61,6 +61,7 @@ class IRobotEntity(Entity): """Base class for iRobot Entities.""" _attr_should_poll = False + _attr_has_entity_name = True def __init__(self, roomba, blid): """Initialize the iRobot handler.""" @@ -135,6 +136,8 @@ class IRobotEntity(Entity): class IRobotVacuum(IRobotEntity, StateVacuumEntity): """Base class for iRobot robots.""" + _attr_name = None + def __init__(self, roomba, blid): """Initialize the iRobot handler.""" super().__init__(roomba, blid) @@ -160,11 +163,6 @@ class IRobotVacuum(IRobotEntity, StateVacuumEntity): """Return True if entity is available.""" return True # Always available, otherwise setup will fail - @property - def name(self): - """Return the name of the device.""" - return self._name - @property def extra_state_attributes(self): """Return the state attributes of the device.""" diff --git a/homeassistant/components/roomba/sensor.py b/homeassistant/components/roomba/sensor.py index c0092922783..dd74a023ff1 100644 --- a/homeassistant/components/roomba/sensor.py +++ b/homeassistant/components/roomba/sensor.py @@ -1,11 +1,9 @@ """Sensor for checking the battery level of Roomba.""" from homeassistant.components.sensor import SensorDeviceClass, SensorEntity -from homeassistant.components.vacuum import STATE_DOCKED from homeassistant.config_entries import ConfigEntry from homeassistant.const import PERCENTAGE, EntityCategory from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.icon import icon_for_battery_level from .const import BLID, DOMAIN, ROOMBA_SESSION from .irobot_base import IRobotEntity @@ -28,36 +26,14 @@ class RoombaBattery(IRobotEntity, SensorEntity): """Class to hold Roomba Sensor basic info.""" _attr_entity_category = EntityCategory.DIAGNOSTIC - - @property - def name(self): - """Return the name of the sensor.""" - return f"{self._name} Battery Level" + _attr_device_class = SensorDeviceClass.BATTERY + _attr_native_unit_of_measurement = PERCENTAGE @property def unique_id(self): """Return the ID of this sensor.""" return f"battery_{self._blid}" - @property - def device_class(self): - """Return the device class of the sensor.""" - return SensorDeviceClass.BATTERY - - @property - def native_unit_of_measurement(self): - """Return the unit_of_measurement of the device.""" - return PERCENTAGE - - @property - def icon(self): - """Return the icon for the battery.""" - charging = bool(self._robot_state == STATE_DOCKED) - - return icon_for_battery_level( - battery_level=self._battery_level, charging=charging - ) - @property def native_value(self): """Return the state of the sensor.""" diff --git a/homeassistant/components/roomba/strings.json b/homeassistant/components/roomba/strings.json index be2e5b99159..206e8c5bae0 100644 --- a/homeassistant/components/roomba/strings.json +++ b/homeassistant/components/roomba/strings.json @@ -47,5 +47,12 @@ } } } + }, + "entity": { + "binary_sensor": { + "bin_full": { + "name": "Bin full" + } + } } }