Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ components:
version: 1
- id: lockAlarm
version: 1
- id: doorState
version: 1
optional: true
- id: remoteControlStatus
version: 1
- id: lockUsers
Expand Down
3 changes: 3 additions & 0 deletions drivers/SmartThings/matter-lock/profiles/lock-modular.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ components:
capabilities:
- id: lock
version: 1
- id: doorState
version: 1
optional: true
- id: lockAlarm
version: 1
- id: remoteControlStatus
Expand Down
33 changes: 33 additions & 0 deletions drivers/SmartThings/matter-lock/src/new-matter-lock/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ local subscribed_attributes = {
[capabilities.lock.ID] = {
DoorLock.attributes.LockState
},
[capabilities.doorState.ID] = {
DoorLock.attributes.DoorState
},
[capabilities.remoteControlStatus.ID] = {
DoorLock.attributes.OperatingMode
},
Expand Down Expand Up @@ -221,6 +224,12 @@ local function match_profile_modular(driver, device)
local clus_has_feature = function(feature_bitmap)
return DoorLock.are_features_supported(feature_bitmap, ep_cluster.feature_map)
end
if clus_has_feature(DoorLock.types.Feature.DOOR_POSITION_SENSOR) then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that at least some locks will set the DOOR_POSITION_SENSOR feature flag by default even if a door sensor is not configured. They will report NULL for the DoorState attribute until one has been configured. So I think we should check DoorState and the DPS flag and if they are non-NULL and the flag is set then we can say doorState is supported on this lock.

table.insert(main_component_capabilities, capabilities.doorState.ID)
device.thread:call_with_delay(5, function(t)
device:emit_event(capabilities.doorState.supportedDoorStates({"open", "closed"}, {visibility = {displayed = false}})) -- open and closed are mandatory
end)
end
if clus_has_feature(DoorLock.types.Feature.USER) then
table.insert(main_component_capabilities, capabilities.lockUsers.ID)
end
Expand Down Expand Up @@ -383,6 +392,29 @@ local function lock_state_handler(driver, device, ib, response)
end)
end

local function door_state_handler(driver, device, ib, response)
local DoorStateEnum = DoorLock.types.DoorStateEnum
local doorState = capabilities.doorState.doorState
local DOOR_STATE_MAP = {
[DoorStateEnum.DOOR_OPEN] = doorState.open,
[DoorStateEnum.DOOR_CLOSED] = doorState.closed,
[DoorStateEnum.DOOR_JAMMED] = doorState.jammed,
[DoorStateEnum.DOOR_FORCED_OPEN] = doorState.forcedOpen,
[DoorStateEnum.DOOR_UNSPECIFIED_ERROR] = doorState.unspecifiedError,
[DoorStateEnum.DOOR_AJAR] = doorState.ajar
}
device:emit_event(DOOR_STATE_MAP[ib.data.value]())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DoorState is a nullable attribute so you should check for nil here


local supportedDoorStates = device:get_latest_state("main", capabilities.doorState.ID, capabilities.doorState.supportedDoorStates.NAME) or {}
for _, state in pairs(supportedDoorStates) do
if state == DOOR_STATE_MAP[ib.data.value].NAME then
return
end
end
table.insert(supportedDoorStates, DOOR_STATE_MAP[ib.data.value].NAME);
device:emit_event(capabilities.doorState.supportedDoorStates(supportedDoorStates, {visibility = {displayed = false}}))
end

---------------------
-- Operating Modes --
---------------------
Expand Down Expand Up @@ -2884,6 +2916,7 @@ local new_matter_lock_handler = {
attr = {
[DoorLock.ID] = {
[DoorLock.attributes.LockState.ID] = lock_state_handler,
[DoorLock.attributes.DoorState.ID] = door_state_handler,
[DoorLock.attributes.OperatingMode.ID] = operating_modes_handler,
[DoorLock.attributes.NumberOfTotalUsersSupported.ID] = total_users_supported_handler,
[DoorLock.attributes.NumberOfPINUsersSupported.ID] = pin_users_supported_handler,
Expand Down
Loading