Skip to content

Commit

Permalink
vacuum: support new activity property and VacuumActivity enum
Browse files Browse the repository at this point in the history
New way to return vacuum state introduced in HA 2025.1
This change should avoid the deprecation warnings for the old direct
state returning using constants, which will be removed in 2026.1

Issue #2647
  • Loading branch information
make-all committed Jan 16, 2025
1 parent 833fdf6 commit 1320183
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 42 deletions.
2 changes: 1 addition & 1 deletion custom_components/tuya_local/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"tinytuya==1.16.0",
"tuya-device-sharing-sdk~=0.2.1"
],
"version": "2025.1.0"
"version": "2025.1.1"
}
25 changes: 10 additions & 15 deletions custom_components/tuya_local/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@
SERVICE_CLEAN_SPOT,
SERVICE_RETURN_TO_BASE,
SERVICE_STOP,
STATE_CLEANING,
STATE_DOCKED,
STATE_ERROR,
STATE_IDLE,
STATE_PAUSED,
STATE_RETURNING,
StateVacuumEntity,
VacuumActivity,
VacuumEntityFeature,
)

Expand Down Expand Up @@ -98,25 +93,25 @@ def status(self):
return self._status_dps.get_value(self._device)

@property
def state(self):
def activity(self):
"""Return the state of the vacuum cleaner."""
status = self.status
if self._error_dps and self._error_dps.get_value(self._device):
return STATE_ERROR
return VacuumActivity.ERROR
elif status in [SERVICE_RETURN_TO_BASE, "returning"]:
return STATE_RETURNING
return VacuumActivity.RETURNING
elif status in ["standby", "sleep"]:
return STATE_IDLE
return VacuumActivity.IDLE
elif status == "paused":
return STATE_PAUSED
return VacuumActivity.PAUSED
elif status in ["charging", "charged"]:
return STATE_DOCKED
return VacuumActivity.DOCKED
elif self._power_dps and self._power_dps.get_value(self._device) is False:
return STATE_IDLE
return VacuumActivity.IDLE
elif self._activate_dps and self._activate_dps.get_value(self._device) is False:
return STATE_PAUSED
return VacuumActivity.PAUSED
else:
return STATE_CLEANING
return VacuumActivity.CLEANING

async def async_turn_on(self, **kwargs):
"""Turn on the vacuum cleaner."""
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Tuya Local",
"homeassistant": "2024.12.0",
"homeassistant": "2025.1.0",
"hacs": "2.0.0"
}
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fuzzywuzzy
levenshtein
pytest-homeassistant-custom-component>=0.13.190
pytest-homeassistant-custom-component>=0.13.201
pytest
pytest-asyncio
pytest-cov
Expand Down
20 changes: 8 additions & 12 deletions tests/devices/test_kyvol_e30_vacuum.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from homeassistant.components.button import ButtonDeviceClass
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.components.vacuum import (
STATE_CLEANING,
STATE_ERROR,
STATE_IDLE,
STATE_PAUSED,
STATE_RETURNING,
VacuumActivity,
VacuumEntityFeature,
)
from homeassistant.const import PERCENTAGE, UnitOfArea, UnitOfTime
Expand Down Expand Up @@ -154,23 +150,23 @@ def test_status(self):
self.dps[COMMAND_DPS] = "spiral"
self.assertEqual(self.subject.status, "clean_spot")

def test_state(self):
def test_activity(self):
self.dps[POWER_DPS] = True
self.dps[SWITCH_DPS] = True
self.dps[ERROR_DPS] = 0
self.dps[COMMAND_DPS] = "return_to_base"
self.assertEqual(self.subject.state, STATE_RETURNING)
self.assertEqual(self.subject.activity, VacuumActivity.RETURNING)
self.dps[COMMAND_DPS] = "standby"
self.assertEqual(self.subject.state, STATE_IDLE)
self.assertEqual(self.subject.activity, VacuumActivity.IDLE)
self.dps[COMMAND_DPS] = "random"
self.assertEqual(self.subject.state, STATE_CLEANING)
self.assertEqual(self.subject.activity, VacuumActivity.CLEANING)
self.dps[POWER_DPS] = False
self.assertEqual(self.subject.state, STATE_IDLE)
self.assertEqual(self.subject.activity, VacuumActivity.IDLE)
self.dps[POWER_DPS] = True
self.dps[SWITCH_DPS] = False
self.assertEqual(self.subject.state, STATE_PAUSED)
self.assertEqual(self.subject.activity, VacuumActivity.PAUSED)
self.dps[ERROR_DPS] = 1
self.assertEqual(self.subject.state, STATE_ERROR)
self.assertEqual(self.subject.activity, VacuumActivity.ERROR)

async def test_async_turn_on(self):
async with assert_device_properties_set(
Expand Down
20 changes: 8 additions & 12 deletions tests/devices/test_lefant_m213_vacuum.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.components.vacuum import (
STATE_CLEANING,
STATE_ERROR,
STATE_IDLE,
STATE_PAUSED,
STATE_RETURNING,
VacuumActivity,
VacuumEntityFeature,
)
from homeassistant.const import PERCENTAGE, UnitOfArea, UnitOfTime
Expand Down Expand Up @@ -110,23 +106,23 @@ def test_status(self):
self.dps[STATUS_DPS] = "7"
self.assertEqual(self.subject.status, "standby")

def test_state(self):
def test_activity(self):
self.dps[POWER_DPS] = True
self.dps[SWITCH_DPS] = True
self.dps[ERROR_DPS] = 0
self.dps[STATUS_DPS] = "4"
self.assertEqual(self.subject.state, STATE_RETURNING)
self.assertEqual(self.subject.activity, VacuumActivity.RETURNING)
self.dps[STATUS_DPS] = "7"
self.assertEqual(self.subject.state, STATE_IDLE)
self.assertEqual(self.subject.activity, VacuumActivity.IDLE)
self.dps[STATUS_DPS] = "6"
self.assertEqual(self.subject.state, STATE_CLEANING)
self.assertEqual(self.subject.activity, VacuumActivity.CLEANING)
self.dps[POWER_DPS] = False
self.assertEqual(self.subject.state, STATE_IDLE)
self.assertEqual(self.subject.activity, VacuumActivity.IDLE)
self.dps[POWER_DPS] = True
self.dps[SWITCH_DPS] = False
self.assertEqual(self.subject.state, STATE_PAUSED)
self.assertEqual(self.subject.activity, VacuumActivity.PAUSED)
self.dps[ERROR_DPS] = 1
self.assertEqual(self.subject.state, STATE_ERROR)
self.assertEqual(self.subject.activity, VacuumActivity.ERROR)

async def test_async_turn_on(self):
async with assert_device_properties_set(
Expand Down

0 comments on commit 1320183

Please sign in to comment.