Skip to content

Commit

Permalink
Use shorthand attributes in neato vacuum (home-assistant#70843)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Apr 30, 2022
1 parent c8ea264 commit e3f224e
Showing 1 changed file with 9 additions and 38 deletions.
47 changes: 9 additions & 38 deletions homeassistant/components/neato/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ async def async_setup_entry(
class NeatoConnectedVacuum(StateVacuumEntity):
"""Representation of a Neato Connected Vacuum."""

_attr_icon = "mdi:robot-vacuum-variant"
_attr_supported_features = (
VacuumEntityFeature.BATTERY
| VacuumEntityFeature.PAUSE
Expand All @@ -115,12 +116,13 @@ def __init__(
) -> None:
"""Initialize the Neato Connected Vacuum."""
self.robot = robot
self._available: bool = neato is not None
self._attr_available: bool = neato is not None
self._mapdata = mapdata
self._name: str = f"{self.robot.name}"
self._attr_name: str = self.robot.name
self._robot_has_map: bool = self.robot.has_persistent_maps
self._robot_maps = persistent_maps
self._robot_serial: str = self.robot.serial
self._attr_unique_id: str = self.robot.serial
self._status_state: str | None = None
self._clean_state: str | None = None
self._state: dict[str, Any] | None = None
Expand All @@ -134,7 +136,6 @@ def __init__(
self._clean_pause_time: int | None = None
self._clean_error_time: int | None = None
self._launched_from: str | None = None
self._battery_level: int | None = None
self._robot_boundaries: list = []
self._robot_stats: dict[str, Any] | None = None

Expand All @@ -150,17 +151,17 @@ def update(self) -> None:
try:
self._state = self.robot.state
except NeatoRobotException as ex:
if self._available: # print only once when available
if self._attr_available: # print only once when available
_LOGGER.error(
"Neato vacuum connection error for '%s': %s", self.entity_id, ex
)
self._state = None
self._available = False
self._attr_available = False
return

if self._state is None:
return
self._available = True
self._attr_available = True
_LOGGER.debug("self._state=%s", self._state)
if "alert" in self._state:
robot_alert = ALERTS.get(self._state["alert"])
Expand Down Expand Up @@ -205,7 +206,7 @@ def update(self) -> None:
self._clean_state = STATE_ERROR
self._status_state = ERRORS.get(self._state["error"])

self._battery_level = self._state["details"]["charge"]
self._attr_battery_level = self._state["details"]["charge"]

if self._mapdata is None or not self._mapdata.get(self._robot_serial, {}).get(
"maps", []
Expand Down Expand Up @@ -260,41 +261,11 @@ def update(self) -> None:
self._robot_boundaries,
)

@property
def name(self) -> str:
"""Return the name of the device."""
return self._name

@property
def supported_features(self) -> int:
"""Flag vacuum cleaner robot features that are supported."""
return self._attr_supported_features

@property
def battery_level(self) -> int | None:
"""Return the battery level of the vacuum cleaner."""
return self._battery_level

@property
def available(self) -> bool:
"""Return if the robot is available."""
return self._available

@property
def icon(self) -> str:
"""Return neato specific icon."""
return "mdi:robot-vacuum-variant"

@property
def state(self) -> str | None:
"""Return the status of the vacuum cleaner."""
return self._clean_state

@property
def unique_id(self) -> str:
"""Return a unique ID."""
return self._robot_serial

@property
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes of the vacuum cleaner."""
Expand Down Expand Up @@ -333,7 +304,7 @@ def device_info(self) -> DeviceInfo:
identifiers={(NEATO_DOMAIN, self._robot_serial)},
manufacturer=stats["battery"]["vendor"] if stats else None,
model=stats["model"] if stats else None,
name=self._name,
name=self._attr_name,
sw_version=stats["firmware"] if stats else None,
)

Expand Down

0 comments on commit e3f224e

Please sign in to comment.