node-red-contrib-knx-ultimate 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/KNXEngine/dptlib/index.js +1 -1
  3. package/KNXUltimate.code-workspace +11 -1
  4. package/README.md +1 -1
  5. package/img/hue.png +0 -0
  6. package/img/hueButton.png +0 -0
  7. package/img/hueLight.png +0 -0
  8. package/img/knx.png +0 -0
  9. package/nodes/hue-config.js +20 -6
  10. package/nodes/knxUltimateHueButton.html +586 -0
  11. package/nodes/knxUltimateHueButton.js +159 -0
  12. package/nodes/knxUltimateHueLight.html +363 -55
  13. package/nodes/knxUltimateHueLight.js +70 -13
  14. package/nodes/locales/en-US/knxUltimateHueLight.json +3 -3
  15. package/nodes/utils/hueColorConverter.js +237 -0
  16. package/nodes/utils/hueUtils.js +37 -21
  17. package/package.json +6 -4
  18. package/nodes/locales/en-US/knxUltimateHueLight.html +0 -10
  19. /package/nodes/locales/{de → de-disabled}/hue-config.html +0 -0
  20. /package/nodes/locales/{de → de-disabled}/hue-config.json +0 -0
  21. /package/nodes/locales/{de → de-disabled}/knxUltimate-config.html +0 -0
  22. /package/nodes/locales/{de → de-disabled}/knxUltimate-config.json +0 -0
  23. /package/nodes/locales/{de → de-disabled}/knxUltimate.html +0 -0
  24. /package/nodes/locales/{de → de-disabled}/knxUltimate.json +0 -0
  25. /package/nodes/locales/{de → de-disabled}/knxUltimateAlerter.html +0 -0
  26. /package/nodes/locales/{de → de-disabled}/knxUltimateAlerter.json +0 -0
  27. /package/nodes/locales/{de → de-disabled}/knxUltimateGlobalContext.html +0 -0
  28. /package/nodes/locales/{de → de-disabled}/knxUltimateGlobalContext.json +0 -0
  29. /package/nodes/locales/{de → de-disabled}/knxUltimateHueLight.html +0 -0
  30. /package/nodes/locales/{de → de-disabled}/knxUltimateHueLight.json +0 -0
  31. /package/nodes/locales/{de → de-disabled}/knxUltimateLoadControl.html +0 -0
  32. /package/nodes/locales/{de → de-disabled}/knxUltimateLoadControl.json +0 -0
  33. /package/nodes/locales/{de → de-disabled}/knxUltimateLogger.html +0 -0
  34. /package/nodes/locales/{de → de-disabled}/knxUltimateLogger.json +0 -0
  35. /package/nodes/locales/{de → de-disabled}/knxUltimateSceneController.html +0 -0
  36. /package/nodes/locales/{de → de-disabled}/knxUltimateSceneController.json +0 -0
  37. /package/nodes/locales/{de → de-disabled}/knxUltimateViewer.html +0 -0
  38. /package/nodes/locales/{de → de-disabled}/knxUltimateViewer.json +0 -0
  39. /package/nodes/locales/{de → de-disabled}/knxUltimateWatchDog.html +0 -0
  40. /package/nodes/locales/{de → de-disabled}/knxUltimateWatchDog.json +0 -0
