Use shorthand attributes in Roomba (#99831)

This commit is contained in:
Joost Lekkerkerker 2023-09-07 15:56:40 +02:00 committed by GitHub
parent 1fe17b5bed
commit 114b5bd1f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 36 deletions

View File

@ -27,7 +27,7 @@ async def async_setup_entry(
class RoombaBinStatus(IRobotEntity, BinarySensorEntity): class RoombaBinStatus(IRobotEntity, BinarySensorEntity):
"""Class to hold Roomba Sensor basic info.""" """Class to hold Roomba Sensor basic info."""
ICON = "mdi:delete-variant" _attr_icon = "mdi:delete-variant"
_attr_translation_key = "bin_full" _attr_translation_key = "bin_full"
@property @property
@ -35,11 +35,6 @@ class RoombaBinStatus(IRobotEntity, BinarySensorEntity):
"""Return the ID of this sensor.""" """Return the ID of this sensor."""
return f"bin_{self._blid}" return f"bin_{self._blid}"
@property
def icon(self):
"""Return the icon of this sensor."""
return self.ICON
@property @property
def is_on(self): def is_on(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""

View File

@ -29,6 +29,8 @@ SUPPORT_BRAAVA = SUPPORT_IROBOT | VacuumEntityFeature.FAN_SPEED
class BraavaJet(IRobotVacuum): class BraavaJet(IRobotVacuum):
"""Braava Jet.""" """Braava Jet."""
_attr_supported_features = SUPPORT_BRAAVA
def __init__(self, roomba, blid): def __init__(self, roomba, blid):
"""Initialize the Roomba handler.""" """Initialize the Roomba handler."""
super().__init__(roomba, blid) super().__init__(roomba, blid)
@ -38,12 +40,7 @@ class BraavaJet(IRobotVacuum):
for behavior in BRAAVA_MOP_BEHAVIORS: for behavior in BRAAVA_MOP_BEHAVIORS:
for spray in BRAAVA_SPRAY_AMOUNT: for spray in BRAAVA_SPRAY_AMOUNT:
speed_list.append(f"{behavior}-{spray}") speed_list.append(f"{behavior}-{spray}")
self._speed_list = speed_list self._attr_fan_speed_list = speed_list
@property
def supported_features(self):
"""Flag vacuum cleaner robot features that are supported."""
return SUPPORT_BRAAVA
@property @property
def fan_speed(self): def fan_speed(self):
@ -62,11 +59,6 @@ class BraavaJet(IRobotVacuum):
pad_wetness_value = pad_wetness.get("disposable") pad_wetness_value = pad_wetness.get("disposable")
return f"{behavior}-{pad_wetness_value}" return f"{behavior}-{pad_wetness_value}"
@property
def fan_speed_list(self):
"""Get the list of available fan speed steps of the vacuum cleaner."""
return self._speed_list
async def async_set_fan_speed(self, fan_speed, **kwargs): async def async_set_fan_speed(self, fan_speed, **kwargs):
"""Set fan speed.""" """Set fan speed."""
try: try:

View File

@ -138,17 +138,14 @@ class IRobotVacuum(IRobotEntity, StateVacuumEntity):
"""Base class for iRobot robots.""" """Base class for iRobot robots."""
_attr_name = None _attr_name = None
_attr_supported_features = SUPPORT_IROBOT
_attr_available = True # Always available, otherwise setup will fail
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)
self._cap_position = self.vacuum_state.get("cap", {}).get("pose") == 1 self._cap_position = self.vacuum_state.get("cap", {}).get("pose") == 1
@property
def supported_features(self):
"""Flag vacuum cleaner robot features that are supported."""
return SUPPORT_IROBOT
@property @property
def battery_level(self): def battery_level(self):
"""Return the battery level of the vacuum cleaner.""" """Return the battery level of the vacuum cleaner."""
@ -159,11 +156,6 @@ class IRobotVacuum(IRobotEntity, StateVacuumEntity):
"""Return the state of the vacuum cleaner.""" """Return the state of the vacuum cleaner."""
return self._robot_state return self._robot_state
@property
def available(self) -> bool:
"""Return True if entity is available."""
return True # Always available, otherwise setup will fail
@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

@ -42,10 +42,8 @@ class RoombaVacuum(IRobotVacuum):
class RoombaVacuumCarpetBoost(RoombaVacuum): class RoombaVacuumCarpetBoost(RoombaVacuum):
"""Roomba robot with carpet boost.""" """Roomba robot with carpet boost."""
@property _attr_fan_speed_list = FAN_SPEEDS
def supported_features(self): _attr_supported_features = SUPPORT_ROOMBA_CARPET_BOOST
"""Flag vacuum cleaner robot features that are supported."""
return SUPPORT_ROOMBA_CARPET_BOOST
@property @property
def fan_speed(self): def fan_speed(self):
@ -62,11 +60,6 @@ class RoombaVacuumCarpetBoost(RoombaVacuum):
fan_speed = FAN_SPEED_ECO fan_speed = FAN_SPEED_ECO
return fan_speed return fan_speed
@property
def fan_speed_list(self):
"""Get the list of available fan speed steps of the vacuum cleaner."""
return FAN_SPEEDS
async def async_set_fan_speed(self, fan_speed, **kwargs): async def async_set_fan_speed(self, fan_speed, **kwargs):
"""Set fan speed.""" """Set fan speed."""
if fan_speed.capitalize() in FAN_SPEEDS: if fan_speed.capitalize() in FAN_SPEEDS: