Skip to content

Commit

Permalink
Merge pull request #1327 from SmartThingsCommunity/beta
Browse files Browse the repository at this point in the history
Rolling Up Beta to Production
  • Loading branch information
greens authored Apr 16, 2024
2 parents c30d6c6 + 561dcea commit 37e5ce8
Show file tree
Hide file tree
Showing 9 changed files with 719 additions and 0 deletions.
133 changes: 133 additions & 0 deletions drivers/Aqara/aqara-lock/capabilities/lockCredentialInfo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
id: stse.lockCredentialInfo
version: 1
status: proposed
name: Lock Credential Info
ephemeral: false
attributes:
credentialInfo:
schema:
type: object
properties:
value:
type: array
items:
title: Credential info
type: object
additionalProperties: false
properties:
credentialId:
type: integer
minimum: 0
credentialType:
type: string
enum:
- keypad
- rfid
- fingerprint
userId:
type: string
maxLength: 255
userLabel:
type: string
maxLength: 255
userType:
type: string
enum:
- unknown
- administrator
- regularUser
- frequentVisitors
- host
required:
- credentialId
- credentialType
- userId
- userLabel
- userType
additionalProperties: false
required:
- value
enumCommands: []
commands:
syncAll:
name: syncAll
arguments:
- name: credentialInfo
optional: false
schema:
title: Credential info
type: array
items:
properties:
credentialId:
type: integer
minimum: 0
credentialType:
type: string
enum:
- keypad
- rfid
- fingerprint
userId:
type: string
maxLength: 255
userLabel:
type: string
maxLength: 255
userType:
type: string
enum:
- unknown
- administrator
- regularUser
- frequentVisitors
- host
upsert:
name: upsert
arguments:
- name: credentialInfo
optional: false
schema:
title: Credential info
type: array
items:
properties:
credentialId:
type: integer
minimum: 0
credentialType:
type: string
enum:
- keypad
- rfid
- fingerprint
userId:
type: string
maxLength: 255
userLabel:
type: string
maxLength: 255
userType:
type: string
enum:
- unknown
- administrator
- regularUser
- frequentVisitors
- host
deleteUser:
name: deleteUser
arguments:
- name: userId
optional: false
schema:
type: integer
minimum: 0
deleteCredential:
name: deleteCredential
arguments:
- name: credentialId
optional: false
schema:
type: integer
minimum: 0
7 changes: 7 additions & 0 deletions drivers/Aqara/aqara-lock/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: 'Aqara Lock'
packageKey: 'aqara-lock'
permissions:
aqara_provisioning: {}
zigbee: {}
description: "SmartThings driver for Aqara Doorlock"
vendorSupportInformation: "https://www.aqara.com/en/support/"
6 changes: 6 additions & 0 deletions drivers/Aqara/aqara-lock/fingerprints.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
zigbeeManufacturer:
- id: "LUMI/aqara.lock.akr011"
deviceLabel: "Aqara Doorlock K100"
manufacturer: Lumi
model: aqara.lock.akr011
deviceProfileName: aqara-lock-battery
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"dashboard": {
"states": [],
"actions": [],
"basicPlus": []
},
"id": "stse.lockCredentialInfo",
"version": 1
}

21 changes: 21 additions & 0 deletions drivers/Aqara/aqara-lock/profiles/aqara-lock-battery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: aqara-lock-battery
components:
- id: main
capabilities:
- id: lock
version: 1
- id: battery
version: 1
- id: tamperAlert
version: 1
- id: remoteControlStatus
version: 1
- id: firmwareUpdate
version: 1
- id: stse.lockCredentialInfo
version: 1
categories:
- name: SmartLock
metadata:
mnmn: "SolutionsEngineering"
vid: "SmartThings-smartthings-Aqara_K100"
143 changes: 143 additions & 0 deletions drivers/Aqara/aqara-lock/src/credential_utils.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
local capabilities = require "st.capabilities"
local utils = require "st.utils"

local remoteControlStatus = capabilities.remoteControlStatus
local lockCredentialInfo = capabilities["stse.lockCredentialInfo"]

local credential_utils = {}
local HOST_COUNT = "__host_count"

credential_utils.save_data = function(driver)
driver.datastore:save()
driver.datastore:commit()
end

