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

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.
 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** (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.
 - **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_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.
 - **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
         optional: true
         persist: false
         persist: false
       - id: 47  # Lock motor state
       - id: 47  # Lock motor state
-        name: lock
+        name: lock_state
         type: boolean
         type: boolean
-        readonly: true
         optional: true
         optional: true
         mapping:
         mapping:
           - dps_val: true  # Unlocked
           - dps_val: true  # Unlocked

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

+ 5 - 2
custom_components/tuya_local/lock.py

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