Skip to content

Commit 81ea6f8

Browse files
authored
Migrate Tuya vacuum (status) to use wrapper class (home-assistant#156744)
1 parent 4f88599 commit 81ea6f8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

homeassistant/components/tuya/vacuum.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ def async_discover_device(device_ids: list[str]) -> None:
8080
mode_wrapper=DPCodeEnumWrapper.find_dpcode(
8181
device, DPCode.MODE, prefer_function=True
8282
),
83+
status_wrapper=DPCodeEnumWrapper.find_dpcode(
84+
device, DPCode.STATUS
85+
),
8386
switch_wrapper=DPCodeBooleanWrapper.find_dpcode(
8487
device, DPCode.POWER_GO, prefer_function=True
8588
),
@@ -108,6 +111,7 @@ def __init__(
108111
fan_speed_wrapper: DPCodeEnumWrapper | None,
109112
locate_wrapper: DPCodeBooleanWrapper | None,
110113
mode_wrapper: DPCodeEnumWrapper | None,
114+
status_wrapper: DPCodeEnumWrapper | None,
111115
switch_wrapper: DPCodeBooleanWrapper | None,
112116
) -> None:
113117
"""Init Tuya vacuum."""
@@ -116,6 +120,7 @@ def __init__(
116120
self._fan_speed_wrapper = fan_speed_wrapper
117121
self._locate_wrapper = locate_wrapper
118122
self._mode_wrapper = mode_wrapper
123+
self._status_wrapper = status_wrapper
119124
self._switch_wrapper = switch_wrapper
120125

121126
self._attr_fan_speed_list = []
@@ -151,13 +156,12 @@ def fan_speed(self) -> str | None:
151156
@property
152157
def activity(self) -> VacuumActivity | None:
153158
"""Return Tuya vacuum device state."""
154-
if self.device.status.get(DPCode.PAUSE) and not (
155-
self.device.status.get(DPCode.STATUS)
156-
):
159+
if (status := self._read_wrapper(self._status_wrapper)) is not None:
160+
return TUYA_STATUS_TO_HA.get(status)
161+
162+
if self.device.status.get(DPCode.PAUSE):
157163
return VacuumActivity.PAUSED
158-
if not (status := self.device.status.get(DPCode.STATUS)):
159-
return None
160-
return TUYA_STATUS_TO_HA.get(status)
164+
return None
161165

162166
async def async_start(self, **kwargs: Any) -> None:
163167
"""Start the device."""

0 commit comments

Comments
 (0)