From bb2ccafbd889f239e4d182a9498e8610ed9c7974 Mon Sep 17 00:00:00 2001 From: Hunsup Jung Date: Mon, 10 Mar 2025 20:52:46 +0900 Subject: [PATCH 1/3] Update new-matter-lock driver Signed-off-by: Hunsup Jung --- .../matter-lock/profiles/lock-battery.yml | 25 ++++ .../profiles/lock-batteryLevel.yml | 25 ++++ .../profiles/lock-unlatch-battery.yml | 120 +++++++++++++++++ .../profiles/lock-unlatch-batteryLevel.yml | 120 +++++++++++++++++ .../matter-lock/profiles/lock-unlatch.yml | 25 +++- ...lock-user-pin-schedule-unlatch-battery.yml | 126 ++++++++++++++++++ ...user-pin-schedule-unlatch-batteryLevel.yml | 126 ++++++++++++++++++ .../lock-user-pin-schedule-unlatch.yml | 25 +++- .../profiles/lock-user-pin-unlatch.yml | 25 +++- .../profiles/lock-user-schedule-unlatch.yml | 13 +- .../profiles/lock-user-unlatch.yml | 30 ++++- .../matter-lock/src/new-matter-lock/init.lua | 4 +- 12 files changed, 646 insertions(+), 18 deletions(-) create mode 100644 drivers/SmartThings/matter-lock/profiles/lock-battery.yml create mode 100644 drivers/SmartThings/matter-lock/profiles/lock-batteryLevel.yml create mode 100644 drivers/SmartThings/matter-lock/profiles/lock-unlatch-battery.yml create mode 100644 drivers/SmartThings/matter-lock/profiles/lock-unlatch-batteryLevel.yml create mode 100644 drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-battery.yml create mode 100644 drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-batteryLevel.yml diff --git a/drivers/SmartThings/matter-lock/profiles/lock-battery.yml b/drivers/SmartThings/matter-lock/profiles/lock-battery.yml new file mode 100644 index 0000000000..e4e7229b40 --- /dev/null +++ b/drivers/SmartThings/matter-lock/profiles/lock-battery.yml @@ -0,0 +1,25 @@ +name: lock-battery +components: +- id: main + capabilities: + - id: lock + version: 1 + config: + values: + - key: "lock.value" + enabledValues: + - locked + - unlocked + - not fully locked + - id: lockAlarm + version: 1 + - id: remoteControlStatus + version: 1 + - id: battery + version: 1 + - id: firmwareUpdate + version: 1 + - id: refresh + version: 1 + categories: + - name: SmartLock diff --git a/drivers/SmartThings/matter-lock/profiles/lock-batteryLevel.yml b/drivers/SmartThings/matter-lock/profiles/lock-batteryLevel.yml new file mode 100644 index 0000000000..1286fc4a53 --- /dev/null +++ b/drivers/SmartThings/matter-lock/profiles/lock-batteryLevel.yml @@ -0,0 +1,25 @@ +name: lock-batteryLevel +components: +- id: main + capabilities: + - id: lock + version: 1 + config: + values: + - key: "lock.value" + enabledValues: + - locked + - unlocked + - not fully locked + - id: lockAlarm + version: 1 + - id: remoteControlStatus + version: 1 + - id: batteryLevel + version: 1 + - id: firmwareUpdate + version: 1 + - id: refresh + version: 1 + categories: + - name: SmartLock diff --git a/drivers/SmartThings/matter-lock/profiles/lock-unlatch-battery.yml b/drivers/SmartThings/matter-lock/profiles/lock-unlatch-battery.yml new file mode 100644 index 0000000000..c0837439dd --- /dev/null +++ b/drivers/SmartThings/matter-lock/profiles/lock-unlatch-battery.yml @@ -0,0 +1,120 @@ +name: lock-unlatch-battery +components: +- id: main + capabilities: + - id: lock + version: 1 + config: + values: + - key: "lock.value" + enabledValues: + - locked + - unlocked + - unlatched + - not fully locked + - id: lockAlarm + version: 1 + - id: remoteControlStatus + version: 1 + - id: battery + version: 1 + - id: firmwareUpdate + version: 1 + - id: refresh + version: 1 + categories: + - name: SmartLock +deviceConfig: + dashboard: + states: + - component: main + capability: lock + version: 1 + actions: + - component: main + capability: lock + version: 1 + visibleCondition: { + "capability": "lock", + "version": 1, + "component": "main", + "value": "lock.value", + "operator": "DOES_NOT_EQUAL", + "operand": "unlatched" + } + detailView: + - component: main + capability: lock + version: 1 + values: + - key: lock.value + alternatives: + - key: locked + type: inactive + value: '{{i18n.attributes.lock.i18n.value.locked.label}}' + - key: unlocked + value: '{{i18n.attributes.lock.i18n.value.unlocked.label}}' + - key: unlatched + value: '{{i18n.attributes.lock.i18n.value.unlatched.label}}' + - key: not fully locked + value: '{{i18n.attributes.lock.i18n.value.not fully locked.label}}' + patch: + - op: add + path: /1 + value: + capability: lock + version: 1 + component: main + label: '{{i18n.commands.unlatch.label}}' + displayType: pushButton + pushButton: + command: unlatch + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 + - component: main + capability: battery + version: 1 + automation: + conditions: + - component: main + capability: lock + version: 1 + values: + - key: lock.value + alternatives: + - key: locked + type: inactive + value: '{{i18n.attributes.lock.i18n.value.locked.label}}' + - key: unlocked + value: '{{i18n.attributes.lock.i18n.value.unlocked.label}}' + - key: unlatched + value: '{{i18n.attributes.lock.i18n.value.unlatched.label}}' + - key: not fully locked + value: '{{i18n.attributes.lock.i18n.value.not fully locked.label}}' + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 + - component: main + capability: battery + version: 1 + actions: + - component: main + capability: lock + version: 1 + values: + - key: '{{enumCommands}}' + alternatives: + - key: lock + type: inactive + value: '{{i18n.commands.lock.label}}' + - key: unlock + value: '{{i18n.commands.unlock.label}}' + - key: unlatch + value: '{{i18n.commands.unlatch.label}}' diff --git a/drivers/SmartThings/matter-lock/profiles/lock-unlatch-batteryLevel.yml b/drivers/SmartThings/matter-lock/profiles/lock-unlatch-batteryLevel.yml new file mode 100644 index 0000000000..668ec11a6d --- /dev/null +++ b/drivers/SmartThings/matter-lock/profiles/lock-unlatch-batteryLevel.yml @@ -0,0 +1,120 @@ +name: lock-unlatch-batteryLevel +components: +- id: main + capabilities: + - id: lock + version: 1 + config: + values: + - key: "lock.value" + enabledValues: + - locked + - unlocked + - unlatched + - not fully locked + - id: lockAlarm + version: 1 + - id: remoteControlStatus + version: 1 + - id: batteryLevel + version: 1 + - id: firmwareUpdate + version: 1 + - id: refresh + version: 1 + categories: + - name: SmartLock +deviceConfig: + dashboard: + states: + - component: main + capability: lock + version: 1 + actions: + - component: main + capability: lock + version: 1 + visibleCondition: { + "capability": "lock", + "version": 1, + "component": "main", + "value": "lock.value", + "operator": "DOES_NOT_EQUAL", + "operand": "unlatched" + } + detailView: + - component: main + capability: lock + version: 1 + values: + - key: lock.value + alternatives: + - key: locked + type: inactive + value: '{{i18n.attributes.lock.i18n.value.locked.label}}' + - key: unlocked + value: '{{i18n.attributes.lock.i18n.value.unlocked.label}}' + - key: unlatched + value: '{{i18n.attributes.lock.i18n.value.unlatched.label}}' + - key: not fully locked + value: '{{i18n.attributes.lock.i18n.value.not fully locked.label}}' + patch: + - op: add + path: /1 + value: + capability: lock + version: 1 + component: main + label: '{{i18n.commands.unlatch.label}}' + displayType: pushButton + pushButton: + command: unlatch + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 + - component: main + capability: batteryLevel + version: 1 + automation: + conditions: + - component: main + capability: lock + version: 1 + values: + - key: lock.value + alternatives: + - key: locked + type: inactive + value: '{{i18n.attributes.lock.i18n.value.locked.label}}' + - key: unlocked + value: '{{i18n.attributes.lock.i18n.value.unlocked.label}}' + - key: unlatched + value: '{{i18n.attributes.lock.i18n.value.unlatched.label}}' + - key: not fully locked + value: '{{i18n.attributes.lock.i18n.value.not fully locked.label}}' + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 + - component: main + capability: batteryLevel + version: 1 + actions: + - component: main + capability: lock + version: 1 + values: + - key: '{{enumCommands}}' + alternatives: + - key: lock + type: inactive + value: '{{i18n.commands.lock.label}}' + - key: unlock + value: '{{i18n.commands.unlock.label}}' + - key: unlatch + value: '{{i18n.commands.unlatch.label}}' diff --git a/drivers/SmartThings/matter-lock/profiles/lock-unlatch.yml b/drivers/SmartThings/matter-lock/profiles/lock-unlatch.yml index f479990ddf..182963be89 100644 --- a/drivers/SmartThings/matter-lock/profiles/lock-unlatch.yml +++ b/drivers/SmartThings/matter-lock/profiles/lock-unlatch.yml @@ -1,7 +1,6 @@ name: lock-unlatch components: -- label: Main - id: main +- id: main capabilities: - id: lock version: 1 @@ -33,6 +32,14 @@ deviceConfig: - component: main capability: lock version: 1 + visibleCondition: { + "capability": "lock", + "version": 1, + "component": "main", + "value": "lock.value", + "operator": "DOES_NOT_EQUAL", + "operand": "unlatched" + } detailView: - component: main capability: lock @@ -60,6 +67,12 @@ deviceConfig: displayType: pushButton pushButton: command: unlatch + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 automation: conditions: - component: main @@ -77,6 +90,12 @@ deviceConfig: value: '{{i18n.attributes.lock.i18n.value.unlatched.label}}' - key: not fully locked value: '{{i18n.attributes.lock.i18n.value.not fully locked.label}}' + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 actions: - component: main capability: lock @@ -90,4 +109,4 @@ deviceConfig: - key: unlock value: '{{i18n.commands.unlock.label}}' - key: unlatch - value: '{{i18n.commands.unlatch.label}}' \ No newline at end of file + value: '{{i18n.commands.unlatch.label}}' diff --git a/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-battery.yml b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-battery.yml new file mode 100644 index 0000000000..1568f345b1 --- /dev/null +++ b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-battery.yml @@ -0,0 +1,126 @@ +name: lock-user-pin-schedule-unlatch-battery +components: +- id: main + capabilities: + - id: lock + version: 1 + config: + values: + - key: "lock.value" + enabledValues: + - locked + - unlocked + - unlatched + - not fully locked + - id: lockAlarm + version: 1 + - id: remoteControlStatus + version: 1 + - id: lockUsers + version: 1 + - id: lockCredentials + version: 1 + - id: lockSchedules + version: 1 + - id: battery + version: 1 + - id: firmwareUpdate + version: 1 + - id: refresh + version: 1 + categories: + - name: SmartLock +deviceConfig: + dashboard: + states: + - component: main + capability: lock + version: 1 + actions: + - component: main + capability: lock + version: 1 + visibleCondition: { + "capability": "lock", + "version": 1, + "component": "main", + "value": "lock.value", + "operator": "DOES_NOT_EQUAL", + "operand": "unlatched" + } + detailView: + - component: main + capability: lock + version: 1 + values: + - key: lock.value + alternatives: + - key: locked + type: inactive + value: '{{i18n.attributes.lock.i18n.value.locked.label}}' + - key: unlocked + value: '{{i18n.attributes.lock.i18n.value.unlocked.label}}' + - key: unlatched + value: '{{i18n.attributes.lock.i18n.value.unlatched.label}}' + - key: not fully locked + value: '{{i18n.attributes.lock.i18n.value.not fully locked.label}}' + patch: + - op: add + path: /1 + value: + capability: lock + version: 1 + component: main + label: '{{i18n.commands.unlatch.label}}' + displayType: pushButton + pushButton: + command: unlatch + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 + - component: main + capability: battery + version: 1 + automation: + conditions: + - component: main + capability: lock + version: 1 + values: + - key: lock.value + alternatives: + - key: locked + type: inactive + value: '{{i18n.attributes.lock.i18n.value.locked.label}}' + - key: unlocked + value: '{{i18n.attributes.lock.i18n.value.unlocked.label}}' + - key: unlatched + value: '{{i18n.attributes.lock.i18n.value.unlatched.label}}' + - key: not fully locked + value: '{{i18n.attributes.lock.i18n.value.not fully locked.label}}' + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 + - component: main + capability: battery + version: 1 + actions: + - component: main + capability: lock + version: 1 + values: + - key: '{{enumCommands}}' + alternatives: + - key: lock + type: inactive + value: '{{i18n.commands.lock.label}}' + - key: unlock + value: '{{i18n.commands.unlock.label}}' + - key: unlatch + value: '{{i18n.commands.unlatch.label}}' diff --git a/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-batteryLevel.yml b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-batteryLevel.yml new file mode 100644 index 0000000000..5973f1257c --- /dev/null +++ b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-batteryLevel.yml @@ -0,0 +1,126 @@ +name: lock-user-pin-schedule-unlatch-batteryLevel +components: +- id: main + capabilities: + - id: lock + version: 1 + config: + values: + - key: "lock.value" + enabledValues: + - locked + - unlocked + - unlatched + - not fully locked + - id: lockAlarm + version: 1 + - id: remoteControlStatus + version: 1 + - id: lockUsers + version: 1 + - id: lockCredentials + version: 1 + - id: lockSchedules + version: 1 + - id: batteryLevel + version: 1 + - id: firmwareUpdate + version: 1 + - id: refresh + version: 1 + categories: + - name: SmartLock +deviceConfig: + dashboard: + states: + - component: main + capability: lock + version: 1 + actions: + - component: main + capability: lock + version: 1 + visibleCondition: { + "capability": "lock", + "version": 1, + "component": "main", + "value": "lock.value", + "operator": "DOES_NOT_EQUAL", + "operand": "unlatched" + } + detailView: + - component: main + capability: lock + version: 1 + values: + - key: lock.value + alternatives: + - key: locked + type: inactive + value: '{{i18n.attributes.lock.i18n.value.locked.label}}' + - key: unlocked + value: '{{i18n.attributes.lock.i18n.value.unlocked.label}}' + - key: unlatched + value: '{{i18n.attributes.lock.i18n.value.unlatched.label}}' + - key: not fully locked + value: '{{i18n.attributes.lock.i18n.value.not fully locked.label}}' + patch: + - op: add + path: /1 + value: + capability: lock + version: 1 + component: main + label: '{{i18n.commands.unlatch.label}}' + displayType: pushButton + pushButton: + command: unlatch + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 + - component: main + capability: batteryLevel + version: 1 + automation: + conditions: + - component: main + capability: lock + version: 1 + values: + - key: lock.value + alternatives: + - key: locked + type: inactive + value: '{{i18n.attributes.lock.i18n.value.locked.label}}' + - key: unlocked + value: '{{i18n.attributes.lock.i18n.value.unlocked.label}}' + - key: unlatched + value: '{{i18n.attributes.lock.i18n.value.unlatched.label}}' + - key: not fully locked + value: '{{i18n.attributes.lock.i18n.value.not fully locked.label}}' + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 + - component: main + capability: batteryLevel + version: 1 + actions: + - component: main + capability: lock + version: 1 + values: + - key: '{{enumCommands}}' + alternatives: + - key: lock + type: inactive + value: '{{i18n.commands.lock.label}}' + - key: unlock + value: '{{i18n.commands.unlock.label}}' + - key: unlatch + value: '{{i18n.commands.unlatch.label}}' diff --git a/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch.yml b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch.yml index 7ec2fa7518..648cebe133 100644 --- a/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch.yml +++ b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch.yml @@ -1,7 +1,6 @@ name: lock-user-pin-schedule-unlatch components: -- label: Main - id: main +- id: main capabilities: - id: lock version: 1 @@ -39,6 +38,14 @@ deviceConfig: - component: main capability: lock version: 1 + visibleCondition: { + "capability": "lock", + "version": 1, + "component": "main", + "value": "lock.value", + "operator": "DOES_NOT_EQUAL", + "operand": "unlatched" + } detailView: - component: main capability: lock @@ -66,6 +73,12 @@ deviceConfig: displayType: pushButton pushButton: command: unlatch + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 automation: conditions: - component: main @@ -83,6 +96,12 @@ deviceConfig: value: '{{i18n.attributes.lock.i18n.value.unlatched.label}}' - key: not fully locked value: '{{i18n.attributes.lock.i18n.value.not fully locked.label}}' + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 actions: - component: main capability: lock @@ -96,4 +115,4 @@ deviceConfig: - key: unlock value: '{{i18n.commands.unlock.label}}' - key: unlatch - value: '{{i18n.commands.unlatch.label}}' \ No newline at end of file + value: '{{i18n.commands.unlatch.label}}' diff --git a/drivers/SmartThings/matter-lock/profiles/lock-user-pin-unlatch.yml b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-unlatch.yml index e27a6bc0f4..d65fda144b 100644 --- a/drivers/SmartThings/matter-lock/profiles/lock-user-pin-unlatch.yml +++ b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-unlatch.yml @@ -1,7 +1,6 @@ name: lock-user-pin-unlatch components: -- label: Main - id: main +- id: main capabilities: - id: lock version: 1 @@ -37,6 +36,14 @@ deviceConfig: - component: main capability: lock version: 1 + visibleCondition: { + "capability": "lock", + "version": 1, + "component": "main", + "value": "lock.value", + "operator": "DOES_NOT_EQUAL", + "operand": "unlatched" + } detailView: - component: main capability: lock @@ -64,6 +71,12 @@ deviceConfig: displayType: pushButton pushButton: command: unlatch + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 automation: conditions: - component: main @@ -81,6 +94,12 @@ deviceConfig: value: '{{i18n.attributes.lock.i18n.value.unlatched.label}}' - key: not fully locked value: '{{i18n.attributes.lock.i18n.value.not fully locked.label}}' + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 actions: - component: main capability: lock @@ -94,4 +113,4 @@ deviceConfig: - key: unlock value: '{{i18n.commands.unlock.label}}' - key: unlatch - value: '{{i18n.commands.unlatch.label}}' \ No newline at end of file + value: '{{i18n.commands.unlatch.label}}' diff --git a/drivers/SmartThings/matter-lock/profiles/lock-user-schedule-unlatch.yml b/drivers/SmartThings/matter-lock/profiles/lock-user-schedule-unlatch.yml index 10669ccaeb..2b8153ce1d 100644 --- a/drivers/SmartThings/matter-lock/profiles/lock-user-schedule-unlatch.yml +++ b/drivers/SmartThings/matter-lock/profiles/lock-user-schedule-unlatch.yml @@ -1,7 +1,6 @@ name: lock-user-schedule-unlatch components: -- label: Main - id: main +- id: main capabilities: - id: lock version: 1 @@ -37,6 +36,14 @@ deviceConfig: - component: main capability: lock version: 1 + visibleCondition: { + "capability": "lock", + "version": 1, + "component": "main", + "value": "lock.value", + "operator": "DOES_NOT_EQUAL", + "operand": "unlatched" + } detailView: - component: main capability: lock @@ -94,4 +101,4 @@ deviceConfig: - key: unlock value: '{{i18n.commands.unlock.label}}' - key: unlatch - value: '{{i18n.commands.unlatch.label}}' \ No newline at end of file + value: '{{i18n.commands.unlatch.label}}' diff --git a/drivers/SmartThings/matter-lock/profiles/lock-user-unlatch.yml b/drivers/SmartThings/matter-lock/profiles/lock-user-unlatch.yml index eaaf37ae63..f4760d25ee 100644 --- a/drivers/SmartThings/matter-lock/profiles/lock-user-unlatch.yml +++ b/drivers/SmartThings/matter-lock/profiles/lock-user-unlatch.yml @@ -1,7 +1,6 @@ name: lock-user-unlatch components: -- label: Main - id: main +- id: main capabilities: - id: lock version: 1 @@ -35,6 +34,14 @@ deviceConfig: - component: main capability: lock version: 1 + visibleCondition: { + "capability": "lock", + "version": 1, + "component": "main", + "value": "lock.value", + "operator": "DOES_NOT_EQUAL", + "operand": "unlatched" + } detailView: - component: main capability: lock @@ -62,6 +69,15 @@ deviceConfig: displayType: pushButton pushButton: command: unlatch + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 + - component: main + capability: batteryLevel + version: 1 automation: conditions: - component: main @@ -79,7 +95,13 @@ deviceConfig: value: '{{i18n.attributes.lock.i18n.value.unlatched.label}}' - key: not fully locked value: '{{i18n.attributes.lock.i18n.value.not fully locked.label}}' - actions: + - component: main + capability: lockAlarm + version: 1 + - component: main + capability: remoteControlStatus + version: 1 + actions: - component: main capability: lock version: 1 @@ -92,4 +114,4 @@ deviceConfig: - key: unlock value: '{{i18n.commands.unlock.label}}' - key: unlatch - value: '{{i18n.commands.unlatch.label}}' \ No newline at end of file + value: '{{i18n.commands.unlatch.label}}' diff --git a/drivers/SmartThings/matter-lock/src/new-matter-lock/init.lua b/drivers/SmartThings/matter-lock/src/new-matter-lock/init.lua index 65e6e03941..1208b74b5b 100644 --- a/drivers/SmartThings/matter-lock/src/new-matter-lock/init.lua +++ b/drivers/SmartThings/matter-lock/src/new-matter-lock/init.lua @@ -164,7 +164,7 @@ local function do_configure(driver, device) req:merge(clusters.PowerSource.attributes.AttributeList:read()) device:send(req) else - device.log.info(string.format("Updating device profile to %s.", profile_name)) + device.log.info_with({hub_logs=true}, string.format("Updating device profile to %s.", profile_name)) device:try_update_metadata({profile = profile_name}) end end @@ -396,7 +396,7 @@ local function handle_power_source_attribute_list(driver, device, ib, response) elseif support_battery_level then profile_name = profile_name .. "-batteryLevel" end - device.log.info(string.format("Updating device profile to %s.", profile_name)) + device.log.info_with({hub_logs=true}, string.format("Updating device profile to %s.", profile_name)) device:try_update_metadata({profile = profile_name}) end end From b8a563066af53ad831912f5199c0f5844f5f3b57 Mon Sep 17 00:00:00 2001 From: Hunsup Jung Date: Tue, 11 Mar 2025 10:52:47 +0900 Subject: [PATCH 2/3] Fix unit test error Signed-off-by: Hunsup Jung --- .../SmartThings/matter-lock/profiles/lock-unlatch-battery.yml | 2 +- .../matter-lock/profiles/lock-unlatch-batteryLevel.yml | 2 +- drivers/SmartThings/matter-lock/profiles/lock-unlatch.yml | 2 +- .../profiles/lock-user-pin-schedule-unlatch-battery.yml | 2 +- .../profiles/lock-user-pin-schedule-unlatch-batteryLevel.yml | 2 +- .../matter-lock/profiles/lock-user-pin-schedule-unlatch.yml | 2 +- .../SmartThings/matter-lock/profiles/lock-user-pin-unlatch.yml | 2 +- .../matter-lock/profiles/lock-user-schedule-unlatch.yml | 2 +- drivers/SmartThings/matter-lock/profiles/lock-user-unlatch.yml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/SmartThings/matter-lock/profiles/lock-unlatch-battery.yml b/drivers/SmartThings/matter-lock/profiles/lock-unlatch-battery.yml index c0837439dd..b5c04448b8 100644 --- a/drivers/SmartThings/matter-lock/profiles/lock-unlatch-battery.yml +++ b/drivers/SmartThings/matter-lock/profiles/lock-unlatch-battery.yml @@ -36,7 +36,7 @@ deviceConfig: version: 1 visibleCondition: { "capability": "lock", - "version": 1, + "version": "1", "component": "main", "value": "lock.value", "operator": "DOES_NOT_EQUAL", diff --git a/drivers/SmartThings/matter-lock/profiles/lock-unlatch-batteryLevel.yml b/drivers/SmartThings/matter-lock/profiles/lock-unlatch-batteryLevel.yml index 668ec11a6d..a7b89a4bcc 100644 --- a/drivers/SmartThings/matter-lock/profiles/lock-unlatch-batteryLevel.yml +++ b/drivers/SmartThings/matter-lock/profiles/lock-unlatch-batteryLevel.yml @@ -36,7 +36,7 @@ deviceConfig: version: 1 visibleCondition: { "capability": "lock", - "version": 1, + "version": "1", "component": "main", "value": "lock.value", "operator": "DOES_NOT_EQUAL", diff --git a/drivers/SmartThings/matter-lock/profiles/lock-unlatch.yml b/drivers/SmartThings/matter-lock/profiles/lock-unlatch.yml index 182963be89..92a5a30d06 100644 --- a/drivers/SmartThings/matter-lock/profiles/lock-unlatch.yml +++ b/drivers/SmartThings/matter-lock/profiles/lock-unlatch.yml @@ -34,7 +34,7 @@ deviceConfig: version: 1 visibleCondition: { "capability": "lock", - "version": 1, + "version": "1", "component": "main", "value": "lock.value", "operator": "DOES_NOT_EQUAL", diff --git a/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-battery.yml b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-battery.yml index 1568f345b1..ac5392f5ae 100644 --- a/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-battery.yml +++ b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-battery.yml @@ -42,7 +42,7 @@ deviceConfig: version: 1 visibleCondition: { "capability": "lock", - "version": 1, + "version": "1", "component": "main", "value": "lock.value", "operator": "DOES_NOT_EQUAL", diff --git a/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-batteryLevel.yml b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-batteryLevel.yml index 5973f1257c..d4b1d4ce4a 100644 --- a/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-batteryLevel.yml +++ b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch-batteryLevel.yml @@ -42,7 +42,7 @@ deviceConfig: version: 1 visibleCondition: { "capability": "lock", - "version": 1, + "version": "1", "component": "main", "value": "lock.value", "operator": "DOES_NOT_EQUAL", diff --git a/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch.yml b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch.yml index 648cebe133..ee380d8dd9 100644 --- a/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch.yml +++ b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-unlatch.yml @@ -40,7 +40,7 @@ deviceConfig: version: 1 visibleCondition: { "capability": "lock", - "version": 1, + "version": "1", "component": "main", "value": "lock.value", "operator": "DOES_NOT_EQUAL", diff --git a/drivers/SmartThings/matter-lock/profiles/lock-user-pin-unlatch.yml b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-unlatch.yml index d65fda144b..9718179116 100644 --- a/drivers/SmartThings/matter-lock/profiles/lock-user-pin-unlatch.yml +++ b/drivers/SmartThings/matter-lock/profiles/lock-user-pin-unlatch.yml @@ -38,7 +38,7 @@ deviceConfig: version: 1 visibleCondition: { "capability": "lock", - "version": 1, + "version": "1", "component": "main", "value": "lock.value", "operator": "DOES_NOT_EQUAL", diff --git a/drivers/SmartThings/matter-lock/profiles/lock-user-schedule-unlatch.yml b/drivers/SmartThings/matter-lock/profiles/lock-user-schedule-unlatch.yml index 2b8153ce1d..1e03f51b92 100644 --- a/drivers/SmartThings/matter-lock/profiles/lock-user-schedule-unlatch.yml +++ b/drivers/SmartThings/matter-lock/profiles/lock-user-schedule-unlatch.yml @@ -38,7 +38,7 @@ deviceConfig: version: 1 visibleCondition: { "capability": "lock", - "version": 1, + "version": "1", "component": "main", "value": "lock.value", "operator": "DOES_NOT_EQUAL", diff --git a/drivers/SmartThings/matter-lock/profiles/lock-user-unlatch.yml b/drivers/SmartThings/matter-lock/profiles/lock-user-unlatch.yml index f4760d25ee..d1846f1c2e 100644 --- a/drivers/SmartThings/matter-lock/profiles/lock-user-unlatch.yml +++ b/drivers/SmartThings/matter-lock/profiles/lock-user-unlatch.yml @@ -36,7 +36,7 @@ deviceConfig: version: 1 visibleCondition: { "capability": "lock", - "version": 1, + "version": "1", "component": "main", "value": "lock.value", "operator": "DOES_NOT_EQUAL", From 61c17655f6635a15cb0a5a736c579ae6cca454e9 Mon Sep 17 00:00:00 2001 From: Hunsup Jung Date: Tue, 11 Mar 2025 14:17:20 +0900 Subject: [PATCH 3/3] Add test unit for new door lock profiles Signed-off-by: Hunsup Jung --- .../src/test/test_new_matter_lock_battery.lua | 516 +++++++++++++++++- 1 file changed, 504 insertions(+), 12 deletions(-) diff --git a/drivers/SmartThings/matter-lock/src/test/test_new_matter_lock_battery.lua b/drivers/SmartThings/matter-lock/src/test/test_new_matter_lock_battery.lua index 1565b37799..603f056c06 100644 --- a/drivers/SmartThings/matter-lock/src/test/test_new_matter_lock_battery.lua +++ b/drivers/SmartThings/matter-lock/src/test/test_new_matter_lock_battery.lua @@ -22,6 +22,82 @@ local uint32 = require "st.matter.data_types.Uint32" local DoorLock = clusters.DoorLock local mock_device = test.mock_device.build_test_matter_device({ + profile = t_utils.get_profile_definition("lock.yml"), + manufacturer_info = { + vendor_id = 0x147F, + product_id = 0x0001, + }, + endpoints = { + { + endpoint_id = 0, + clusters = { + { cluster_id = clusters.Basic.ID, cluster_type = "SERVER" }, + }, + device_types = { + { device_type_id = 0x0016, device_type_revision = 1 } -- RootNode + } + }, + { + endpoint_id = 1, + clusters = { + { + cluster_id = DoorLock.ID, + cluster_type = "SERVER", + cluster_revision = 1, + feature_map = 0x0, + }, + { + cluster_id = clusters.PowerSource.ID, + cluster_type = "SERVER", + feature_map = 10 + }, + }, + device_types = { + { device_type_id = 0x000A, device_type_revision = 1 } -- Door Lock + } + } + } +}) + +local mock_device_unlatch = test.mock_device.build_test_matter_device({ + profile = t_utils.get_profile_definition("lock-unlatch.yml"), + manufacturer_info = { + vendor_id = 0x147F, + product_id = 0x0001, + }, + endpoints = { + { + endpoint_id = 0, + clusters = { + { cluster_id = clusters.Basic.ID, cluster_type = "SERVER" }, + }, + device_types = { + { device_type_id = 0x0016, device_type_revision = 1 } -- RootNode + } + }, + { + endpoint_id = 1, + clusters = { + { + cluster_id = DoorLock.ID, + cluster_type = "SERVER", + cluster_revision = 1, + feature_map = 0x1000, -- UNLATCH + }, + { + cluster_id = clusters.PowerSource.ID, + cluster_type = "SERVER", + feature_map = 10 + }, + }, + device_types = { + { device_type_id = 0x000A, device_type_revision = 1 } -- Door Lock + } + } + } +}) + +local mock_device_user_pin = test.mock_device.build_test_matter_device({ profile = t_utils.get_profile_definition("lock-user-pin.yml"), manufacturer_info = { vendor_id = 0x147F, @@ -59,24 +135,98 @@ local mock_device = test.mock_device.build_test_matter_device({ } }) +local mock_device_user_pin_schedule_unlatch = test.mock_device.build_test_matter_device({ + profile = t_utils.get_profile_definition("lock-user-pin-schedule-unlatch.yml"), + manufacturer_info = { + vendor_id = 0x147F, + product_id = 0x0001, + }, + endpoints = { + { + endpoint_id = 0, + clusters = { + { cluster_id = clusters.Basic.ID, cluster_type = "SERVER" }, + }, + device_types = { + { device_type_id = 0x0016, device_type_revision = 1 } -- RootNode + } + }, + { + endpoint_id = 1, + clusters = { + { + cluster_id = DoorLock.ID, + cluster_type = "SERVER", + cluster_revision = 1, + feature_map = 0x1591, -- PIN & USR & COTA & WDSCH & YDSCH & UNLATCH + }, + { + cluster_id = clusters.PowerSource.ID, + cluster_type = "SERVER", + feature_map = 10 + }, + }, + device_types = { + { device_type_id = 0x000A, device_type_revision = 1 } -- Door Lock + } + } + } +}) + local function test_init() local subscribe_request = DoorLock.attributes.LockState:subscribe(mock_device) subscribe_request:merge(DoorLock.attributes.OperatingMode:subscribe(mock_device)) - subscribe_request:merge(DoorLock.attributes.NumberOfTotalUsersSupported:subscribe(mock_device)) - subscribe_request:merge(DoorLock.attributes.NumberOfPINUsersSupported:subscribe(mock_device)) - subscribe_request:merge(DoorLock.attributes.MaxPINCodeLength:subscribe(mock_device)) - subscribe_request:merge(DoorLock.attributes.MinPINCodeLength:subscribe(mock_device)) - subscribe_request:merge(DoorLock.attributes.RequirePINforRemoteOperation:subscribe(mock_device)) subscribe_request:merge(DoorLock.events.LockOperation:subscribe(mock_device)) subscribe_request:merge(DoorLock.events.DoorLockAlarm:subscribe(mock_device)) - subscribe_request:merge(DoorLock.events.LockUserChange:subscribe(mock_device)) test.socket["matter"]:__expect_send({mock_device.id, subscribe_request}) test.mock_device.add_test_device(mock_device) end + +local function test_init_unlatch() + local subscribe_request = DoorLock.attributes.LockState:subscribe(mock_device_unlatch) + subscribe_request:merge(DoorLock.attributes.OperatingMode:subscribe(mock_device_unlatch)) + subscribe_request:merge(DoorLock.events.LockOperation:subscribe(mock_device_unlatch)) + subscribe_request:merge(DoorLock.events.DoorLockAlarm:subscribe(mock_device_unlatch)) + test.socket["matter"]:__expect_send({mock_device_unlatch.id, subscribe_request}) + test.mock_device.add_test_device(mock_device_unlatch) +end + +local function test_init_user_pin() + local subscribe_request = DoorLock.attributes.LockState:subscribe(mock_device_user_pin) + subscribe_request:merge(DoorLock.attributes.OperatingMode:subscribe(mock_device_user_pin)) + subscribe_request:merge(DoorLock.attributes.NumberOfTotalUsersSupported:subscribe(mock_device_user_pin)) + subscribe_request:merge(DoorLock.attributes.NumberOfPINUsersSupported:subscribe(mock_device_user_pin)) + subscribe_request:merge(DoorLock.attributes.MaxPINCodeLength:subscribe(mock_device_user_pin)) + subscribe_request:merge(DoorLock.attributes.MinPINCodeLength:subscribe(mock_device_user_pin)) + subscribe_request:merge(DoorLock.attributes.RequirePINforRemoteOperation:subscribe(mock_device_user_pin)) + subscribe_request:merge(DoorLock.events.LockOperation:subscribe(mock_device_user_pin)) + subscribe_request:merge(DoorLock.events.DoorLockAlarm:subscribe(mock_device_user_pin)) + subscribe_request:merge(DoorLock.events.LockUserChange:subscribe(mock_device_user_pin)) + test.socket["matter"]:__expect_send({mock_device_user_pin.id, subscribe_request}) + test.mock_device.add_test_device(mock_device_user_pin) +end + +local function test_init_user_pin_schedule_unlatch() + local subscribe_request = DoorLock.attributes.LockState:subscribe(mock_device_user_pin_schedule_unlatch) + subscribe_request:merge(DoorLock.attributes.OperatingMode:subscribe(mock_device_user_pin_schedule_unlatch)) + subscribe_request:merge(DoorLock.attributes.NumberOfTotalUsersSupported:subscribe(mock_device_user_pin_schedule_unlatch)) + subscribe_request:merge(DoorLock.attributes.NumberOfPINUsersSupported:subscribe(mock_device_user_pin_schedule_unlatch)) + subscribe_request:merge(DoorLock.attributes.MaxPINCodeLength:subscribe(mock_device_user_pin_schedule_unlatch)) + subscribe_request:merge(DoorLock.attributes.MinPINCodeLength:subscribe(mock_device_user_pin_schedule_unlatch)) + subscribe_request:merge(DoorLock.attributes.RequirePINforRemoteOperation:subscribe(mock_device_user_pin_schedule_unlatch)) + subscribe_request:merge(DoorLock.attributes.NumberOfWeekDaySchedulesSupportedPerUser:subscribe(mock_device_user_pin_schedule_unlatch)) + subscribe_request:merge(DoorLock.attributes.NumberOfYearDaySchedulesSupportedPerUser:subscribe(mock_device_user_pin_schedule_unlatch)) + subscribe_request:merge(DoorLock.events.LockOperation:subscribe(mock_device_user_pin_schedule_unlatch)) + subscribe_request:merge(DoorLock.events.DoorLockAlarm:subscribe(mock_device_user_pin_schedule_unlatch)) + subscribe_request:merge(DoorLock.events.LockUserChange:subscribe(mock_device_user_pin_schedule_unlatch)) + test.socket["matter"]:__expect_send({mock_device_user_pin_schedule_unlatch.id, subscribe_request}) + test.mock_device.add_test_device(mock_device_user_pin_schedule_unlatch) +end + test.set_test_init_function(test_init) test.register_coroutine_test( - "Test profile change when attributes related to BAT feature is not available.", + "Test lock profile change when attributes related to BAT feature is not available.", function() test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" }) mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" }) @@ -107,12 +257,12 @@ test.register_coroutine_test( }) } ) - mock_device:expect_metadata_update({ profile = "lock-user-pin" }) + mock_device:expect_metadata_update({ profile = "lock" }) end ) test.register_coroutine_test( - "Test profile change when BatChargeLevel attribute is available", + "Test lock profile change when BatChargeLevel attribute is available", function() test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" }) mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" }) @@ -144,12 +294,12 @@ test.register_coroutine_test( }) } ) - mock_device:expect_metadata_update({ profile = "lock-user-pin-batteryLevel" }) + mock_device:expect_metadata_update({ profile = "lock-batteryLevel" }) end ) test.register_coroutine_test( - "Test profile change when BatChargeLevel and BatPercentRemaining attributes are available", + "Test lock profile change when BatChargeLevel and BatPercentRemaining attributes are available", function() test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" }) mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" }) @@ -182,8 +332,350 @@ test.register_coroutine_test( }) } ) - mock_device:expect_metadata_update({ profile = "lock-user-pin-battery" }) + mock_device:expect_metadata_update({ profile = "lock-battery" }) end ) +test.register_coroutine_test( + "Test lock-unlatch profile change when attributes related to BAT feature is not available.", + function() + test.socket.device_lifecycle:__queue_receive({ mock_device_unlatch.id, "doConfigure" }) + mock_device_unlatch:expect_metadata_update({ provisioning_state = "PROVISIONED" }) + test.socket.capability:__expect_send( + mock_device_unlatch:generate_test_message("main", capabilities.lock.supportedLockCommands({"lock", "unlock", "unlatch"}, {visibility = {displayed = false}})) + ) + test.socket.matter:__expect_send( + { + mock_device_unlatch.id, + clusters.PowerSource.attributes.AttributeList:read() + } + ) + test.wait_for_events() + test.socket.matter:__queue_receive( + { + mock_device_unlatch.id, + clusters.PowerSource.attributes.AttributeList:build_test_report_data(mock_device_unlatch, 1, + { + uint32(0), + uint32(1), + uint32(2), + uint32(31), + uint32(65528), + uint32(65529), + uint32(65531), + uint32(65532), + uint32(65533), + }) + } + ) + mock_device_unlatch:expect_metadata_update({ profile = "lock-unlatch" }) + end, + { test_init = test_init_unlatch } +) + +test.register_coroutine_test( + "Test lock-unlatch profile change when BatChargeLevel attribute is available", + function() + test.socket.device_lifecycle:__queue_receive({ mock_device_unlatch.id, "doConfigure" }) + mock_device_unlatch:expect_metadata_update({ provisioning_state = "PROVISIONED" }) + test.socket.capability:__expect_send( + mock_device_unlatch:generate_test_message("main", capabilities.lock.supportedLockCommands({"lock", "unlock", "unlatch"}, {visibility = {displayed = false}})) + ) + test.socket.matter:__expect_send( + { + mock_device_unlatch.id, + clusters.PowerSource.attributes.AttributeList:read() + } + ) + test.wait_for_events() + test.socket.matter:__queue_receive( + { + mock_device_unlatch.id, + clusters.PowerSource.attributes.AttributeList:build_test_report_data(mock_device_unlatch, 1, + { + uint32(0), + uint32(1), + uint32(2), + uint32(14), -- BatChargeLevel + uint32(31), + uint32(65528), + uint32(65529), + uint32(65531), + uint32(65532), + uint32(65533), + }) + } + ) + mock_device_unlatch:expect_metadata_update({ profile = "lock-unlatch-batteryLevel" }) + end, + { test_init = test_init_unlatch } +) + +test.register_coroutine_test( + "Test lock-unlatch profile change when BatChargeLevel and BatPercentRemaining attributes are available", + function() + test.socket.device_lifecycle:__queue_receive({ mock_device_unlatch.id, "doConfigure" }) + mock_device_unlatch:expect_metadata_update({ provisioning_state = "PROVISIONED" }) + test.socket.capability:__expect_send( + mock_device_unlatch:generate_test_message("main", capabilities.lock.supportedLockCommands({"lock", "unlock", "unlatch"}, {visibility = {displayed = false}})) + ) + test.socket.matter:__expect_send( + { + mock_device_unlatch.id, + clusters.PowerSource.attributes.AttributeList:read() + } + ) + test.wait_for_events() + test.socket.matter:__queue_receive( + { + mock_device_unlatch.id, + clusters.PowerSource.attributes.AttributeList:build_test_report_data(mock_device_unlatch, 1, + { + uint32(0), + uint32(1), + uint32(2), + uint32(12), -- BatPercentRemaining + uint32(14), -- BatChargeLevel + uint32(31), + uint32(65528), + uint32(65529), + uint32(65531), + uint32(65532), + uint32(65533), + }) + } + ) + mock_device_unlatch:expect_metadata_update({ profile = "lock-unlatch-battery" }) + end, + { test_init = test_init_unlatch } +) + +test.register_coroutine_test( + "Test lock-user-pin profile change when attributes related to BAT feature is not available.", + function() + test.socket.device_lifecycle:__queue_receive({ mock_device_user_pin.id, "doConfigure" }) + mock_device_user_pin:expect_metadata_update({ provisioning_state = "PROVISIONED" }) + test.socket.capability:__expect_send( + mock_device_user_pin:generate_test_message("main", capabilities.lock.supportedLockCommands({"lock", "unlock"}, {visibility = {displayed = false}})) + ) + test.socket.matter:__expect_send( + { + mock_device_user_pin.id, + clusters.PowerSource.attributes.AttributeList:read() + } + ) + test.wait_for_events() + test.socket.matter:__queue_receive( + { + mock_device_user_pin.id, + clusters.PowerSource.attributes.AttributeList:build_test_report_data(mock_device_user_pin, 1, + { + uint32(0), + uint32(1), + uint32(2), + uint32(31), + uint32(65528), + uint32(65529), + uint32(65531), + uint32(65532), + uint32(65533), + }) + } + ) + mock_device_user_pin:expect_metadata_update({ profile = "lock-user-pin" }) + end, + { test_init = test_init_user_pin } +) + +test.register_coroutine_test( + "Test lock-user-pin profile change when BatChargeLevel attribute is available", + function() + test.socket.device_lifecycle:__queue_receive({ mock_device_user_pin.id, "doConfigure" }) + mock_device_user_pin:expect_metadata_update({ provisioning_state = "PROVISIONED" }) + test.socket.capability:__expect_send( + mock_device_user_pin:generate_test_message("main", capabilities.lock.supportedLockCommands({"lock", "unlock"}, {visibility = {displayed = false}})) + ) + test.socket.matter:__expect_send( + { + mock_device_user_pin.id, + clusters.PowerSource.attributes.AttributeList:read() + } + ) + test.wait_for_events() + test.socket.matter:__queue_receive( + { + mock_device_user_pin.id, + clusters.PowerSource.attributes.AttributeList:build_test_report_data(mock_device_user_pin, 1, + { + uint32(0), + uint32(1), + uint32(2), + uint32(14), -- BatChargeLevel + uint32(31), + uint32(65528), + uint32(65529), + uint32(65531), + uint32(65532), + uint32(65533), + }) + } + ) + mock_device_user_pin:expect_metadata_update({ profile = "lock-user-pin-batteryLevel" }) + end, + { test_init = test_init_user_pin } +) + +test.register_coroutine_test( + "Test lock-user-pin profile change when BatChargeLevel and BatPercentRemaining attributes are available", + function() + test.socket.device_lifecycle:__queue_receive({ mock_device_user_pin.id, "doConfigure" }) + mock_device_user_pin:expect_metadata_update({ provisioning_state = "PROVISIONED" }) + test.socket.capability:__expect_send( + mock_device_user_pin:generate_test_message("main", capabilities.lock.supportedLockCommands({"lock", "unlock"}, {visibility = {displayed = false}})) + ) + test.socket.matter:__expect_send( + { + mock_device_user_pin.id, + clusters.PowerSource.attributes.AttributeList:read() + } + ) + test.wait_for_events() + test.socket.matter:__queue_receive( + { + mock_device_user_pin.id, + clusters.PowerSource.attributes.AttributeList:build_test_report_data(mock_device_user_pin, 1, + { + uint32(0), + uint32(1), + uint32(2), + uint32(12), -- BatPercentRemaining + uint32(14), -- BatChargeLevel + uint32(31), + uint32(65528), + uint32(65529), + uint32(65531), + uint32(65532), + uint32(65533), + }) + } + ) + mock_device_user_pin:expect_metadata_update({ profile = "lock-user-pin-battery" }) + end, + { test_init = test_init_user_pin } +) + +test.register_coroutine_test( + "Test lock-user-pin-schedule-unlatch profile change when attributes related to BAT feature is not available.", + function() + test.socket.device_lifecycle:__queue_receive({ mock_device_user_pin_schedule_unlatch.id, "doConfigure" }) + mock_device_user_pin_schedule_unlatch:expect_metadata_update({ provisioning_state = "PROVISIONED" }) + test.socket.capability:__expect_send( + mock_device_user_pin_schedule_unlatch:generate_test_message("main", capabilities.lock.supportedLockCommands({"lock", "unlock", "unlatch"}, {visibility = {displayed = false}})) + ) + test.socket.matter:__expect_send( + { + mock_device_user_pin_schedule_unlatch.id, + clusters.PowerSource.attributes.AttributeList:read() + } + ) + test.wait_for_events() + test.socket.matter:__queue_receive( + { + mock_device_user_pin_schedule_unlatch.id, + clusters.PowerSource.attributes.AttributeList:build_test_report_data(mock_device_user_pin_schedule_unlatch, 1, + { + uint32(0), + uint32(1), + uint32(2), + uint32(31), + uint32(65528), + uint32(65529), + uint32(65531), + uint32(65532), + uint32(65533), + }) + } + ) + mock_device_user_pin_schedule_unlatch:expect_metadata_update({ profile = "lock-user-pin-schedule-unlatch" }) + end, + { test_init = test_init_user_pin_schedule_unlatch } +) + +test.register_coroutine_test( + "Test lock-user-pin-schedule-unlatch profile change when BatChargeLevel attribute is available", + function() + test.socket.device_lifecycle:__queue_receive({ mock_device_user_pin_schedule_unlatch.id, "doConfigure" }) + mock_device_user_pin_schedule_unlatch:expect_metadata_update({ provisioning_state = "PROVISIONED" }) + test.socket.capability:__expect_send( + mock_device_user_pin_schedule_unlatch:generate_test_message("main", capabilities.lock.supportedLockCommands({"lock", "unlock", "unlatch"}, {visibility = {displayed = false}})) + ) + test.socket.matter:__expect_send( + { + mock_device_user_pin_schedule_unlatch.id, + clusters.PowerSource.attributes.AttributeList:read() + } + ) + test.wait_for_events() + test.socket.matter:__queue_receive( + { + mock_device_user_pin_schedule_unlatch.id, + clusters.PowerSource.attributes.AttributeList:build_test_report_data(mock_device_user_pin_schedule_unlatch, 1, + { + uint32(0), + uint32(1), + uint32(2), + uint32(14), -- BatChargeLevel + uint32(31), + uint32(65528), + uint32(65529), + uint32(65531), + uint32(65532), + uint32(65533), + }) + } + ) + mock_device_user_pin_schedule_unlatch:expect_metadata_update({ profile = "lock-user-pin-schedule-unlatch-batteryLevel" }) + end, + { test_init = test_init_user_pin_schedule_unlatch } +) + +test.register_coroutine_test( + "Test lock-user-pin-schedule-unlatch profile change when BatChargeLevel and BatPercentRemaining attributes are available", + function() + test.socket.device_lifecycle:__queue_receive({ mock_device_user_pin_schedule_unlatch.id, "doConfigure" }) + mock_device_user_pin_schedule_unlatch:expect_metadata_update({ provisioning_state = "PROVISIONED" }) + test.socket.capability:__expect_send( + mock_device_user_pin_schedule_unlatch:generate_test_message("main", capabilities.lock.supportedLockCommands({"lock", "unlock", "unlatch"}, {visibility = {displayed = false}})) + ) + test.socket.matter:__expect_send( + { + mock_device_user_pin_schedule_unlatch.id, + clusters.PowerSource.attributes.AttributeList:read() + } + ) + test.wait_for_events() + test.socket.matter:__queue_receive( + { + mock_device_user_pin_schedule_unlatch.id, + clusters.PowerSource.attributes.AttributeList:build_test_report_data(mock_device_user_pin_schedule_unlatch, 1, + { + uint32(0), + uint32(1), + uint32(2), + uint32(12), -- BatPercentRemaining + uint32(14), -- BatChargeLevel + uint32(31), + uint32(65528), + uint32(65529), + uint32(65531), + uint32(65532), + uint32(65533), + }) + } + ) + mock_device_user_pin_schedule_unlatch:expect_metadata_update({ profile = "lock-user-pin-schedule-unlatch-battery" }) + end, + { test_init = test_init_user_pin_schedule_unlatch } +) + test.run_registered_tests()