Skip to content

Commit 6b578d3

Browse files
committed
Prep for more V2 API use, mobile app fixes, scene on/off events
Version 4.2 release
1 parent 4c3301f commit 6b578d3

13 files changed

+940
-836
lines changed

CoCoHue-Latest-Bundle.zip

1.37 KB
Binary file not shown.

apps/cocohue-app.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* =======================================================================================
2323
*
24-
* Last modified: 2024-06-30
24+
* Last modified: 2024-07-28
2525
*
2626
* Changelog:
2727
* v4.1.9 - Add note that Hue Labs features are now deprecated

drivers/cocohue-bridge-driver.groovy

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* ============================= CoCoHue Bridge (Driver) ===============================
33
*
4-
* Copyright 2019-2023 Robert Morris
4+
* Copyright 2019-2024 Robert Morris
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
77
* in compliance with the License. You may obtain a copy of the License at:
@@ -14,9 +14,11 @@
1414
*
1515
* =======================================================================================
1616
*
17-
* Last modified: 2023-01-30
17+
* Last modified: 2024-07-29
1818
*
1919
* Changelog:
20+
* v4.2.1 - Add scene on/off state reporting with v2 API
21+
* v4.2 - Improved eventstream reconnection logic
2022
* v4.1.4 - Improved error handling, fix missing battery for motion sensors
2123
* v4.1.3 - Improved eventstream data handling (when multiple devices included in same payload, thanks to @Modem-Tones)
2224
* v4.1.2 - Additional button enhancements (relative_rotary -- Hue Tap Dial, etc.)
@@ -47,6 +49,8 @@ import groovy.transform.Field
4749
// Seems to be helpful at the moment because get spurious disconnects when SSE is working fine, shortly followed
4850
// by a reconnect (~6 sec for me, so 7 should cover most)
4951
@Field static final Integer eventStreamDisconnectGracePeriod = 8
52+
// For readTimeout value in eventstream connection:
53+
@Field static final Integer eventStreamReadTimeout = 3600
5054

5155
@Field static final Integer debugAutoDisableMinutes = 30
5256

