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

Lock: add lock_state for read-only reporting of lock state

It seems quite common for locks to have a read-only "lock_motor_state"
dp that reports the status of the lock. This is separate from any dp
for performing locking and unlocking if there is one, so having a
read-only lock dp does not cover all the possibilities.

Based on proposed change in PR #3063.
Jason Rumney 9 месяцев назад
Родитель
Сommit
ec3ac5f46a

+ 1 - 0
custom_components/tuya_local/devices/README.md

@@ -694,6 +694,7 @@ The unlock... dps below are normally integers, but can also be boolean, in which
 no information will be available about which specific credential was used to unlock the lock.
 
 - **lock** (optional, boolean): a dp to control the lock state: true = locked, false = unlocked.
+- **lock_state** (optional, boolean): a read-only dp to return the current state of the lock separately from the lock dp (if provided).
 - **open** (optional, boolean): a dp to open or close the door or gate controlled by the lock, or if marked readonly to report the open status.
 - **unlock_fingerprint** (optional, integer): a dp to identify the fingerprint used to unlock the lock.
 - **unlock_password** (optional, integer): a dp to identify the password used to unlock the lock.

+ 1 - 2
custom_components/tuya_local/devices/ailrinni_fingerprint_lock.yaml

@@ -50,9 +50,8 @@ entities:
         optional: true
         persist: false
       - id: 47  # Lock motor state
-        name: lock
+        name: lock_state
         type: boolean
-        readonly: true
         optional: true
         mapping:
           - dps_val: true  # Unlocked

+ 1 - 2
custom_components/tuya_local/devices/ble_hu06_lock.yaml

@@ -38,9 +38,8 @@ entities:
         optional: true
         persist: false
       - id: 47
-        name: lock
+        name: lock_state
         type: boolean
-        readonly: true
       - id: 62
         name: unlock_app
         type: integer

+ 1 - 2
custom_components/tuya_local/devices/ble_kb150a_lock.yaml

@@ -47,9 +47,8 @@ entities:
         optional: true
         persist: false
       - id: 47  # Lock motor state
-        name: lock
+        name: lock_state
         type: boolean
-        readonly: true
         mapping:
           - dps_val: true  # Unlocked
             value: false

+ 1 - 2
custom_components/tuya_local/devices/ble_pulido_p13_lock.yaml

@@ -41,9 +41,8 @@ entities:
         optional: true
         persist: false
       - id: 47  # Lock motor state
-        name: lock
+        name: lock_state
         type: boolean
-        readonly: true
         mapping:
           - dps_val: true  # Unlocked
             value: false

+ 1 - 2
custom_components/tuya_local/devices/ble_ysgbs01_lock.yaml

@@ -46,9 +46,8 @@ entities:
         persist: false
       - id: 47
         type: boolean
-        name: lock
+        name: lock_state
         optional: true
-        readonly: true
       - id: 55
         type: integer
         name: unlock_temp_pwd

+ 1 - 2
custom_components/tuya_local/devices/bstuokey_invisible_lock.yaml

@@ -44,8 +44,7 @@ entities:
           - value: false
       - id: 47
         type: boolean
-        readonly: true
-        name: lock
+        name: lock_state
       - id: 54
         type: string
         optional: true

+ 1 - 2
custom_components/tuya_local/devices/gainsboroughliberty_entrance_lock.yaml

@@ -64,9 +64,8 @@ entities:
             value: false
           - value: false
       - id: 47  # Lock motor state
-        name: lock
+        name: lock_state
         type: boolean
-        readonly: true
         optional: true
         mapping:
           - dps_val: true  # Unlocked

+ 5 - 13
custom_components/tuya_local/devices/hornbill_y4_smart_lock.yaml

@@ -33,7 +33,6 @@ entities:
       # product has a fingerprint recognition function in the hardware.
       - id: 12
         type: integer
-        readonly: true
         name: unlock_fingerprint
         optional: true
         persist: false
@@ -47,7 +46,6 @@ entities:
       - id: 13
         name: unlock_password
         type: integer
-        readonly: true
         optional: true
         persist: false
         range:
@@ -60,7 +58,6 @@ entities:
       - id: 15
         name: unlock_card
         type: integer
-        readonly: true
         optional: true
         persist: false
         range:
@@ -74,7 +71,6 @@ entities:
       - id: 18
         name: open_inside
         type: boolean
-        readonly: true
         optional: true
       # [Report unlocking record] is used for the device to report the door
       # opening record generated by the mobile phone app Bluetooth unlocking.
@@ -82,7 +78,6 @@ entities:
       - id: 19
         name: unlock_ble
         type: integer
-        readonly: true
         optional: true
         persist: false
         range:
@@ -113,8 +108,7 @@ entities:
       - id: 47
         type: boolean
         optional: true
-        name: lock_motor_state
-        readonly: true
+        name: lock_state
       # [Online Temporary Password] is used to add an online temporary
       # password, and supports setting time periods and recurring time limits.
       - id: 51
@@ -274,8 +268,7 @@ entities:
       # under the guidance of pm.
       - id: 21
         type: string
-        readonly: true
-        name: event
+xs        name: event
         optional: true
         mapping:
           - dps_val: wrong_finger
@@ -330,7 +323,6 @@ entities:
     dps:
       - id: 8
         type: integer
-        readonly: true
         name: sensor
         unit: "%"
         optional: true
@@ -418,14 +410,14 @@ entities:
   # detection, it is used to report the door opening and closing status. Only
   # enable this dp if this function is supported.
   # Commented since DP gets reported even if the device doesn't support it.
-  # - entity: select
+  # - entity: sensor
   #   category: config
+  #   class: enum
   #   name: Door Status
   #   dps:
   #     - id: 40
   #       type: string
-  #       name: option
-  #       readonly: true
+  #       name: sensor
   #       optional: true
   #       mapping:
   #         - dps_val: unknown

+ 1 - 2
custom_components/tuya_local/devices/intelbras_IFR7000_lock.yaml

@@ -38,8 +38,7 @@ entities:
         persist: false
       - id: 8
         type: boolean
-        name: lock
-        readonly: true
+        name: lock_state
         mapping:
           - dps_val: true
             value: false

+ 1 - 2
custom_components/tuya_local/devices/orion_dl033ha_lock.yaml

@@ -60,9 +60,8 @@ entities:
             value: false
           - value: false
       - id: 47  # Lock motor state
-        name: lock
+        name: lock_state
         type: boolean
-        readonly: true
         mapping:
           - dps_val: true  # Unlocked
             value: false

+ 5 - 2
custom_components/tuya_local/lock.py

@@ -34,6 +34,7 @@ class TuyaLocalLock(TuyaLocalEntity, LockEntity):
         super().__init__()
         dps_map = self._init_begin(device, config)
         self._lock_dp = dps_map.pop("lock", None)
+        self._lock_state_dp = dps_map.pop("lock_state", None)
         self._open_dp = dps_map.pop("open", None)
         self._unlock_fp_dp = dps_map.pop("unlock_fingerprint", None)
         self._unlock_pw_dp = dps_map.pop("unlock_password", None)
@@ -61,9 +62,11 @@ class TuyaLocalLock(TuyaLocalEntity, LockEntity):
     def is_locked(self):
         """Return the a boolean representing whether the lock is locked."""
         lock = None
-        if self._lock_dp:
+        if self._lock_state_dp:
+            lock = self._lock_state_dp.get_value(self._device)
+        if lock is None and self._lock_dp:
             lock = self._lock_dp.get_value(self._device)
-        else:
+        if lock is None:
             for d in (
                 self._unlock_card_dp,
                 self._unlock_dynpw_dp,