Просмотр исходного кода

Kogan LX10 vacuum: rearrange commands to work more reliably

- rename start dp to activate, which has special handling in code.
- add a conditional mapping based on pause dp.

Vacuum: reorder handling of activate and commands so that commands
take priority.  This allows pause to be handled by command, while
activate dp is used for start, so that the limitation of a single
conditional constraint can be worked with when start and pause are
separate binary dps from the command.

PR #981
Jason Rumney 2 лет назад
Родитель
Сommit
a7820d8d92

+ 16 - 15
custom_components/tuya_local/devices/kogan_lx10_vacuum.yaml

@@ -6,27 +6,30 @@ primary_entity:
   entity: vacuum
   dps:
     - id: 101
-      name: start # clean_switch
+      name: activate # clean_switch
       type: boolean
     - id: 102
       name: pause # pause_switch
       type: boolean
+      hidden: true
     - id: 104
       name: command # clean_mode
       type: string
       mapping:
-        - value: start
-          value_redirect: start
-        - value: pause
-          value_redirect: pause
-        - dps_val: smart
-          value: smart
-        - dps_val: pose
-          value: clean_spot
-        - dps_val: zone
-          value: zone
-        - dps_val: backcharge
-          value: return_to_base
+        - constraint: pause
+          conditions:
+            - dps_val: true
+              value: pause
+            - dps_val: false
+              mapping:
+                - dps_val: smart
+                  value: smart
+                - dps_val: pose
+                  value: clean_spot
+                - dps_val: zone
+                  value: zone
+                - dps_val: backcharge
+                  value: return_to_base
     - id: 105
       name: status # robot_state
       type: string
@@ -86,8 +89,6 @@ primary_entity:
       name: error # robot_fault
       type: bitfield
       mapping:
-        - dps_val: 0
-          value: 0
         - dps_val: 32
           value: Drop sensor abnormal
         - dps_val: 524288

+ 10 - 14
custom_components/tuya_local/vacuum.py

@@ -129,29 +129,25 @@ class TuyaLocalVacuum(TuyaLocalEntity, StateVacuumEntity):
 
     async def async_toggle(self, **kwargs):
         """Toggle the vacuum cleaner."""
-        dps = self._power_dps
-        if not dps:
-            dps = self._activate_dps
+        dps = self._power_dps or self._activate_dps
         if dps:
             switch_to = not dps.get_value(self._device)
             await dps.async_set_value(self._device, switch_to)
 
-    async def async_start(self):
-        if self._activate_dps:
+    async def async_start(self): 
+        dps = self._command_dps or self._status_dps
+        if dps and "start" in dps.values(self._device):
+            await dps.async_set_value(self._device, "start")
+        elif self._activate_dps:
             await self._activate_dps.async_set_value(self._device, True)
-        else:
-            dps = self._command_dps or self._status_dps
-            if "start" in dps.values(self._device):
-                await dps.async_set_value(self._device, "start")
 
     async def async_pause(self):
         """Pause the vacuum cleaner."""
-        if self._activate_dps:
+        dps = self._command_dps or self._status_dps
+        if dps and "pause" in dps.values(self._device):
+            await dps.async_set_value(self._device, "pause")
+        elif self._activate_dps:
             await self._activate_dps.async_set_value(self._device, False)
-        else:
-            dps = self._command_dps or self._status_dps
-            if "pause" in dps.values(self._device):
-                await dps.async_set_value(self._device, "pause")
 
     async def async_return_to_base(self, **kwargs):
         """Tell the vacuum cleaner to return to its base."""