From 0dc145aee3940b05db41882871bdfbda9c054b76 Mon Sep 17 00:00:00 2001 From: Jiacheng Ma Date: Tue, 8 Jul 2025 01:03:35 -0700 Subject: [PATCH] Fix tuya vacuum return_to_base function (#144362) Co-authored-by: Franck Nijhof --- homeassistant/components/tuya/vacuum.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/tuya/vacuum.py b/homeassistant/components/tuya/vacuum.py index e36a682fa4e..f722fd918ca 100644 --- a/homeassistant/components/tuya/vacuum.py +++ b/homeassistant/components/tuya/vacuum.py @@ -91,14 +91,15 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity): if self.find_dpcode(DPCode.PAUSE, prefer_function=True): self._attr_supported_features |= VacuumEntityFeature.PAUSE - if self.find_dpcode(DPCode.SWITCH_CHARGE, prefer_function=True) or ( - ( - enum_type := self.find_dpcode( - DPCode.MODE, dptype=DPType.ENUM, prefer_function=True - ) + self._return_home_use_switch_charge = False + if self.find_dpcode(DPCode.SWITCH_CHARGE, prefer_function=True): + self._attr_supported_features |= VacuumEntityFeature.RETURN_HOME + self._return_home_use_switch_charge = True + elif ( + enum_type := self.find_dpcode( + DPCode.MODE, dptype=DPType.ENUM, prefer_function=True ) - and TUYA_MODE_RETURN_HOME in enum_type.range - ): + ) and TUYA_MODE_RETURN_HOME in enum_type.range: self._attr_supported_features |= VacuumEntityFeature.RETURN_HOME if self.find_dpcode(DPCode.SEEK, prefer_function=True): @@ -159,12 +160,10 @@ class TuyaVacuumEntity(TuyaEntity, StateVacuumEntity): def return_to_base(self, **kwargs: Any) -> None: """Return device to dock.""" - self._send_command( - [ - {"code": DPCode.SWITCH_CHARGE, "value": True}, - {"code": DPCode.MODE, "value": TUYA_MODE_RETURN_HOME}, - ] - ) + if self._return_home_use_switch_charge: + self._send_command([{"code": DPCode.SWITCH_CHARGE, "value": True}]) + else: + self._send_command([{"code": DPCode.MODE, "value": TUYA_MODE_RETURN_HOME}]) def locate(self, **kwargs: Any) -> None: """Locate the device."""