credential_utils.update_remote_control_status = function(driver, device, added)
local host_cnt = device:get_field(HOST_COUNT) or 0
if added then
if host_cnt == 0 then
device:emit_event(remoteControlStatus.remoteControlEnabled('true', { visibility = { displayed = false } }))
end
host_cnt = host_cnt + 1
else
if host_cnt > 0 then host_cnt = host_cnt - 1 end

if host_cnt == 0 then
device:emit_event(remoteControlStatus.remoteControlEnabled('false', { visibility = { displayed = false } }))
end
end

device:set_field(HOST_COUNT, host_cnt, { persist = true })
credential_utils.save_data(driver)
end

credential_utils.sync_all_credential_info = function(driver, device, command)
for _, credentialinfo in ipairs(command.args.credentialInfo) do
if credentialinfo.userType == "host" then
credential_utils.update_remote_control_status(driver, device, true)
end
end
device:emit_event(lockCredentialInfo.credentialInfo(command.args.credentialInfo, { visibility = { displayed = false } }))
credential_utils.save_data(driver)
end

credential_utils.upsert_credential_info = function(driver, device, command)
if #command.args.credentialInfo == 0 then
return
end

local credentialInfoTable = utils.deep_copy(device:get_latest_state("main", lockCredentialInfo.ID,
lockCredentialInfo.credentialInfo.NAME, {}))

for _, credentialinfo in ipairs(command.args.credentialInfo) do
local exist = false
for i = 1, #credentialInfoTable, 1 do
if credentialInfoTable[i].credentialId == credentialinfo.credentialId then
credentialInfoTable[i] = utils.deep_copy(credentialinfo)
exist = true
break
end
end

if exist == false then
if credentialinfo.userType == "host" then
credential_utils.update_remote_control_status(driver, device, true)
end

table.insert(credentialInfoTable, credentialinfo)
end
end

if credential_utils.is_exist_host(device) == false then
credential_utils.update_remote_control_status(driver, device, true)
end

device:emit_event(lockCredentialInfo.credentialInfo(credentialInfoTable, { visibility = { displayed = false } }))
credential_utils.save_data(driver)
end

credential_utils.delete_user = function(driver, device, command)
local credentialInfoTable = utils.deep_copy(device:get_latest_state("main", lockCredentialInfo.ID,
lockCredentialInfo.credentialInfo.NAME, {}))
if #credentialInfoTable == 0 then
return
end

local id = tostring(command.args.userId)

for i = #credentialInfoTable, 1, -1 do
if id == credentialInfoTable[i].userId then
if credentialInfoTable[i].userType == "host" then
credential_utils.update_remote_control_status(driver, device, false)
end
table.remove(credentialInfoTable, i)
end
end

device:emit_event(lockCredentialInfo.credentialInfo(credentialInfoTable, { visibility = { displayed = false } }))
credential_utils.save_data(driver)
end

credential_utils.delete_credential = function(driver, device, command)
local credentialInfoTable = utils.deep_copy(device:get_latest_state("main", lockCredentialInfo.ID,
lockCredentialInfo.credentialInfo.NAME, {}))
if #credentialInfoTable == 0 then
return
end

for i = #credentialInfoTable, 1, -1 do
if command.args.credentialId == credentialInfoTable[i].credentialId then
if credentialInfoTable[i].userType == "host" then
credential_utils.update_remote_control_status(driver, device, false)
end
table.remove(credentialInfoTable, i)
break
end
end

device:emit_event(lockCredentialInfo.credentialInfo(credentialInfoTable, { visibility = { displayed = false } }))
credential_utils.save_data(driver)
end

credential_utils.find_userLabel = function(driver, device, value)
local unlockCredentialId = value & 0xFFFF
local credentialInfoTable = utils.deep_copy(device:get_latest_state("main", lockCredentialInfo.ID,
lockCredentialInfo.credentialInfo.NAME, {}))
for _, credentialInfo in ipairs(credentialInfoTable) do
if credentialInfo.credentialId == unlockCredentialId then
return credentialInfo.userId, credentialInfo.userLabel
end
end
return nil, nil
end

credential_utils.is_exist_host = function(device)
local host_cnt = device:get_field(HOST_COUNT) or 0
return host_cnt > 0 and true or false
end

credential_utils.set_host_count = function(device, value)
device:set_field(HOST_COUNT, 0, { persist = true })
end

return credential_utils
Loading

0 comments on commit 37e5ce8

Please sign in to comment.