@@ -95,12 +99,13 @@ void connectEventStream() {
9599
if (enableDebug) {
96100
log.debug "Connecting to event stream at 'https://${data.ip}/eventstream/clip/v2' with key '${data.username}'"
97101
}
102+
interfaces.eventStream.close()
98103
interfaces.eventStream.connect(
99104
"https://${data.ip}/eventstream/clip/v2", [
100105
headers: ["Accept": "text/event-stream", "hue-application-key": data.username],
101106
rawData: true,
102107
pingInterval: 10,
103-
readTimeout: 3600,
108+
readTimeout: eventStreamReadTimeout,
104109
ignoreSSLIssues: true
105110
])
106111
}
@@ -127,9 +132,12 @@ void eventStreamStatus(String message) {
127132
if (message.startsWith("START:")) {
128133
setEventStreamStatusToConnected()
129134
}
130-
else {
135+
else if (message.startsWith("STOP:")) {
131136
runIn(eventStreamDisconnectGracePeriod, "setEventStreamStatusToDisconnected")
132137
}
138+
else {
139+
if (enableDebug) log.debug "Unhandled eventStreamStatus message: $message"
140+
}
133141
}
134142

135143
private void setEventStreamStatusToConnected() {
@@ -151,7 +159,7 @@ private void setEventStreamStatusToDisconnected() {
151159
else {
152160
state.connectionRetryTime = 5
153161
}
154-
if (enableDebug) log.debug "reconnecting SSE in ${state.connectionRetryTime}"
162+
if (enableDebug) log.debug "Reconnecting SSE in ${state.connectionRetryTime}"
155163
runIn(state.connectionRetryTime, "reconnectEventStream")
156164
}
157165

@@ -179,20 +187,25 @@ void parse(String description) {
179187
dataEntryMap.data?.each { updateEntryMap ->
180188
//log.trace "--> map = ${updateEntryMap}"
181189
String fullId = updateEntryMap.id_v1
190+
String hueId
182191
if (fullId != null) {
183192
switch (fullId) {
184193
case { it.startsWith("/lights/") }:
185-
String hueId = fullId.split("/")[-1]
194+
hueId = fullId.split("/")[-1]
186195
DeviceWrapper dev = parent.getChildDevice("${device.deviceNetworkId}/Light/${hueId}")
187196
if (dev != null) dev.createEventsFromSSE(updateEntryMap)
188197
break
189198
case { it.startsWith("/groups/") }:
190-
String hueId = fullId.split("/")[-1]
199+
hueId = fullId.split("/")[-1]
191200
DeviceWrapper dev = parent.getChildDevice("${device.deviceNetworkId}/Group/${hueId}")
192201
if (dev != null) dev.createEventsFromSSE(updateEntryMap)
193202
break
203+
case { it.startsWith("/scenes/") }:
204+
hueId = fullId.split("/")[-1]
205+
DeviceWrapper dev = parent.getChildDevice("${device.deviceNetworkId}/Scene/${hueId}")
206+
if (dev != null) dev.createEventsFromSSE(updateEntryMap)
194207
case { it.startsWith("/sensors/") }:
195-
String hueId = fullId.split("/")[-1]
208+
hueId = fullId.split("/")[-1]
196209
DeviceWrapper dev = parent.getChildDevices().find { DeviceWrapper dev ->
197210
hueId in dev.deviceNetworkId.tokenize('/')[-1].tokenize('|') &&
198211
dev.deviceNetworkId.startsWith("${device.deviceNetworkId}/Sensor/") // shouldn't be necessary but gave me a Light ID once in testing for a sensor, so?!
@@ -209,7 +222,7 @@ void parse(String description) {
209222
}
210223
break
211224
default:
212-
if (enableDebug) log.debug "skipping Hue v1 ID: $hueId"
225+
if (enableDebug) log.debug "skipping Hue v1 ID: $fullId"
213226
}
214227
}
215228
}
@@ -743,7 +756,7 @@ void clearLabsSensorsCache() {
743756
if (enableDebug) log.debug "Running clearLabsSensorsCache..."
744757
state.remove("labsSensors")
745758
}
746-
// ~~~~~ start include (2) RMoRobert.CoCoHue_Common_Lib ~~~~~
759+
// ~~~~~ start include (8) RMoRobert.CoCoHue_Common_Lib ~~~~~
747760
// Version 1.0.2 // library marker RMoRobert.CoCoHue_Common_Lib, line 1
748761

749762
// 1.0.2 - HTTP error handling tweaks // library marker RMoRobert.CoCoHue_Common_Lib, line 3
@@ -817,4 +830,4 @@ void doSendEvent(String eventName, eventValue, String eventUnit=null, Boolean fo
817830
} // library marker RMoRobert.CoCoHue_Common_Lib, line 71
818831
} // library marker RMoRobert.CoCoHue_Common_Lib, line 72
819832

820-
// ~~~~~ end include (2) RMoRobert.CoCoHue_Common_Lib ~~~~~
833+
// ~~~~~ end include (8) RMoRobert.CoCoHue_Common_Lib ~~~~~

drivers/cocohue-button-driver.groovy

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* ============================= CoCoHue Button (Driver) ===============================
33
*
4-
* Copyright 2022-2023 Robert Morris
4+
* Copyright 2022-2024 Robert Morris
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
77
* in compliance with the License. You may obtain a copy of the License at:
@@ -13,10 +13,11 @@
1313
* for the specific language governing permissions and limitations under the License.
1414
*
1515
* =======================================================================================
16-
*
17-
* Last modified: 2024-03-02
16+
17+
* Last modified: 2024-07-29
1818
*
1919
* Changelog:
20+
* v4.2 - Library updates, prep for more v2 API
2021
* v4.1.5 - Improve button command compatibility
2122
* v4.1.4 - Improved HTTP error handling
2223
* v4.1.2 - Add relative_rotary support (Hue Tap Dial, etc.)
@@ -141,6 +142,9 @@ void createEventsFromSSE(Map data) {
141142
case "long_release":
142143
eventName = "released"
143144
break
145+
case "id_v1":
146+
if (state.id_v1 != value) state.id_v1 = value
147+
break
144148
default:
145149
if (enableDebug == true) log.debug "No button event created from: ${data.button.last_event}"
146150
break
@@ -186,7 +190,7 @@ void setButtons(Map<String,Integer> buttons, List<String> relativeRotaries=null)
186190
doSendEvent("numberOfButtons", numButtons)
187191
}
188192

189-
// ~~~~~ start include (2) RMoRobert.CoCoHue_Common_Lib ~~~~~
193+
// ~~~~~ start include (8) RMoRobert.CoCoHue_Common_Lib ~~~~~
190194
// Version 1.0.2 // library marker RMoRobert.CoCoHue_Common_Lib, line 1
191195

192196
// 1.0.2 - HTTP error handling tweaks // library marker RMoRobert.CoCoHue_Common_Lib, line 3
@@ -260,4 +264,4 @@ void doSendEvent(String eventName, eventValue, String eventUnit=null, Boolean fo
260264
} // library marker RMoRobert.CoCoHue_Common_Lib, line 71
261265
} // library marker RMoRobert.CoCoHue_Common_Lib, line 72
262266

263-
// ~~~~~ end include (2) RMoRobert.CoCoHue_Common_Lib ~~~~~
267+
// ~~~~~ end include (8) RMoRobert.CoCoHue_Common_Lib ~~~~~

0 commit comments

Comments
 (0)