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