@homebridge-plugins/homebridge-govee 10.12.1

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 (78) hide show
  1. package/CHANGELOG.md +1937 -0
  2. package/LICENSE +21 -0
  3. package/README.md +72 -0
  4. package/config.schema.json +1727 -0
  5. package/eslint.config.js +49 -0
  6. package/lib/connection/aws.js +174 -0
  7. package/lib/connection/ble.js +208 -0
  8. package/lib/connection/cert/AmazonRootCA1.pem +20 -0
  9. package/lib/connection/http.js +240 -0
  10. package/lib/connection/lan.js +284 -0
  11. package/lib/device/cooler-single.js +300 -0
  12. package/lib/device/dehumidifier-H7150.js +182 -0
  13. package/lib/device/dehumidifier-H7151.js +157 -0
  14. package/lib/device/diffuser-H7161.js +117 -0
  15. package/lib/device/diffuser-H7162.js +117 -0
  16. package/lib/device/fan-H7100.js +274 -0
  17. package/lib/device/fan-H7101.js +330 -0
  18. package/lib/device/fan-H7102.js +274 -0
  19. package/lib/device/fan-H7105.js +503 -0
  20. package/lib/device/fan-H7106.js +274 -0
  21. package/lib/device/fan-H7111.js +335 -0
  22. package/lib/device/heater-single.js +300 -0
  23. package/lib/device/heater1a.js +353 -0
  24. package/lib/device/heater1b.js +616 -0
  25. package/lib/device/heater2.js +838 -0
  26. package/lib/device/humidifier-H7140.js +224 -0
  27. package/lib/device/humidifier-H7141.js +257 -0
  28. package/lib/device/humidifier-H7142.js +522 -0
  29. package/lib/device/humidifier-H7143.js +157 -0
  30. package/lib/device/humidifier-H7148.js +157 -0
  31. package/lib/device/humidifier-H7160.js +446 -0
  32. package/lib/device/ice-maker-H7162.js +46 -0
  33. package/lib/device/index.js +105 -0
  34. package/lib/device/kettle.js +269 -0
  35. package/lib/device/light-switch.js +86 -0
  36. package/lib/device/light.js +617 -0
  37. package/lib/device/outlet-double.js +121 -0
  38. package/lib/device/outlet-single.js +172 -0
  39. package/lib/device/outlet-triple.js +160 -0
  40. package/lib/device/purifier-H7120.js +336 -0
  41. package/lib/device/purifier-H7121.js +336 -0
  42. package/lib/device/purifier-H7122.js +449 -0
  43. package/lib/device/purifier-H7123.js +411 -0
  44. package/lib/device/purifier-H7124.js +411 -0
  45. package/lib/device/purifier-H7126.js +296 -0
  46. package/lib/device/purifier-H7127.js +296 -0
  47. package/lib/device/purifier-H712C.js +296 -0
  48. package/lib/device/purifier-single.js +119 -0
  49. package/lib/device/sensor-button.js +22 -0
  50. package/lib/device/sensor-contact.js +22 -0
  51. package/lib/device/sensor-leak.js +87 -0
  52. package/lib/device/sensor-monitor.js +190 -0
  53. package/lib/device/sensor-presence.js +53 -0
  54. package/lib/device/sensor-thermo.js +144 -0
  55. package/lib/device/sensor-thermo4.js +55 -0
  56. package/lib/device/switch-double.js +121 -0
  57. package/lib/device/switch-single.js +95 -0
  58. package/lib/device/switch-triple.js +160 -0
  59. package/lib/device/tap-single.js +108 -0
  60. package/lib/device/template.js +43 -0
  61. package/lib/device/tv-single.js +84 -0
  62. package/lib/device/valve-single.js +155 -0
  63. package/lib/fakegato/LICENSE +21 -0
  64. package/lib/fakegato/fakegato-history.js +814 -0
  65. package/lib/fakegato/fakegato-storage.js +108 -0
  66. package/lib/fakegato/fakegato-timer.js +125 -0
  67. package/lib/fakegato/uuid.js +27 -0
  68. package/lib/homebridge-ui/public/index.html +433 -0
  69. package/lib/homebridge-ui/server.js +10 -0
  70. package/lib/index.js +8 -0
  71. package/lib/platform.js +1967 -0
  72. package/lib/utils/colour.js +564 -0
  73. package/lib/utils/constants.js +579 -0
  74. package/lib/utils/custom-chars.js +225 -0
  75. package/lib/utils/eve-chars.js +68 -0
  76. package/lib/utils/functions.js +117 -0
  77. package/lib/utils/lang-en.js +131 -0
  78. package/package.json +75 -0
