Skip to content

Commit

Permalink
support switches and buttons in the new Konnected Alarm Panel driver
Browse files Browse the repository at this point in the history
  • Loading branch information
heythisisnate committed Nov 1, 2024
1 parent 31b0538 commit c5c66a0
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
cp bundles/alarm-panel.txt AlarmPanel/install.txt
cp bundles/alarm-panel.txt AlarmPanel/update.txt
cp drivers/konnected-alarm-panel.groovy AlarmPanel/konnected.KonnectedAlarmPanel.groovy
cp drivers/konnected-button-trigger.groovy AlarmPanel/konnected.KonnectedButtonTrigger.groovy
wget -O AlarmPanel/esphome.espHomeApiHelper.groovy https://raw.githubusercontent.com/konnected-io/hubitat-public/refs/heads/main/ESPHome/ESPHome-API-Library.groovy
- name: Zip EspHomeApiHelper
Expand Down
1 change: 1 addition & 0 deletions bundles/alarm-panel.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
konnected
Alarm Panel
library esphome.espHomeApiHelper.groovy
driver konnected.KonnectedButtonTrigger.groovy
driver konnected.KonnectedAlarmPanel.groovy
60 changes: 54 additions & 6 deletions drivers/konnected-alarm-panel.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ public void refresh() {
espHomeDeviceInfoRequest()
}

public void componentOn(cd) {
if (logTextEnable) { log.info "${cd.displayName} switch on" }
Long key = cd.deviceNetworkId.split('-')[1] as Long
espHomeSwitchCommand(key: key, state: 1)
}

public void componentOff(cd) {
if (logTextEnable) { log.info "${cd.displayName} switch off" }
Long key = cd.deviceNetworkId.split('-')[1] as Long
espHomeSwitchCommand(key: key, state: 0)
}

public void componentRefresh(cd) {
// not implemented
}

public void componentPush(cd) {
if (logTextEnable) { log.info "${cd.displayName} pushed" }
Long key = cd.deviceNetworkId.split('-')[1] as Long
espHomeButtonCommand(key: key)
}

// the parse method is invoked by the API library when messages are received
public void parse(Map message) {
if (logEnable) { log.debug "ESPHome received: ${message}" }
Expand Down Expand Up @@ -157,39 +179,60 @@ private void doParseEntity(Map message) {
return
}

if (message.platform == 'switch') {
deviceType = "Switch"
getOrCreateDevice(message.key as Long, deviceType, message.name)
return
}

if (message.platform == 'button') {
deviceType = "Konnected Button Trigger"
getOrCreateDevice(message.key as Long, deviceType, message.name)
return
}

}

private void doParseState(Map message) {
if (!message.key) { return }

// update the state of a child device that matches the key
def childDevice = getChildDevice("${device.id}-${message.key}")
if (childDevice && message.hasState) {
if (childDevice) {
String attr = childDevice.getSupportedAttributes().first()
String value
String description

switch (attr) {
case 'contact':
if (!message.hasState) { return }
value = message.state ? 'open' : 'closed'
description = 'Contact'
break
case 'motion':
if (!message.hasState) { return }
value = message.state ? 'active' : 'inactive'
description = 'Motion'
break
case 'smoke':
if (!message.hasState) { return }
value = message.state ? 'detected' : 'clear'
description = 'Smoke'
break
case 'carbonMonoxide':
if (!message.hasState) { return }
value = message.state ? 'detected' : 'clear'
description = 'Carbon Monoxide'
break
case 'sound':
if (!message.hasState) { return }
value = message.state ? 'detected' : 'not detected'
description = 'Sound'
break
case 'switch':
value = message.state ? 'on' : 'off'
description = 'Switch'
break
}
if (!value) { return }
sendDeviceEvent(attr, value, type, description, childDevice, attr)
Expand Down Expand Up @@ -240,13 +283,18 @@ private DeviceWrapper getOrCreateDevice(key, deviceType, label = null) {
return null
}
String dni = "${device.id}-${key}" as String
String childDeviceType
String childDeviceNamespace
def d = getChildDevice(dni)
if (!d) {
d = addChildDevice(
"hubitat",
"Generic Component ${deviceType}",
dni
)
if (deviceType.startsWith('Konnected')) {
childDeviceType = deviceType
childDeviceNamespace = 'konnected'
} else {
childDeviceType = "Generic Component ${deviceType}"
childDeviceNamespace = 'hubitat'
}
d = addChildDevice(childDeviceNamespace, childDeviceType, dni)
d.name = label?:deviceType
d.label = label?:deviceType
}
Expand Down
13 changes: 10 additions & 3 deletions package-alarm-panel.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"packageName": "Alarm Panel (universal)",
"author": "Konnected Inc.",
"version": "0.1",
"version": "0.2",
"minimumHEVersion": "0.0",
"dateReleased": "2024-09-27",
"bundles": [
Expand All @@ -16,10 +16,17 @@
"drivers": [
{
"id": "353b5525-8943-4a2c-9f1b-e51c5265ce33",
"name": "",
"namespace": "",
"name": "Konnected Alarm Panel",
"namespace": "konnected",
"location": "https://raw.githubusercontent.com/konnected-io/konnected-hubitat/master/drivers/konnected-alarm-panel.groovy",
"required": true
},
{
"id": "00d197f9-42cb-4a8c-b3d3-1257413e520c",
"name": "Konnected Button Trigger",
"namespace": "konnected",
"location": "https://raw.githubusercontent.com/konnected-io/konnected-hubitat/master/drivers/konnected-button-trigger.groovy",
"required": true
}
]
}

0 comments on commit c5c66a0

Please sign in to comment.