Skip to content
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

Added matter component lock driver #8

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
126 changes: 126 additions & 0 deletions Components/Matter_Generic_Component_Door_Lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/* groovylint-disable CompileStatic, DuplicateStringLiteral, LineLength, PublicMethodsBeforeNonPublicMethods */
/*
* 'Matter Generic Component Door Lock' - component driver for Matter Advanced Bridge
*
* https://community.hubitat.com/t/dynamic-capabilities-commands-and-attributes-for-drivers/98342
* https://community.hubitat.com/t/project-zemismart-m1-matter-bridge-for-tuya-zigbee-devices-matter/127009
*
* Licensed Virtual the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
* ver. 1.0.0 2024-03-16 kkossev - first release
*
*/

import groovy.transform.Field

@Field static final String matterComponentSwitchVersion = '1.0.0'
@Field static final String matterComponentSwitchStamp = '2024/03/16 9:26 AM'

metadata {
definition(name: 'Matter Generic Component Door Lock', namespace: 'kkossev', author: 'Daniel Segall', importUrl: 'https://raw.githubusercontent.com/kkossev/Hubitat---Matter-Advanced-Bridge/main/Components/Matter_Generic_Component_Switch.groovy') {
capability 'Lock'
capability 'Refresh'
}
}

preferences {
section {
input name: 'logEnable',
type: 'bool',
title: 'Enable debug logging',
required: false,
defaultValue: true

input name: 'txtEnable',
type: 'bool',
title: 'Enable descriptionText logging',
required: false,
defaultValue: true
}
}

/* groovylint-disable-next-line UnusedMethodParameter */
void parse(String description) { log.warn 'parse(String description) not implemented' }

// parse commands from parent
void parse(List<Map> description) {
//if (logEnable) { log.debug "${description}" }
description.each { d ->
if (d.name == 'lock') {
if (device.currentValue('lock') != d.value) {
if (d.descriptionText && txtEnable) { log.info "${d.descriptionText} (value changed)" }
sendEvent(d)
}
else {
if (logEnable) { log.debug "${device.displayName} : ignored switch event '${d.value}' (no change)" }
}
}
else {
if (d.descriptionText && txtEnable) { log.info "${d.descriptionText}" }
sendEvent(d)
}
}
}

// Component command to lock device
void lock() {
if (logEnable) { log.debug "${device.displayName} locking ..." }
parent?.componentLock(device)
}

// Component command to unlock device
void unlock() {
if (logEnable) { log.debug "${device.displayName} unlocking ..." }
parent?.componentUnlock(device)
}

// Component command to ping the device
void ping() {
parent?.componentPing(device)
}

// Called when the device is first created
void installed() {
log.info "${device.displayName} driver installed"
}

// Called when the device is removed
void uninstalled() {
log.info "${device.displayName} driver uninstalled"
}

// Called when the settings are updated
void updated() {
log.info "${device.displayName} driver configuration updated"
if (logEnable) {
log.debug settings
runIn(86400, 'logsOff')
}
}

/* groovylint-disable-next-line UnusedPrivateMethod */
private void logsOff() {
log.warn "debug logging disabled for ${device.displayName} "
device.updateSetting('logEnable', [value: 'false', type: 'bool'] )
}

void refresh() {
parent?.componentRefresh(this.device)
}

void setState(String stateName, String stateValue) {
if (logEnable) { log.debug "${device.displayName} setting state '${stateName}' to '${stateValue}'" }
state[stateName] = stateValue
}

String getState(String stateName) {
if (logEnable) { log.debug "${device.displayName} getting state '${stateName}'" }
return state[stateName]
}
2 changes: 1 addition & 1 deletion Matter_Advanced_Bridge.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,7 @@ Map mapTuyaCategory(Map d) {
return [ namespace: 'kkossev', driver: 'Matter Generic Component Motion Sensor', product_name: 'Motion Sensor' ]
}
if ('0101' in d.ServerList) { // Door Lock
return [driver: 'Generic Component Lock', product_name: 'Door Lock' ]
return [ namespace: 'kkossev', driver: 'Matter Generic Component Door Lock', product_name: 'Door Lock' ]
}
if ('0102' in d.ServerList) { // Curtain Motor (uses custom driver)
return [ namespace: 'kkossev', driver: 'Matter Generic Component Window Shade', product_name: 'Curtain Motor' ]
Expand Down