@@ -0,0 +1,155 @@
1
+ import { generateRandomString, parseError } from '../utils/functions.js'
2
+ import platformLang from '../utils/lang-en.js'
3
+
4
+ export default class {
5
+ constructor(platform, accessory) {
6
+ // Set up variables from the platform
7
+ this.hapChar = platform.api.hap.Characteristic
8
+ this.hapErr = platform.api.hap.HapStatusError
9
+ this.hapServ = platform.api.hap.Service
10
+ this.platform = platform
11
+
12
+ // Set up variables from the accessory
13
+ this.accessory = accessory;
14
+
15
+ // Remove any old services from simulations
16
+ ['AirPurifier', 'HeaterCooler', 'Lightbulb', 'Outlet', 'Switch'].forEach((service) => {
17
+ if (this.accessory.getService(this.hapServ[service])) {
18
+ this.accessory.removeService(this.accessory.getService(this.hapServ[service]))
19
+ }
20
+ })
21
+
22
+ // Make sure this wasn't setup as a valve
23
+ if (
24
+ this.accessory.getService(this.hapServ.Valve)
25
+ && this.accessory.context.valveType !== 'valve'
26
+ ) {
27
+ this.accessory.removeService(this.accessory.getService(this.hapServ.Valve))
28
+ }
29
+
30
+ // Add the tap service if it doesn't already exist
31
+ this.service = this.accessory.getService(this.hapServ.Valve)
32
+ if (!this.service) {
33
+ this.service = this.accessory.addService(this.hapServ.Valve)
34
+ this.service.updateCharacteristic(this.hapChar.Active, 0)
35
+ this.service.updateCharacteristic(this.hapChar.InUse, 0)
36
+ this.service.updateCharacteristic(this.hapChar.ValveType, 1)
37
+ this.service.updateCharacteristic(this.hapChar.SetDuration, 120)
38
+ this.service.addCharacteristic(this.hapChar.RemainingDuration)
39
+ this.accessory.context.valveType = 'valve'
40
+ }
41
+
42
+ // Add the set handler to the switch on/off characteristic
43
+ this.service.getCharacteristic(this.hapChar.Active).onSet(async (value) => {
44
+ await this.internalStateUpdate(value)
45
+ })
46
+
47
+ // Add the set handler to the valve set duration characteristic
48
+ this.service.getCharacteristic(this.hapChar.SetDuration).onSet((value) => {
49
+ // Check if the valve is currently active
50
+ if (this.service.getCharacteristic(this.hapChar.InUse).value === 1) {
51
+ // Update the remaining duration characteristic with the new value
52
+ this.service.updateCharacteristic(this.hapChar.RemainingDuration, value)
53
+
54
+ // Clear any existing active timers
55
+ clearTimeout(this.timer)
56
+
57
+ // Set a new active timer with the new time amount
58
+ this.timer = setTimeout(
59
+ () => this.service.setCharacteristic(this.hapChar.Active, 0),
60
+ value * 1000,
61
+ )
62
+ }
63
+ })
64
+
65
+ // Output the customised options to the log
66
+ const opts = JSON.stringify({
67
+ showAs: 'valve',
68
+ })
69
+ platform.log('[%s] %s %s.', accessory.displayName, platformLang.devInitOpts, opts)
70
+ }
71
+
72
+ async internalStateUpdate(value) {
73
+ try {
74
+ const newValue = value === 1 ? 'on' : 'off'
75
+
76
+ // Don't continue if the new value is the same as before
77
+ if (newValue === this.cacheState) {
78
+ return
79
+ }
80
+
81
+ // Set up a one-minute timeout for the plugin to ignore incoming updates
82
+ const timerKey = generateRandomString(5)
83
+ this.updateTimeout = timerKey
84
+ setTimeout(() => {
85
+ if (this.updateTimeout === timerKey) {
86
+ this.updateTimeout = false
87
+ }
88
+ }, 60000)
89
+
90
+ // Send the request to the platform sender function
91
+ await this.platform.sendDeviceUpdate(this.accessory, {
92
+ cmd: 'stateOutlet',
93
+ value: newValue,
94
+ })
95
+
96
+ // Cache the new state and log if appropriate
97
+ if (this.cacheState !== newValue) {
98
+ this.cacheState = newValue
99
+ this.accessory.log(`${platformLang.curState} [${this.cacheState}]`)
100
+ }
101
+
102
+ // Update the InUse characteristic
103
+ this.service.updateCharacteristic(this.hapChar.InUse, value)
104
+ switch (value) {
105
+ case 0:
106
+ this.service.updateCharacteristic(this.hapChar.RemainingDuration, 0)
107
+ clearTimeout(this.timer)
108
+ break
109
+ case 1: {
110
+ const timer = this.service.getCharacteristic(this.hapChar.SetDuration).value
111
+ this.service.updateCharacteristic(this.hapChar.RemainingDuration, timer)
112
+ this.timer = setTimeout(() => {
113
+ this.service.setCharacteristic(this.hapChar.Active, 0)
114
+ }, timer * 1000)
115
+ break
116
+ }
117
+ default:
118
+ }
119
+ } catch (err) {
120
+ // Catch any errors during the process
121
+ this.accessory.logWarn(`${platformLang.devNotUpdated} ${parseError(err)}`)
122
+
123
+ // Throw a 'no response' error and set a timeout to revert this after 2 seconds
124
+ setTimeout(() => {
125
+ this.service.updateCharacteristic(this.hapChar.Active, this.cacheState === 'on' ? 1 : 0)
126
+ }, 2000)
127
+ throw new this.hapErr(-70402)
128
+ }
129
+ }
130
+
131
+ externalUpdate(params) {
132
+ // Check to see if the provided state is different from the cached state
133
+ if (params.state && params.state !== this.cacheState) {
134
+ // State is different so update Homebridge with new values
135
+ this.cacheState = params.state
136
+ if (this.cacheState === 'on') {
137
+ if (this.service.getCharacteristic(this.hapChar.Active).value === 0) {
138
+ const timer = this.service.getCharacteristic(this.hapChar.SetDuration).value
139
+ this.service.updateCharacteristic(this.hapChar.Active, 1)
140
+ this.service.updateCharacteristic(this.hapChar.InUse, 1)
141
+ this.service.updateCharacteristic(this.hapChar.RemainingDuration, timer)
142
+ this.accessory.log(`${platformLang.curState} [${this.cacheState}]`)
143
+ this.timer = setTimeout(() => {
144
+ this.service.setCharacteristic(this.hapChar.Active, 0)
145
+ }, timer * 1000)
146
+ }
147
+ } else {
148
+ this.service.updateCharacteristic(this.hapChar.Active, 0)
149
+ this.service.updateCharacteristic(this.hapChar.InUse, 0)
150
+ this.service.updateCharacteristic(this.hapChar.RemainingDuration, 0)
151
+ clearTimeout(this.timer)
152
+ }
153
+ }
154
+ }
155
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 simont77
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.