-
Notifications
You must be signed in to change notification settings - Fork 498
Update matter-lock driver for U-tec #1812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
77e05ce
Update matter-lock driver for U-tec
HunsupJung 5ac5f2e
Update test cases for matter-lock
HunsupJung 5002f41
Update handle_power_source_attribute_list function
HunsupJung 49a5c71
Add test cases for matter-lock driver
HunsupJung 0cd0746
Add lock-user-pin-batteryLevel profile
HunsupJung 94dfd14
Modify test_new_matter_lock_battery file
HunsupJung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
drivers/SmartThings/matter-lock/profiles/lock-user-pin-battery.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: lock-user-pin-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: lockUsers | ||
version: 1 | ||
- id: lockCredentials | ||
version: 1 | ||
- id: battery | ||
version: 1 | ||
- id: firmwareUpdate | ||
version: 1 | ||
- id: refresh | ||
version: 1 | ||
categories: | ||
- name: SmartLock |
29 changes: 29 additions & 0 deletions
29
drivers/SmartThings/matter-lock/profiles/lock-user-pin-batteryLevel.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: lock-user-pin-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: lockUsers | ||
version: 1 | ||
- id: lockCredentials | ||
version: 1 | ||
- id: batteryLevel | ||
version: 1 | ||
- id: firmwareUpdate | ||
version: 1 | ||
- id: refresh | ||
version: 1 | ||
categories: | ||
- name: SmartLock |
31 changes: 31 additions & 0 deletions
31
drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-battery.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: lock-user-pin-schedule-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: 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 |
31 changes: 31 additions & 0 deletions
31
drivers/SmartThings/matter-lock/profiles/lock-user-pin-schedule-batteryLevel.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: lock-user-pin-schedule-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: 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,15 +25,19 @@ if version.api < 10 then | |
end | ||
|
||
local DoorLock = clusters.DoorLock | ||
local PowerSource = clusters.PowerSource | ||
local INITIAL_COTA_INDEX = 1 | ||
local ALL_INDEX = 0xFFFE | ||
|
||
local NEW_MATTER_LOCK_PRODUCTS = { | ||
{0x115f, 0x2802}, -- AQARA, U200 | ||
{0x115f, 0x2801}, -- AQARA, U300 | ||
{0x10E1, 0x2002} -- VDA | ||
{0x147F, 0x0001}, -- U-tec | ||
{0x10E1, 0x2002} -- VDA | ||
} | ||
|
||
local PROFILE_BASE_NAME = "__profile_base_name" | ||
|
||
local subscribed_attributes = { | ||
[capabilities.lock.ID] = { | ||
DoorLock.attributes.LockState | ||
|
@@ -53,6 +57,12 @@ local subscribed_attributes = { | |
[capabilities.lockSchedules.ID] = { | ||
DoorLock.attributes.NumberOfWeekDaySchedulesSupportedPerUser, | ||
DoorLock.attributes.NumberOfYearDaySchedulesSupportedPerUser | ||
}, | ||
[capabilities.battery.ID] = { | ||
PowerSource.attributes.BatPercentRemaining | ||
}, | ||
[capabilities.batteryLevel.ID] = { | ||
PowerSource.attributes.BatChargeLevel | ||
} | ||
} | ||
|
||
|
@@ -127,6 +137,7 @@ local function do_configure(driver, device) | |
local week_schedule_eps = device:get_endpoints(DoorLock.ID, {feature_bitmap = DoorLock.types.Feature.WEEK_DAY_ACCESS_SCHEDULES}) | ||
local year_schedule_eps = device:get_endpoints(DoorLock.ID, {feature_bitmap = DoorLock.types.Feature.YEAR_DAY_ACCESS_SCHEDULES}) | ||
local unbolt_eps = device:get_endpoints(DoorLock.ID, {feature_bitmap = DoorLock.types.Feature.UNBOLT}) | ||
local battery_eps = device:get_endpoints(PowerSource.ID, {feature_bitmap = PowerSource.types.PowerSourceFeature.BATTERY}) | ||
|
||
local profile_name = "lock" | ||
if #user_eps > 0 then | ||
|
@@ -144,8 +155,15 @@ local function do_configure(driver, device) | |
else | ||
device:emit_event(capabilities.lock.supportedLockCommands({"lock", "unlock"}, {visibility = {displayed = false}})) | ||
end | ||
device.log.info(string.format("Updating device profile to %s.", profile_name)) | ||
device:try_update_metadata({profile = profile_name}) | ||
if #battery_eps > 0 then | ||
device:set_field(PROFILE_BASE_NAME, profile_name, {persist = true}) | ||
local req = im.InteractionRequest(im.InteractionRequest.RequestType.READ, {}) | ||
req:merge(clusters.PowerSource.attributes.AttributeList:read()) | ||
device:send(req) | ||
else | ||
device.log.info(string.format("Updating device profile to %s.", profile_name)) | ||
device:try_update_metadata({profile = profile_name}) | ||
end | ||
end | ||
|
||
local function info_changed(driver, device, event, args) | ||
|
@@ -353,6 +371,55 @@ local function max_year_schedule_of_user_handler(driver, device, ib, response) | |
device:emit_event(capabilities.lockSchedules.yearDaySchedulesPerUser(ib.data.value, {visibility = {displayed = false}})) | ||
end | ||
|
||
--------------------------------- | ||
-- Power Source Attribute List -- | ||
--------------------------------- | ||
local function handle_power_source_attribute_list(driver, device, ib, response) | ||
local support_battery_percentage = false | ||
local support_battery_level = false | ||
for _, attr in ipairs(ib.data.elements) do | ||
-- Re-profile the device if BatPercentRemaining (Attribute ID 0x0C) is present. | ||
if attr.value == 0x0C then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add an explicit check for the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I will |
||
support_battery_percentage = true | ||
end | ||
if attr.value == 0x0E then | ||
support_battery_level = true | ||
end | ||
end | ||
local profile_name = device:get_field(PROFILE_BASE_NAME) | ||
if profile_name ~= nil then | ||
if support_battery_percentage then | ||
profile_name = profile_name .. "-battery" | ||
elseif support_battery_level then | ||
profile_name = profile_name .. "-batteryLevel" | ||
end | ||
device.log.info(string.format("Updating device profile to %s.", profile_name)) | ||
device:try_update_metadata({profile = profile_name}) | ||
end | ||
end | ||
|
||
------------------------------- | ||
-- Battery Percent Remaining -- | ||
------------------------------- | ||
local function handle_battery_percent_remaining(driver, device, ib, response) | ||
if ib.data.value ~= nil then | ||
device:emit_event(capabilities.battery.battery(math.floor(ib.data.value / 2.0 + 0.5))) | ||
end | ||
end | ||
|
||
-------------------------- | ||
-- Battery Charge Level -- | ||
-------------------------- | ||
local function handle_battery_charge_level(driver, device, ib, response) | ||
if ib.data.value == PowerSource.types.BatChargeLevelEnum.OK then | ||
device:emit_event(capabilities.batteryLevel.battery.normal()) | ||
elseif ib.data.value == PowerSource.types.BatChargeLevelEnum.WARNING then | ||
device:emit_event(capabilities.batteryLevel.battery.warning()) | ||
elseif ib.data.value == PowerSource.types.BatChargeLevelEnum.CRITICAL then | ||
device:emit_event(capabilities.batteryLevel.battery.critical()) | ||
end | ||
end | ||
|
||
-- Capability Handler | ||
----------------- | ||
-- Lock/Unlock -- | ||
|
@@ -1671,6 +1738,11 @@ local new_matter_lock_handler = { | |
[DoorLock.attributes.RequirePINforRemoteOperation.ID] = require_remote_pin_handler, | ||
[DoorLock.attributes.NumberOfWeekDaySchedulesSupportedPerUser.ID] = max_week_schedule_of_user_handler, | ||
[DoorLock.attributes.NumberOfYearDaySchedulesSupportedPerUser.ID] = max_year_schedule_of_user_handler, | ||
}, | ||
[PowerSource.ID] = { | ||
[PowerSource.attributes.AttributeList.ID] = handle_power_source_attribute_list, | ||
[PowerSource.attributes.BatPercentRemaining.ID] = handle_battery_percent_remaining, | ||
[PowerSource.attributes.BatChargeLevel.ID] = handle_battery_charge_level, | ||
} | ||
}, | ||
event = { | ||
|
@@ -1723,7 +1795,9 @@ local new_matter_lock_handler = { | |
capabilities.lock, | ||
capabilities.lockUsers, | ||
capabilities.lockCredentials, | ||
capabilities.lockSchedules | ||
capabilities.lockSchedules, | ||
capabilities.battery, | ||
capabilities.batteryLevel | ||
}, | ||
can_handle = is_new_matter_lock_products | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.