Skip to content
Merged
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,9 +6,6 @@ components:
version: 1
- id: lockAlarm
version: 1
- id: doorState
version: 1
optional: true
- id: remoteControlStatus
version: 1
- id: lockUsers
Expand Down
3 changes: 0 additions & 3 deletions drivers/SmartThings/matter-lock/profiles/lock-modular.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ components:
capabilities:
- id: lock
version: 1
- id: doorState
version: 1
optional: true
- id: lockAlarm
version: 1
- id: remoteControlStatus
Expand Down
2 changes: 1 addition & 1 deletion drivers/SmartThings/matter-lock/src/lock_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ local lock_utils = {
COMMAND_REQUEST_ID = "commandRequestId",
MODULAR_PROFILE_UPDATED = "__MODULAR_PROFILE_UPDATED",
ALIRO_READER_CONFIG_UPDATED = "aliroReaderConfigUpdated",
LATEST_DOOR_LOCK_FEATURE_MAP = "latestDoorLockFeatureMap"
LATEST_DOOR_LOCK_FEATURE_MAP = "latestDoorLockFeatureMap",
}
local capabilities = require "st.capabilities"
local json = require "st.json"
Expand Down
64 changes: 1 addition & 63 deletions drivers/SmartThings/matter-lock/src/new-matter-lock/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,13 @@ local battery_support = {

local profiling_data = {
BATTERY_SUPPORT = "__BATTERY_SUPPORT",
ENABLE_DOOR_STATE = "__ENABLE_DOOR_STATE"
}

local DoorLockFeatureMapAttr = {ID = 0xFFFC, cluster = DoorLock.ID}
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 @@ -133,11 +129,6 @@ end

local function device_init(driver, device)
device:set_component_to_endpoint_fn(component_to_endpoint)
if #device:get_endpoints(clusters.DoorLock.ID, {feature_bitmap = clusters.DoorLock.types.Feature.DOOR_POSITION_SENSOR}) == 0 then
device:set_field(profiling_data.ENABLE_DOOR_STATE, false, {persist = true})
else
device:add_subscribed_attribute(clusters.DoorLock.attributes.DoorState)
end
if #device:get_endpoints(clusters.PowerSource.ID, {feature_bitmap = clusters.PowerSource.types.PowerSourceFeature.BATTERY}) == 0 then
device:set_field(profiling_data.BATTERY_SUPPORT, battery_support.NO_BATTERY, {persist = true})
elseif device:get_field(profiling_data.BATTERY_SUPPORT) == nil then
Expand Down Expand Up @@ -267,10 +258,6 @@ local function match_profile_modular(driver, device)
table.insert(main_component_capabilities, capabilities.battery.ID)
end

if device:get_field(profiling_data.ENABLE_DOOR_STATE) then
table.insert(main_component_capabilities, capabilities.doorState.ID)
end

table.insert(enabled_optional_component_capability_pairs, {"main", main_component_capabilities})
if lock_utils.optional_capabilities_list_changed(enabled_optional_component_capability_pairs, device.profile.components) then
device:try_update_metadata({profile = modular_profile_name, optional_component_capabilities = enabled_optional_component_capability_pairs})
Expand Down Expand Up @@ -378,10 +365,7 @@ local function info_changed(driver, device, event, args)
if device:supports_capability_by_id(capabilities.lockAliro.ID) then
set_reader_config(device)
end
if device:supports_capability(capabilities.doorState) and device:get_latest_state("main", capabilities.doorState.ID, capabilities.doorState.supportedDoorStates.NAME) == nil then
device:emit_event(capabilities.doorState.supportedDoorStates({"open", "closed"}, {visibility = {displayed = false}})) -- open and closed are mandatory
end
if device:supports_capability(capabilities.lockAlarm) and device:get_latest_state("main", capabilities.lockAlarm.ID, capabilities.lockAlarm.supportedAlarmValues.NAME) == nil then
if device:get_latest_state("main", capabilities.lockAlarm.ID, capabilities.lockAlarm.supportedAlarmValues.NAME) == nil then
device:emit_event(capabilities.lockAlarm.alarm.clear({state_change = true}))
device:emit_event(capabilities.lockAlarm.supportedAlarmValues({"unableToLockTheDoor"}, {visibility = {displayed = false}})) -- lockJammed is mandatory
end
Expand Down Expand Up @@ -443,45 +427,6 @@ local function lock_state_handler(driver, device, ib, response)
end)
end

local function door_state_handler(driver, device, ib, response)
if ib.data.value == nil then
-- early return on nil data. Also, if ENABLE_DOOR_STATE is unset, set it to false and attempt profile matching.
if device:get_field(profiling_data.ENABLE_DOOR_STATE) == nil then
device:set_field(profiling_data.ENABLE_DOOR_STATE, false, {persist = true})
match_profile(driver, device)
end
return
elseif device:supports_capability(capabilities.doorState) == false then
-- if a non-nil report comes in and the doorState capability is unsupported, set ENABLE_DOOR_STATE to true and attempt profile matching.
device:set_field(profiling_data.ENABLE_DOOR_STATE, true, {persist = true})
match_profile(driver, device)
return
end

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
}
local door_state = DOOR_STATE_MAP[ib.data.value] or doorState.unspecifiedError -- fallback to unspecifiedError if we receive a value we don't recognize
device:emit_event(door_state())

-- add new door states to supportedDoorStates list if not already present.
local supported_door_states = utils.deep_copy(device:get_latest_state("main", capabilities.doorState.ID, capabilities.doorState.supportedDoorStates.NAME) or {})
for _, state in pairs(supported_door_states) do
if state == door_state.NAME then
return
end
end
table.insert(supported_door_states, door_state.NAME)
device:emit_event(capabilities.doorState.supportedDoorStates(supported_door_states, {visibility = {displayed = false}}))
end

---------------------
-- Operating Modes --
---------------------
Expand Down Expand Up @@ -730,12 +675,6 @@ local function door_lock_feature_map_handler(driver, device, ib, response)
local feature_map = lock_utils.get_field_for_endpoint(device, lock_utils.LATEST_DOOR_LOCK_FEATURE_MAP, ib.endpoint_id) or nil
if feature_map ~= ib.data.value then
lock_utils.set_field_for_endpoint(device, lock_utils.LATEST_DOOR_LOCK_FEATURE_MAP, ib.endpoint_id, ib.data.value, { persist = true })
-- If the DPS feature is changed, check the DoorState value and call the match_profile.
if ib.data.value & clusters.DoorLock.types.Feature.DOOR_POSITION_SENSOR == 0 then
device:set_field(profiling_data.ENABLE_DOOR_STATE, false, {persist = true})
else
device:set_field(profiling_data.ENABLE_DOOR_STATE, true, {persist = true})
end
match_profile(driver, device, true)
end
end
Expand Down Expand Up @@ -2992,7 +2931,6 @@ 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
Loading