From ad348d32739abc44654462b0f827a5dc765aa0b1 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 27 Apr 2022 09:59:14 +0200 Subject: [PATCH] Use shorthand attributes in ecovacs vacuum (#70845) --- homeassistant/components/ecovacs/vacuum.py | 36 +++++----------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/homeassistant/components/ecovacs/vacuum.py b/homeassistant/components/ecovacs/vacuum.py index 42dba0336a7..8557658d128 100644 --- a/homeassistant/components/ecovacs/vacuum.py +++ b/homeassistant/components/ecovacs/vacuum.py @@ -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."""