Migrate Roomba to has entity name (#96085)

This commit is contained in:
Joost Lekkerkerker 2023-07-11 20:27:31 +02:00 committed by GitHub
parent fe44827e3c
commit 8b379254c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 36 deletions

View file

@ -28,11 +28,7 @@ class RoombaBinStatus(IRobotEntity, BinarySensorEntity):
"""Class to hold Roomba Sensor basic info.""" """Class to hold Roomba Sensor basic info."""
ICON = "mdi:delete-variant" ICON = "mdi:delete-variant"
_attr_translation_key = "bin_full"
@property
def name(self):
"""Return the name of the sensor."""
return f"{self._name} Bin Full"
@property @property
def unique_id(self): def unique_id(self):

View file

@ -61,6 +61,7 @@ class IRobotEntity(Entity):
"""Base class for iRobot Entities.""" """Base class for iRobot Entities."""
_attr_should_poll = False _attr_should_poll = False
_attr_has_entity_name = True
def __init__(self, roomba, blid): def __init__(self, roomba, blid):
"""Initialize the iRobot handler.""" """Initialize the iRobot handler."""
@ -135,6 +136,8 @@ class IRobotEntity(Entity):
class IRobotVacuum(IRobotEntity, StateVacuumEntity): class IRobotVacuum(IRobotEntity, StateVacuumEntity):
"""Base class for iRobot robots.""" """Base class for iRobot robots."""
_attr_name = None
def __init__(self, roomba, blid): def __init__(self, roomba, blid):
"""Initialize the iRobot handler.""" """Initialize the iRobot handler."""
super().__init__(roomba, blid) super().__init__(roomba, blid)
@ -160,11 +163,6 @@ class IRobotVacuum(IRobotEntity, StateVacuumEntity):
"""Return True if entity is available.""" """Return True if entity is available."""
return True # Always available, otherwise setup will fail return True # Always available, otherwise setup will fail
@property
def name(self):
"""Return the name of the device."""
return self._name
@property @property
def extra_state_attributes(self): def extra_state_attributes(self):
"""Return the state attributes of the device.""" """Return the state attributes of the device."""

View file

@ -1,11 +1,9 @@
"""Sensor for checking the battery level of Roomba.""" """Sensor for checking the battery level of Roomba."""
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.components.vacuum import STATE_DOCKED
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, EntityCategory from homeassistant.const import PERCENTAGE, EntityCategory
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.icon import icon_for_battery_level
from .const import BLID, DOMAIN, ROOMBA_SESSION from .const import BLID, DOMAIN, ROOMBA_SESSION
from .irobot_base import IRobotEntity from .irobot_base import IRobotEntity
@ -28,36 +26,14 @@ class RoombaBattery(IRobotEntity, SensorEntity):
"""Class to hold Roomba Sensor basic info.""" """Class to hold Roomba Sensor basic info."""
_attr_entity_category = EntityCategory.DIAGNOSTIC _attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_device_class = SensorDeviceClass.BATTERY
@property _attr_native_unit_of_measurement = PERCENTAGE
def name(self):
"""Return the name of the sensor."""
return f"{self._name} Battery Level"
@property @property
def unique_id(self): def unique_id(self):
"""Return the ID of this sensor.""" """Return the ID of this sensor."""
return f"battery_{self._blid}" 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 @property
def native_value(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""

View file

@ -47,5 +47,12 @@
} }
} }
} }
},
"entity": {
"binary_sensor": {
"bin_full": {
"name": "Bin full"
}
}
} }
} }