@@ -0,0 +1,159 @@
1
+ module.exports = function (RED) {
2
+ const dptlib = require('./../KNXEngine/dptlib')
3
+ const hueColorConverter = require('./utils/hueColorConverter')
4
+
5
+
6
+ async function getLightState(node, _lightID) {
7
+ return new Promise((resolve, reject) => {
8
+ try {
9
+ if (node !== null && node.serverHue !== null && node.serverHue.hueManager !== null) {
10
+ node.serverHue.hueManager.getLight(_lightID).then(ret => {
11
+ node.currentHUEDevice = ret[0]
12
+ resolve(ret)
13
+ })
14
+ }
15
+ } catch (error) {
16
+ reject(error)
17
+ }
18
+ })
19
+ }
20
+
21
+ function knxUltimateHueButton(config) {
22
+ RED.nodes.createNode(this, config)
23
+ const node = this
24
+ node.server = RED.nodes.getNode(config.server)
25
+ node.serverHue = RED.nodes.getNode(config.serverHue)
26
+ node.topic = node.name
27
+ node.name = config.name === undefined ? 'Hue' : config.name
28
+ node.outputtopic = node.name
29
+ node.dpt = ''
30
+ node.notifyreadrequest = false
31
+ node.notifyreadrequestalsorespondtobus = 'false'
32
+ node.notifyreadrequestalsorespondtobusdefaultvalueifnotinitialized = ''
33
+ node.notifyresponse = false
34
+ node.notifywrite = true
35
+ node.initialread = true
36
+ node.listenallga = true // Don't remove
37
+ node.outputtype = 'write'
38
+ node.outputRBE = false // Apply or not RBE to the output (Messages coming from flow)
39
+ node.inputRBE = false // Apply or not RBE to the input (Messages coming from BUS)
40
+ node.currentPayload = '' // Current value for the RBE input and for the .previouspayload msg
41
+ node.passthrough = 'no'
42
+ node.formatmultiplyvalue = 1
43
+ node.formatnegativevalue = 'leave'
44
+ node.formatdecimalsvalue = 2
45
+ node.toggle1 = false
46
+ node.toggle2 = false // up or down if repeat field is set to DIM
47
+ node.toggle3 = false
48
+ node.toggle4 = false
49
+ node.toggle4 = false
50
+ node.toggle5 = false
51
+ node.toggle5 = false
52
+
53
+
54
+ // Read the state of the light and store it in the holding object
55
+ try {
56
+ if (config.hueLight !== undefined && config.hueLight !== '') getLightState(node, config.hueLight)
57
+ } catch (error) {
58
+ }
59
+
60
+
61
+
62
+ // Used to call the status update from the config node.
63
+ node.setNodeStatus = ({ fill, shape, text, payload }) => {
64
+
65
+ }
66
+
67
+ // This function is called by the knx-ultimate config node, to output a msg.payload.
68
+ node.handleSend = msg => {
69
+ }
70
+
71
+ node.handleSendHUE = _event => {
72
+ try {
73
+ if (_event.id === config.hueDevice) {
74
+ const knxMsgPayload = {}
75
+ if (_event.button.last_event === 'initial_press') {
76
+ knxMsgPayload.ga = config.GAinitial_press
77
+ knxMsgPayload.dpt = config.dptinitial_press
78
+ config.toggleValues ? node.toggle1 = !node.toggle1 : node.toggle1 = true
79
+ knxMsgPayload.payload = node.toggle1
80
+ // Toggle the DIM direction
81
+ config.toggleValues ? node.toggle2 = !node.toggle2 : node.toggle2 = true
82
+ }
83
+ if (_event.button.last_event === 'repeat') {
84
+ knxMsgPayload.ga = config.GArepeat
85
+ knxMsgPayload.dpt = config.dptrepeat
86
+ // True/False or DIM
87
+ if (knxMsgPayload.dpt.startsWith('1.')) {
88
+ config.toggleValues ? node.toggle2 = !node.toggle2 : node.toggle2 = true
89
+ knxMsgPayload.payload = node.toggle2
90
+ }
91
+ if (knxMsgPayload.dpt.startsWith('3.007')) {
92
+ if (!config.toggleValues) node.toggle2 = true
93
+ knxMsgPayload.payload = node.toggle2 ? { decr_incr: 1, data: 5 } : { decr_incr: 0, data: 5 }
94
+ }
95
+ }
96
+ if (_event.button.last_event === 'short_release') {
97
+ knxMsgPayload.ga = config.GAshort_release
98
+ knxMsgPayload.dpt = config.dptshort_release
99
+ config.toggleValues ? node.toggle3 = !node.toggle3 : node.toggle3 = true
100
+ knxMsgPayload.payload = node.toggle3
101
+ }
102
+ if (_event.button.last_event === 'long_release') {
103
+ knxMsgPayload.ga = config.GAlong_release
104
+ knxMsgPayload.dpt = config.dptlong_release
105
+ config.toggleValues ? node.toggle4 = !node.toggle4 : node.toggle4 = true
106
+ knxMsgPayload.payload = node.toggle4
107
+ }
108
+ if (_event.button.last_event === 'double_short_release') {
109
+ knxMsgPayload.ga = config.GAdouble_short_release
110
+ knxMsgPayload.dpt = config.dptdouble_short_release
111
+ config.toggleValues ? node.toggle5 = !node.toggle5 : node.toggle5 = true
112
+ knxMsgPayload.payload = node.toggle5
113
+ }
114
+ if (_event.button.last_event === 'long_press') {
115
+ knxMsgPayload.ga = config.GAlong_press
116
+ knxMsgPayload.dpt = config.dptlong_press
117
+ config.toggleValues ? node.toggle6 = !node.toggle6 : node.toggle6 = true
118
+ knxMsgPayload.payload = node.toggle6
119
+ }
120
+ // Send to KNX bus
121
+ if (knxMsgPayload.ga !== undefined) {
122
+ node.status({ fill: 'green', shape: 'dot', text: 'HUE->KNX ' + _event.button.last_event + ' ' + JSON.stringify(knxMsgPayload.payload) + ' (' + new Date().getDate() + ', ' + new Date().toLocaleTimeString() + ')' })
123
+ if (knxMsgPayload.ga !== '' && knxMsgPayload.ga !== undefined) node.server.writeQueueAdd({ grpaddr: knxMsgPayload.ga, payload: knxMsgPayload.payload, dpt: knxMsgPayload.dpt, outputtype: 'write', nodecallerid: node.id })
124
+ }
125
+ }
126
+ } catch (error) {
127
+ node.status({ fill: 'red', shape: 'dot', text: 'HUE->KNX error ' + error.message + ' (' + new Date().getDate() + ', ' + new Date().toLocaleTimeString() + ')' })
128
+ }
129
+ }
130
+
131
+ // On each deploy, unsubscribe+resubscribe
132
+ if (node.server) {
133
+ node.server.removeClient(node)
134
+ node.server.addClient(node)
135
+ }
136
+ if (node.serverHue) {
137
+ node.serverHue.removeClient(node)
138
+ node.serverHue.addClient(node)
139
+ }
140
+
141
+ node.on('input', function (msg) {
142
+
143
+ })
144
+
145
+ node.on('close', function (done) {
146
+ if (node.server) {
147
+ node.server.removeClient(node)
148
+ }
149
+ done()
150
+ })
151
+
152
+ // On each deploy, unsubscribe+resubscribe
153
+ if (node.server) {
154
+ node.server.removeClient(node)
155
+ node.server.addClient(node)
156
+ }
157
+ }
158
+ RED.nodes.registerType('knxUltimateHueButton', knxUltimateHueButton)
159
+ }