Use shorthand attributes in ecovacs vacuum (#70845)

This commit is contained in:
epenet 2022-04-27 09:59:14 +02:00 committed by GitHub
parent 052c3fcb6a
commit ad348d3273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,6 +36,8 @@ def setup_platform(
class EcovacsVacuum(VacuumEntity):
"""Ecovacs Vacuums such as Deebot."""
_attr_fan_speed_list = [sucks.FAN_SPEED_NORMAL, sucks.FAN_SPEED_HIGH]
_attr_should_poll = False
_attr_supported_features = (
VacuumEntityFeature.BATTERY
| VacuumEntityFeature.RETURN_HOME
@ -49,17 +51,16 @@ class EcovacsVacuum(VacuumEntity):
| VacuumEntityFeature.FAN_SPEED
)
def __init__(self, device):
def __init__(self, device: sucks.VacBot) -> None:
"""Initialize the Ecovacs Vacuum."""
self.device = device
self.device.connect_and_wait_until_ready()
if self.device.vacuum.get("nick") is not None:
self._name = str(self.device.vacuum["nick"])
self._attr_name = str(self.device.vacuum["nick"])
else:
# In case there is no nickname defined, use the device id
self._name = str(format(self.device.vacuum["did"]))
self._attr_name = str(format(self.device.vacuum["did"]))
self._fan_speed = None
self._error = None
_LOGGER.debug("Vacuum initialized: %s", self.name)
@ -86,11 +87,6 @@ class EcovacsVacuum(VacuumEntity):
)
self.schedule_update_ha_state()
@property
def should_poll(self) -> bool:
"""Return True if entity has to be polled for state."""
return False
@property
def unique_id(self) -> str:
"""Return an unique ID."""
@ -106,16 +102,6 @@ class EcovacsVacuum(VacuumEntity):
"""Return true if vacuum is currently charging."""
return self.device.is_charging
@property
def name(self):
"""Return the name of the device."""
return self._name
@property
def supported_features(self) -> int:
"""Flag vacuum cleaner features that are supported."""
return self._attr_supported_features
@property
def status(self):
"""Return the status of the vacuum cleaner."""
@ -127,14 +113,14 @@ class EcovacsVacuum(VacuumEntity):
self.device.run(sucks.Charge())
@property
def battery_icon(self):
def battery_icon(self) -> str:
"""Return the battery icon for the vacuum cleaner."""
return icon_for_battery_level(
battery_level=self.battery_level, charging=self.is_charging
)
@property
def battery_level(self):
def battery_level(self) -> int | None:
"""Return the battery level of the vacuum cleaner."""
if self.device.battery_status is not None:
return self.device.battery_status * 100
@ -142,16 +128,10 @@ class EcovacsVacuum(VacuumEntity):
return super().battery_level
@property
def fan_speed(self):
def fan_speed(self) -> str | None:
"""Return the fan speed of the vacuum cleaner."""
return self.device.fan_speed
@property
def fan_speed_list(self):
"""Get the list of available fan speed steps of the vacuum cleaner."""
return [sucks.FAN_SPEED_NORMAL, sucks.FAN_SPEED_HIGH]
def turn_on(self, **kwargs):
"""Turn the vacuum on and start cleaning."""