diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8403d53..7f64b61 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/bundles/alarm-panel.txt b/bundles/alarm-panel.txt index 664275a..3b2d32a 100644 --- a/bundles/alarm-panel.txt +++ b/bundles/alarm-panel.txt @@ -1,4 +1,5 @@ konnected Alarm Panel library esphome.espHomeApiHelper.groovy +driver konnected.KonnectedButtonTrigger.groovy driver konnected.KonnectedAlarmPanel.groovy \ No newline at end of file diff --git a/drivers/konnected-alarm-panel.groovy b/drivers/konnected-alarm-panel.groovy index 63c073e..0ed1706 100644 --- a/drivers/konnected-alarm-panel.groovy +++ b/drivers/konnected-alarm-panel.groovy @@ -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}" } @@ -157,6 +179,18 @@ 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) { @@ -164,32 +198,41 @@ private void doParseState(Map message) { // 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) @@ -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 } diff --git a/package-alarm-panel.json b/package-alarm-panel.json index 259b6dc..c49d724 100644 --- a/package-alarm-panel.json +++ b/package-alarm-panel.json @@ -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": [ @@ -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 } ] } \ No newline at end of file