Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Deprecated vacuum state const in 2025.1 #2280

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion custom_components/xiaomi_miot/core/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,14 @@ class AlarmControlPanelState(StrEnum):
PENDING = "pending"
ARMING = "arming"
DISARMING = "disarming"
TRIGGERED = "triggered"
TRIGGERED = "triggered"

try:
# hass 2025.1
from homeassistant.components.vacuum import VacuumActivity
except (ModuleNotFoundError, ImportError):
class VacuumActivity(StrEnum):
CLEANING = "cleaning"
DOCKED = "docked"
RETURNING = "returning"
ERROR = "error"
16 changes: 6 additions & 10 deletions custom_components/xiaomi_miot/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
DOMAIN as ENTITY_DOMAIN,
StateVacuumEntity,
VacuumEntityFeature, # v2022.5
STATE_CLEANING,
STATE_DOCKED,
STATE_RETURNING,
STATE_ERROR,
z-master42 marked this conversation as resolved.
Show resolved Hide resolved
)

from . import (
Expand Down Expand Up @@ -147,17 +143,17 @@ def state(self):
'Part Sweeping', 'Zone Sweeping', 'Select Sweeping', 'Spot Sweeping', 'Goto Target',
'Starting', 'Working', 'Busy', 'DustCollecting'
):
return STATE_CLEANING
return VacuumActivity.CLEANING
elif val in self._prop_status.list_search('Idle', 'Sleep'):
return STATE_IDLE
elif val in self._prop_status.list_search('Charging', 'Charging Completed', 'Fullcharge', 'Charge Done', 'Drying'):
return STATE_DOCKED
return VacuumActivity.DOCKED
elif val in self._prop_status.list_search('Go Charging'):
return STATE_RETURNING
return VacuumActivity.RETURNING
elif val in self._prop_status.list_search('Paused'):
return STATE_PAUSED
elif val in self._prop_status.list_search('Error', 'Charging Problem'):
return STATE_ERROR
return VacuumActivity.ERROR
else:
return self._prop_status.list_description(val)
return None
Expand Down Expand Up @@ -193,7 +189,7 @@ def pause(self):

def start_pause(self, **kwargs):
sta = self.state
if sta == STATE_CLEANING:
if sta == VacuumActivity.CLEANING:
return self.pause()
return self.start()

Expand Down Expand Up @@ -367,7 +363,7 @@ def start_clean_segment(self, segment, repeat=1, **kwargs):
if not segments:
self.return_to_base()
return False
if self.state == STATE_CLEANING:
if self.state == VacuumActivity.CLEANING:
self.pause()
time.sleep(1)
if self.model in ['roborock.vacuum.m1s']:
Expand Down