Skip to content

Commit

Permalink
Switching States to use the new VacuumActivity as many are becoming d…
Browse files Browse the repository at this point in the history
…eprecated (#237)
  • Loading branch information
davidcollom authored Jan 21, 2025
1 parent 25e6f3c commit 3c7e9c7
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions custom_components/gardena_smart_system/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
)
from homeassistant.components.vacuum import (
StateVacuumEntity,
STATE_CLEANING,
STATE_DOCKED,
STATE_RETURNING,
STATE_ERROR,
VacuumActivity,
VacuumEntityFeature,
)

Expand Down Expand Up @@ -98,36 +95,36 @@ async def async_update(self):
if state in ["WARNING", "ERROR", "UNAVAILABLE"]:
self._error_message = self._device.last_error_code
if self._device.last_error_code == "PARKED_DAILY_LIMIT_REACHED":
self._state = STATE_IDLE
self._state = VacuumActivity.IDLE
else:
_LOGGER.debug("Mower has an error")
self._state = STATE_ERROR
self._state = VacuumActivity.ERROR
else:
_LOGGER.debug("Getting mower state")
activity = self._device.activity
_LOGGER.debug("Mower has activity %s", activity)
if activity == "PAUSED":
self._state = PAUSE
self._state = VacuumActivity.PAUSED
elif activity in [
"OK_CUTTING",
"OK_CUTTING_TIMER_OVERRIDDEN",
"OK_LEAVING",
]:
if self._state != STATE_CLEANING:
if self._state != VacuumActivity.CLEANING:
self._stint_start = datetime.now()
self._stint_end = None
self._state = STATE_CLEANING
self._state = VacuumActivity.CLEANING
elif activity == "OK_SEARCHING":
if self._state == STATE_CLEANING:
if self._state == VacuumActivity.CLEANING:
self._stint_end = datetime.now()
self._state = STATE_RETURNING
self._state = VacuumActivity.RETURNING
elif activity in [
"OK_CHARGING",
"PARKED_TIMER",
"PARKED_PARK_SELECTED",
"PARKED_AUTOTIMER",
]:
self._state = STATE_DOCKED
self._state = VacuumActivity.DOCKED
elif activity == "NONE":
self._state = None
_LOGGER.debug("Mower has no activity")
Expand Down Expand Up @@ -159,7 +156,7 @@ def available(self):

def error(self):
"""Return the error message."""
if self._state == STATE_ERROR:
if self._state == VacuumActivity.ERROR:
return self._error_message
return ""

Expand Down

0 comments on commit 3c7e9c7

Please sign in to comment.