@mp-consulting/homebridge-lg-thinq 1.0.0

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 (241) hide show
  1. package/.claude/settings.local.json +15 -0
  2. package/CHANGELOG.md +98 -0
  3. package/LICENSE +176 -0
  4. package/README.md +114 -0
  5. package/config.schema.json +399 -0
  6. package/dist/__tests__/baseDevice.spec.d.ts +1 -0
  7. package/dist/__tests__/baseDevice.spec.js +96 -0
  8. package/dist/__tests__/baseDevice.spec.js.map +1 -0
  9. package/dist/__tests__/deviceControl.coercion.spec.d.ts +1 -0
  10. package/dist/__tests__/deviceControl.coercion.spec.js +53 -0
  11. package/dist/__tests__/deviceControl.coercion.spec.js.map +1 -0
  12. package/dist/__tests__/helper.spec.d.ts +1 -0
  13. package/dist/__tests__/helper.spec.js +74 -0
  14. package/dist/__tests__/helper.spec.js.map +1 -0
  15. package/dist/baseDevice.d.ts +40 -0
  16. package/dist/baseDevice.js +85 -0
  17. package/dist/baseDevice.js.map +1 -0
  18. package/dist/baseDevice.spec.d.ts +1 -0
  19. package/dist/baseDevice.spec.js +107 -0
  20. package/dist/baseDevice.spec.js.map +1 -0
  21. package/dist/characteristics/TotalConsumption.d.ts +2 -0
  22. package/dist/characteristics/TotalConsumption.js +17 -0
  23. package/dist/characteristics/TotalConsumption.js.map +1 -0
  24. package/dist/characteristics/index.d.ts +2 -0
  25. package/dist/characteristics/index.js +7 -0
  26. package/dist/characteristics/index.js.map +1 -0
  27. package/dist/cli.d.ts +2 -0
  28. package/dist/cli.js +89 -0
  29. package/dist/cli.js.map +1 -0
  30. package/dist/devices/AeroTower.d.ts +24 -0
  31. package/dist/devices/AeroTower.js +113 -0
  32. package/dist/devices/AeroTower.js.map +1 -0
  33. package/dist/devices/AirConditioner.d.ts +425 -0
  34. package/dist/devices/AirConditioner.js +1253 -0
  35. package/dist/devices/AirConditioner.js.map +1 -0
  36. package/dist/devices/AirPurifier.d.ts +50 -0
  37. package/dist/devices/AirPurifier.js +281 -0
  38. package/dist/devices/AirPurifier.js.map +1 -0
  39. package/dist/devices/Dehumidifier.d.ts +28 -0
  40. package/dist/devices/Dehumidifier.js +175 -0
  41. package/dist/devices/Dehumidifier.js.map +1 -0
  42. package/dist/devices/Dishwasher.d.ts +64 -0
  43. package/dist/devices/Dishwasher.js +740 -0
  44. package/dist/devices/Dishwasher.js.map +1 -0
  45. package/dist/devices/Microwave.d.ts +128 -0
  46. package/dist/devices/Microwave.js +1939 -0
  47. package/dist/devices/Microwave.js.map +1 -0
  48. package/dist/devices/Oven.d.ts +148 -0
  49. package/dist/devices/Oven.js +1850 -0
  50. package/dist/devices/Oven.js.map +1 -0
  51. package/dist/devices/RangeHood.d.ts +16 -0
  52. package/dist/devices/RangeHood.js +99 -0
  53. package/dist/devices/RangeHood.js.map +1 -0
  54. package/dist/devices/Refrigerator.d.ts +50 -0
  55. package/dist/devices/Refrigerator.js +325 -0
  56. package/dist/devices/Refrigerator.js.map +1 -0
  57. package/dist/devices/Styler.d.ts +27 -0
  58. package/dist/devices/Styler.js +76 -0
  59. package/dist/devices/Styler.js.map +1 -0
  60. package/dist/devices/WasherDryer.d.ts +39 -0
  61. package/dist/devices/WasherDryer.js +170 -0
  62. package/dist/devices/WasherDryer.js.map +1 -0
  63. package/dist/devices/WasherDryer2.d.ts +9 -0
  64. package/dist/devices/WasherDryer2.js +16 -0
  65. package/dist/devices/WasherDryer2.js.map +1 -0
  66. package/dist/errors/AuthenticationError.d.ts +2 -0
  67. package/dist/errors/AuthenticationError.js +3 -0
  68. package/dist/errors/AuthenticationError.js.map +1 -0
  69. package/dist/errors/ManualProcessNeeded.d.ts +3 -0
  70. package/dist/errors/ManualProcessNeeded.js +4 -0
  71. package/dist/errors/ManualProcessNeeded.js.map +1 -0
  72. package/dist/errors/MonitorError.d.ts +2 -0
  73. package/dist/errors/MonitorError.js +3 -0
  74. package/dist/errors/MonitorError.js.map +1 -0
  75. package/dist/errors/NotConnectedError.d.ts +3 -0
  76. package/dist/errors/NotConnectedError.js +4 -0
  77. package/dist/errors/NotConnectedError.js.map +1 -0
  78. package/dist/errors/TokenError.d.ts +2 -0
  79. package/dist/errors/TokenError.js +3 -0
  80. package/dist/errors/TokenError.js.map +1 -0
  81. package/dist/errors/TokenExpiredError.d.ts +3 -0
  82. package/dist/errors/TokenExpiredError.js +4 -0
  83. package/dist/errors/TokenExpiredError.js.map +1 -0
  84. package/dist/errors/index.d.ts +6 -0
  85. package/dist/errors/index.js +7 -0
  86. package/dist/errors/index.js.map +1 -0
  87. package/dist/helper.d.ts +24 -0
  88. package/dist/helper.js +66 -0
  89. package/dist/helper.js.map +1 -0
  90. package/dist/helper.spec.d.ts +1 -0
  91. package/dist/helper.spec.js +74 -0
  92. package/dist/helper.spec.js.map +1 -0
  93. package/dist/index.d.ts +6 -0
  94. package/dist/index.js +9 -0
  95. package/dist/index.js.map +1 -0
  96. package/dist/lib/API.d.ts +141 -0
  97. package/dist/lib/API.js +362 -0
  98. package/dist/lib/API.js.map +1 -0
  99. package/dist/lib/API.spec.d.ts +1 -0
  100. package/dist/lib/API.spec.js +55 -0
  101. package/dist/lib/API.spec.js.map +1 -0
  102. package/dist/lib/Auth.d.ts +99 -0
  103. package/dist/lib/Auth.js +348 -0
  104. package/dist/lib/Auth.js.map +1 -0
  105. package/dist/lib/Auth.spec.d.ts +1 -0
  106. package/dist/lib/Auth.spec.js +111 -0
  107. package/dist/lib/Auth.spec.js.map +1 -0
  108. package/dist/lib/Device.d.ts +88 -0
  109. package/dist/lib/Device.js +95 -0
  110. package/dist/lib/Device.js.map +1 -0
  111. package/dist/lib/Device.spec.d.ts +1 -0
  112. package/dist/lib/Device.spec.js +53 -0
  113. package/dist/lib/Device.spec.js.map +1 -0
  114. package/dist/lib/DeviceModel.d.ts +164 -0
  115. package/dist/lib/DeviceModel.js +321 -0
  116. package/dist/lib/DeviceModel.js.map +1 -0
  117. package/dist/lib/DeviceModel.spec.d.ts +1 -0
  118. package/dist/lib/DeviceModel.spec.js +90 -0
  119. package/dist/lib/DeviceModel.spec.js.map +1 -0
  120. package/dist/lib/Gateway.d.ts +18 -0
  121. package/dist/lib/Gateway.js +25 -0
  122. package/dist/lib/Gateway.js.map +1 -0
  123. package/dist/lib/Gateway.spec.d.ts +1 -0
  124. package/dist/lib/Gateway.spec.js +35 -0
  125. package/dist/lib/Gateway.spec.js.map +1 -0
  126. package/dist/lib/Persist.d.ts +101 -0
  127. package/dist/lib/Persist.js +245 -0
  128. package/dist/lib/Persist.js.map +1 -0
  129. package/dist/lib/Persist.spec.d.ts +1 -0
  130. package/dist/lib/Persist.spec.js +90 -0
  131. package/dist/lib/Persist.spec.js.map +1 -0
  132. package/dist/lib/Session.d.ts +80 -0
  133. package/dist/lib/Session.js +100 -0
  134. package/dist/lib/Session.js.map +1 -0
  135. package/dist/lib/Session.spec.d.ts +1 -0
  136. package/dist/lib/Session.spec.js +43 -0
  137. package/dist/lib/Session.spec.js.map +1 -0
  138. package/dist/lib/ThinQ.d.ts +28 -0
  139. package/dist/lib/ThinQ.js +373 -0
  140. package/dist/lib/ThinQ.js.map +1 -0
  141. package/dist/lib/__tests__/API.spec.d.ts +1 -0
  142. package/dist/lib/__tests__/API.spec.js +55 -0
  143. package/dist/lib/__tests__/API.spec.js.map +1 -0
  144. package/dist/lib/__tests__/Auth.spec.d.ts +1 -0
  145. package/dist/lib/__tests__/Auth.spec.js +110 -0
  146. package/dist/lib/__tests__/Auth.spec.js.map +1 -0
  147. package/dist/lib/__tests__/Device.spec.d.ts +1 -0
  148. package/dist/lib/__tests__/Device.spec.js +53 -0
  149. package/dist/lib/__tests__/Device.spec.js.map +1 -0
  150. package/dist/lib/__tests__/DeviceModel.spec.d.ts +1 -0
  151. package/dist/lib/__tests__/DeviceModel.spec.js +90 -0
  152. package/dist/lib/__tests__/DeviceModel.spec.js.map +1 -0
  153. package/dist/lib/__tests__/Gateway.spec.d.ts +1 -0
  154. package/dist/lib/__tests__/Gateway.spec.js +35 -0
  155. package/dist/lib/__tests__/Gateway.spec.js.map +1 -0
  156. package/dist/lib/__tests__/Persist.spec.d.ts +1 -0
  157. package/dist/lib/__tests__/Persist.spec.js +90 -0
  158. package/dist/lib/__tests__/Persist.spec.js.map +1 -0
  159. package/dist/lib/__tests__/Session.spec.d.ts +1 -0
  160. package/dist/lib/__tests__/Session.spec.js +43 -0
  161. package/dist/lib/__tests__/Session.spec.js.map +1 -0
  162. package/dist/lib/constants.d.ts +95 -0
  163. package/dist/lib/constants.js +106 -0
  164. package/dist/lib/constants.js.map +1 -0
  165. package/dist/lib/request.d.ts +2 -0
  166. package/dist/lib/request.js +66 -0
  167. package/dist/lib/request.js.map +1 -0
  168. package/dist/platform.d.ts +41 -0
  169. package/dist/platform.js +229 -0
  170. package/dist/platform.js.map +1 -0
  171. package/dist/settings.d.ts +8 -0
  172. package/dist/settings.js +9 -0
  173. package/dist/settings.js.map +1 -0
  174. package/dist/status/BaseStatus.d.ts +48 -0
  175. package/dist/status/BaseStatus.js +59 -0
  176. package/dist/status/BaseStatus.js.map +1 -0
  177. package/dist/types/snapshots.d.ts +142 -0
  178. package/dist/types/snapshots.js +6 -0
  179. package/dist/types/snapshots.js.map +1 -0
  180. package/dist/utils/__tests__/normalize.spec.d.ts +1 -0
  181. package/dist/utils/__tests__/normalize.spec.js +95 -0
  182. package/dist/utils/__tests__/normalize.spec.js.map +1 -0
  183. package/dist/utils/normalize.d.ts +22 -0
  184. package/dist/utils/normalize.js +51 -0
  185. package/dist/utils/normalize.js.map +1 -0
  186. package/dist/v1/__tests__/prepareControlData.spec.d.ts +1 -0
  187. package/dist/v1/__tests__/prepareControlData.spec.js +48 -0
  188. package/dist/v1/__tests__/prepareControlData.spec.js.map +1 -0
  189. package/dist/v1/devices/AC.d.ts +13 -0
  190. package/dist/v1/devices/AC.js +112 -0
  191. package/dist/v1/devices/AC.js.map +1 -0
  192. package/dist/v1/devices/AirPurifier.d.ts +15 -0
  193. package/dist/v1/devices/AirPurifier.js +57 -0
  194. package/dist/v1/devices/AirPurifier.js.map +1 -0
  195. package/dist/v1/devices/RangeHood.d.ts +6 -0
  196. package/dist/v1/devices/RangeHood.js +12 -0
  197. package/dist/v1/devices/RangeHood.js.map +1 -0
  198. package/dist/v1/devices/Refrigerator.d.ts +17 -0
  199. package/dist/v1/devices/Refrigerator.js +69 -0
  200. package/dist/v1/devices/Refrigerator.js.map +1 -0
  201. package/dist/v1/devices/Washer.d.ts +10 -0
  202. package/dist/v1/devices/Washer.js +23 -0
  203. package/dist/v1/devices/Washer.js.map +1 -0
  204. package/dist/v1/devices/index.d.ts +6 -0
  205. package/dist/v1/devices/index.js +7 -0
  206. package/dist/v1/devices/index.js.map +1 -0
  207. package/dist/v1/helper.d.ts +14 -0
  208. package/dist/v1/helper.js +111 -0
  209. package/dist/v1/helper.js.map +1 -0
  210. package/dist/v1/transforms/AirPurifierState.d.ts +2 -0
  211. package/dist/v1/transforms/AirPurifierState.js +9 -0
  212. package/dist/v1/transforms/AirPurifierState.js.map +1 -0
  213. package/dist/v1/transforms/AirState.d.ts +9 -0
  214. package/dist/v1/transforms/AirState.js +55 -0
  215. package/dist/v1/transforms/AirState.js.map +1 -0
  216. package/dist/v1/transforms/HoodState.d.ts +17 -0
  217. package/dist/v1/transforms/HoodState.js +20 -0
  218. package/dist/v1/transforms/HoodState.js.map +1 -0
  219. package/dist/v1/transforms/RefState.d.ts +6 -0
  220. package/dist/v1/transforms/RefState.js +29 -0
  221. package/dist/v1/transforms/RefState.js.map +1 -0
  222. package/dist/v1/transforms/WasherDryer.d.ts +49 -0
  223. package/dist/v1/transforms/WasherDryer.js +56 -0
  224. package/dist/v1/transforms/WasherDryer.js.map +1 -0
  225. package/docs/authorization.md +40 -0
  226. package/docs/device-configuration.md +68 -0
  227. package/homebridge-ui/public/index.html +120 -0
  228. package/homebridge-ui/public/js/app.js +300 -0
  229. package/homebridge-ui/public/js/countries.js +233 -0
  230. package/homebridge-ui/public/styles.css +185 -0
  231. package/homebridge-ui/server.js +103 -0
  232. package/jest.config.ts +39 -0
  233. package/package.json +83 -0
  234. package/sample/README.md +10 -0
  235. package/sample/airconditioner-model.json +3080 -0
  236. package/sample/airconditioner-snapshot.json +49 -0
  237. package/sample/airconditioner.json +157 -0
  238. package/sample/dishwasher-model.json +869 -0
  239. package/sample/dishwasher.json +125 -0
  240. package/sample/washer_dryer-model.json +1294 -0
  241. package/sample/washer_dryer.json +126 -0
@@ -0,0 +1,1939 @@
1
+ /**
2
+ * Special thank to carlosgamezvillegas (https://github.com/carlosgamezvillegas) for the initial work on the Microwave device.
3
+ */
4
+ import { BaseDevice } from '../baseDevice.js';
5
+ import { normalizeBoolean, normalizeNumber, safeParseInt } from '../helper.js';
6
+ import { ONE_HOUR_IN_SECONDS, ONE_SECOND_MS, TEN_SECONDS_MS, TWO_MINUTES_MS } from '../lib/constants.js';
7
+ export default class Microwave extends BaseDevice {
8
+ platform;
9
+ accessory;
10
+ inputNameStatus = 'Microwave Status';
11
+ inputNameMode = 'Microwave Mode';
12
+ inputNameTempString = 'Microwave Temperature';
13
+ courseStartString = 'Microwave Start Time Not Set';
14
+ courseTimeString = 'Microwave Cook Time Not Set';
15
+ courseTimerString = 'Microwave Cook Timer Not Set';
16
+ courseTimeEndString = 'Microwave End Time Not Set';
17
+ inputNameOptions = 'Microwave Options';
18
+ firstStart = true;
19
+ firstDuration = 0;
20
+ firstTimer = 0;
21
+ courseStartMS = 0;
22
+ inputID = 1;
23
+ temperatureFCommand = 0;
24
+ thermostatSel = 0;
25
+ timerAlarmSec = 0;
26
+ pauseUpdate = false;
27
+ firstPause = true;
28
+ ventSpeed = 0;
29
+ lampLevel = 0;
30
+ mwPower = 50;
31
+ localTemperature = 22;
32
+ localHumidity = 50;
33
+ defaultTemp = 0;
34
+ waitingForCommand = false;
35
+ ovenCommandList = {
36
+ ovenMode: 'WARM',
37
+ ovenSetTemperature: 0,
38
+ tempUnits: this.Status.data?.LWOTargetTemperatureUnit,
39
+ ovenSetDuration: 0,
40
+ subCookNumber: 0,
41
+ weightUnits: 'KG',
42
+ microwavePower: '100',
43
+ targetWeight: 0
44
+ };
45
+ showTime = true;
46
+ showTimer = true;
47
+ monitorOnly = false;
48
+ timeOut = 0;
49
+ /** Service */
50
+ serviceHood;
51
+ serviceLight;
52
+ microwavePower;
53
+ ovenService;
54
+ ovenState;
55
+ lightVent;
56
+ ovenMode;
57
+ ovenTemp;
58
+ ovenOptions;
59
+ ovenStart;
60
+ ovenTimer;
61
+ ovenTime;
62
+ ovenEndTime;
63
+ ovenTimerService;
64
+ ovenAlarmService;
65
+ microwaveSwitch;
66
+ combiBakeSwitch;
67
+ dehydrateSwitch;
68
+ ovenSwitch;
69
+ convectionBakeSwitch;
70
+ convectionRoastSwitch;
71
+ frozenMealSwitch;
72
+ defrostSwitch;
73
+ airFrySwitch;
74
+ proofSwitch;
75
+ warmModeSwitch;
76
+ cancelSwitch;
77
+ startOvenSwitch;
78
+ ovenTempControl;
79
+ offSwitch;
80
+ constructor(platform, accessory, logger) {
81
+ super(platform, accessory, logger);
82
+ this.platform = platform;
83
+ this.accessory = accessory;
84
+ const { Characteristic } = this.platform;
85
+ //const device = accessory.context.device;
86
+ this.serviceHood = this.accessory.getService('Microwave Fan') ||
87
+ this.accessory.addService(this.platform.Service.Fanv2, 'Microwave Fan', 'YourUniqueIdentifier-59F');
88
+ this.serviceHood.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
89
+ this.serviceHood.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Microwave Fan');
90
+ this.serviceHood.getCharacteristic(Characteristic.Active)
91
+ .on('get', (callback) => {
92
+ let currentValue = 0;
93
+ if (this.Status.data?.mwoVentSpeedLevel > 0) {
94
+ currentValue = 1;
95
+ }
96
+ callback(null, currentValue);
97
+ })
98
+ .on('set', (value, callback) => {
99
+ const vNum = normalizeNumber(value);
100
+ if (vNum === null) {
101
+ callback(null);
102
+ return;
103
+ }
104
+ this.ventSpeed = vNum;
105
+ if (this.ventSpeed !== this.Status.data?.mwoVentSpeedLevel) {
106
+ this.sendLightVentCommand();
107
+ }
108
+ callback(null);
109
+ });
110
+ this.serviceHood.getCharacteristic(Characteristic.RotationSpeed)
111
+ .on('get', (callback) => {
112
+ this.ventSpeed = this.Status.data?.mwoVentSpeedLevel;
113
+ callback(null, this.ventSpeed);
114
+ })
115
+ .on('set', (value, callback) => {
116
+ const vNum = normalizeNumber(value);
117
+ if (vNum === null) {
118
+ callback(null);
119
+ return;
120
+ }
121
+ this.ventSpeed = vNum;
122
+ this.sendLightVentCommand();
123
+ callback(null);
124
+ });
125
+ this.serviceHood.getCharacteristic(Characteristic.RotationSpeed)
126
+ .setProps({
127
+ minValue: 0,
128
+ maxValue: 5,
129
+ minStep: 1,
130
+ });
131
+ // vent lamp
132
+ this.serviceLight = this.accessory.getService('Microwave Light') ||
133
+ this.accessory.addService(this.platform.Service.Lightbulb, 'Microwave Light', 'YourUniqueIdentifier-59L');
134
+ this.serviceLight.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
135
+ this.serviceLight.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Microwave Light');
136
+ this.serviceLight.getCharacteristic(Characteristic.On)
137
+ .on('set', (value, callback) => {
138
+ const enabled = normalizeBoolean(value);
139
+ if (!enabled) {
140
+ this.lampLevel = 0;
141
+ this.sendLightVentCommand();
142
+ }
143
+ else {
144
+ this.lampLevel = 2;
145
+ this.sendLightVentCommand();
146
+ }
147
+ callback(null);
148
+ })
149
+ .on('get', (callback) => {
150
+ let currentValue = false;
151
+ if (this.Status.data?.mwoLampLevel > 0) {
152
+ currentValue = true;
153
+ }
154
+ callback(null, currentValue);
155
+ });
156
+ this.serviceLight.getCharacteristic(Characteristic.Brightness)
157
+ .on('get', (callback) => {
158
+ this.lampLevel = this.Status.data?.mwoLampLevel;
159
+ callback(null, this.lampLevel);
160
+ })
161
+ .on('set', (value, callback) => {
162
+ const vNum = normalizeNumber(value);
163
+ if (vNum === null) {
164
+ callback(null);
165
+ return;
166
+ }
167
+ this.lampLevel = vNum;
168
+ if (this.lampLevel !== this.Status.data?.mwoLampLevel) {
169
+ this.sendLightVentCommand();
170
+ }
171
+ callback(null);
172
+ });
173
+ this.serviceLight.getCharacteristic(Characteristic.Brightness)
174
+ .setProps({
175
+ minValue: 0,
176
+ maxValue: 2,
177
+ minStep: 1,
178
+ });
179
+ this.offSwitch = accessory.getService('Turn Off Microwave') ||
180
+ accessory.addService(this.platform.Service.Switch, 'Turn Off Microwave', 'CataNicoGaTa-Control8Off');
181
+ this.offSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
182
+ this.offSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Turn Off the Microwave');
183
+ this.offSwitch.getCharacteristic(this.platform.Characteristic.On)
184
+ .on('get', (callback) => {
185
+ const currentValue = false;
186
+ callback(null, currentValue);
187
+ })
188
+ .on('set', (value, callback) => {
189
+ if (value) {
190
+ if (this.Status.data?.mwoVentSpeedLevel !== 0 || this.Status.data?.mwoLampLevel !== 0) {
191
+ this.lampLevel = 0;
192
+ this.ventSpeed = 0;
193
+ this.sendLightVentCommand();
194
+ }
195
+ setTimeout(() => {
196
+ this.offSwitch.updateCharacteristic(this.platform.Characteristic.On, false);
197
+ }, ONE_SECOND_MS);
198
+ }
199
+ callback(null);
200
+ });
201
+ this.microwavePower = this.accessory.getService('Microwave Power') ||
202
+ this.accessory.addService(this.platform.Service.Lightbulb, 'Microwave Power', 'YourUniqueIdentifier-59SP');
203
+ this.microwavePower.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
204
+ this.microwavePower.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Microwave Power');
205
+ this.microwavePower.getCharacteristic(this.platform.Characteristic.On)
206
+ .on('set', (value, callback) => {
207
+ const enabled = normalizeBoolean(value);
208
+ if (!enabled) {
209
+ this.mwPower = 0;
210
+ }
211
+ else {
212
+ this.mwPower = 100;
213
+ }
214
+ callback(null);
215
+ })
216
+ .on('get', (callback) => {
217
+ let currentValue = false;
218
+ if (safeParseInt(this.Status.data?.LWOMGTPowerLevel) * 10 > 0) {
219
+ currentValue = true;
220
+ }
221
+ callback(null, currentValue);
222
+ });
223
+ this.microwavePower.getCharacteristic(this.platform.Characteristic.Brightness)
224
+ .on('get', (callback) => {
225
+ const currentValue = safeParseInt(this.Status.data?.LWOMGTPowerLevel) * 10;
226
+ callback(null, currentValue);
227
+ })
228
+ .on('set', (value, callback) => {
229
+ const vNum = normalizeNumber(value);
230
+ if (vNum !== null) {
231
+ this.mwPower = vNum;
232
+ }
233
+ callback(null);
234
+ });
235
+ this.microwavePower.getCharacteristic(this.platform.Characteristic.Brightness)
236
+ .setProps({
237
+ minValue: 0,
238
+ maxValue: 100,
239
+ minStep: 10,
240
+ });
241
+ /////////////
242
+ this.ovenService = this.accessory.getService(this.config.name) ||
243
+ this.accessory.addService(this.platform.Service.Television, this.config.name, 'NicoCataGaTa-OvenOven7');
244
+ this.ovenService.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'LG Microwave Oven');
245
+ this.ovenService.setPrimaryService(true);
246
+ this.ovenService.setCharacteristic(this.platform
247
+ .Characteristic.SleepDiscoveryMode, this.platform.Characteristic.SleepDiscoveryMode.ALWAYS_DISCOVERABLE);
248
+ this.ovenService.getCharacteristic(this.platform.Characteristic.Active)
249
+ .on('get', (callback) => {
250
+ const currentValue = this.ovenServiceActive();
251
+ callback(null, currentValue);
252
+ })
253
+ .on('set', (value, callback) => {
254
+ const enabled = normalizeBoolean(value);
255
+ if (!enabled) {
256
+ if (this.Status.data?.LWOState?.includes('INITIAL')) {
257
+ this.stopOven();
258
+ this.timeOut = 1500;
259
+ setTimeout(() => {
260
+ this.timeOut = 0;
261
+ }, this.timeOut);
262
+ }
263
+ setTimeout(() => {
264
+ if (this.Status.data?.mwoVentSpeedLevel !== 0 || this.Status.data?.mwoLampLevel !== 0) {
265
+ this.lampLevel = 0;
266
+ this.ventSpeed = 0;
267
+ this.sendLightVentCommand();
268
+ }
269
+ }, this.timeOut);
270
+ }
271
+ else {
272
+ if (this.Status.data?.mwoVentSpeedLevel === 0 || this.Status.data?.mwoLampLevel === 0) {
273
+ this.lampLevel = 2;
274
+ this.ventSpeed = 2;
275
+ this.sendLightVentCommand();
276
+ }
277
+ }
278
+ callback(null);
279
+ });
280
+ this.ovenService
281
+ .setCharacteristic(this.platform.Characteristic.ActiveIdentifier, this.inputID);
282
+ this.ovenService
283
+ .getCharacteristic(this.platform.Characteristic.ActiveIdentifier)
284
+ .on('set', (inputIdentifier, callback) => {
285
+ const vNum = normalizeNumber(inputIdentifier);
286
+ if (vNum === null) {
287
+ this.logger.error('ActiveIdentifier is not a number');
288
+ callback();
289
+ return;
290
+ }
291
+ if (vNum > 9 || vNum < 1) {
292
+ this.inputID = 1;
293
+ }
294
+ else {
295
+ this.inputID = vNum;
296
+ }
297
+ callback();
298
+ })
299
+ .on('get', (callback) => {
300
+ const currentValue = this.inputID;
301
+ callback(null, currentValue);
302
+ });
303
+ this.ovenState = this.accessory.getService('Microwave Status')
304
+ || this.accessory.addService(this.platform.Service.InputSource, 'Microwave Status', 'NicoCataGaTa-Oven1003')
305
+ .setCharacteristic(this.platform.Characteristic.Identifier, 1)
306
+ .setCharacteristic(this.platform.Characteristic.ConfiguredName, this.ovenStatus())
307
+ .setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
308
+ .setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
309
+ .setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.platform.Characteristic.CurrentVisibilityState.SHOWN);
310
+ this.ovenState.getCharacteristic(this.platform.Characteristic.ConfiguredName)
311
+ .on('get', (callback) => {
312
+ const currentValue = this.ovenStatus();
313
+ callback(null, currentValue);
314
+ });
315
+ this.ovenService.addLinkedService(this.ovenState);
316
+ this.lightVent = this.accessory.getService('Light and Vent Status')
317
+ || this.accessory.addService(this.platform.Service.InputSource, 'Light and Vent Status', 'NicoCata-Always15')
318
+ .setCharacteristic(this.platform.Characteristic.Identifier, 2)
319
+ .setCharacteristic(this.platform.Characteristic.ConfiguredName, this.lightVentStatus())
320
+ .setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
321
+ .setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
322
+ .setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.lightVentState()
323
+ ? this.platform.Characteristic.TargetVisibilityState.SHOWN
324
+ : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
325
+ .setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.lightVentState()
326
+ ? this.platform.Characteristic.CurrentVisibilityState.SHOWN
327
+ : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
328
+ this.lightVent.getCharacteristic(this.platform.Characteristic.ConfiguredName)
329
+ .on('get', (callback) => {
330
+ const currentValue = this.lightVentStatus();
331
+ callback(null, currentValue);
332
+ });
333
+ this.ovenService.addLinkedService(this.lightVent);
334
+ this.ovenMode = this.accessory.getService('Microwave Cooking Mode')
335
+ || this.accessory.addService(this.platform.Service.InputSource, 'Microwave Cooking Mode', 'NicoCataGaTa-Oven1004')
336
+ .setCharacteristic(this.platform.Characteristic.Identifier, 3)
337
+ .setCharacteristic(this.platform.Characteristic.ConfiguredName, this.ovenModeName())
338
+ .setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
339
+ .setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
340
+ .setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.onStatus()
341
+ ? this.platform.Characteristic.TargetVisibilityState.SHOWN
342
+ : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
343
+ .setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.onStatus()
344
+ ? this.platform.Characteristic.CurrentVisibilityState.SHOWN
345
+ : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
346
+ this.ovenMode.getCharacteristic(this.platform.Characteristic.ConfiguredName)
347
+ .on('get', (callback) => {
348
+ const currentValue = this.ovenModeName();
349
+ callback(null, currentValue);
350
+ });
351
+ this.ovenService.addLinkedService(this.ovenMode);
352
+ this.ovenTemp = this.accessory.getService('Microwave Oven Temperature')
353
+ || this.accessory.addService(this.platform.Service.InputSource, 'Microwave Oven Temperature', 'NicoCataGaTa-Oven1004T')
354
+ .setCharacteristic(this.platform.Characteristic.Identifier, 4)
355
+ .setCharacteristic(this.platform.Characteristic.ConfiguredName, this.ovenTemperature())
356
+ .setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
357
+ .setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
358
+ .setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.onStatus()
359
+ ? this.platform.Characteristic.TargetVisibilityState.SHOWN
360
+ : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
361
+ .setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.onStatus()
362
+ ? this.platform.Characteristic.CurrentVisibilityState.SHOWN
363
+ : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
364
+ this.ovenTemp.getCharacteristic(this.platform.Characteristic.ConfiguredName)
365
+ .on('get', (callback) => {
366
+ const currentValue = this.ovenTemperature();
367
+ callback(null, currentValue);
368
+ });
369
+ this.ovenService.addLinkedService(this.ovenTemp);
370
+ this.ovenOptions = this.accessory.getService('Microwave Options')
371
+ || this.accessory.addService(this.platform.Service.InputSource, 'Microwave Options', 'NicoCata-Always4')
372
+ .setCharacteristic(this.platform.Characteristic.Identifier, 5)
373
+ .setCharacteristic(this.platform.Characteristic.ConfiguredName, this.oventOptions())
374
+ .setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
375
+ .setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
376
+ .setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.onStatus()
377
+ ? this.platform.Characteristic.TargetVisibilityState.SHOWN
378
+ : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
379
+ .setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.onStatus()
380
+ ? this.platform.Characteristic.CurrentVisibilityState.SHOWN
381
+ : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
382
+ this.ovenOptions.getCharacteristic(this.platform.Characteristic.ConfiguredName)
383
+ .on('get', (callback) => {
384
+ const currentValue = this.oventOptions();
385
+ callback(null, currentValue);
386
+ });
387
+ this.ovenService.addLinkedService(this.ovenOptions);
388
+ this.ovenStart = this.accessory.getService('Microwave Start Time')
389
+ || this.accessory.addService(this.platform.Service.InputSource, 'Microwave Start Time', 'NicoCata-Always1')
390
+ .setCharacteristic(this.platform.Characteristic.Identifier, 6)
391
+ .setCharacteristic(this.platform.Characteristic.ConfiguredName, this.courseStartString)
392
+ .setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
393
+ .setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
394
+ .setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.showTime
395
+ ? this.platform.Characteristic.TargetVisibilityState.SHOWN
396
+ : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
397
+ .setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.showTime
398
+ ? this.platform.Characteristic.CurrentVisibilityState.SHOWN
399
+ : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
400
+ this.ovenStart.getCharacteristic(this.platform.Characteristic.ConfiguredName)
401
+ .on('get', (callback) => {
402
+ const currentValue = this.courseStartString;
403
+ callback(null, currentValue);
404
+ });
405
+ this.ovenService.addLinkedService(this.ovenStart);
406
+ this.ovenTimer = this.accessory.getService('Microwave Timer Status')
407
+ || this.accessory.addService(this.platform.Service.InputSource, 'Microwave Timer Status', 'NicoCata-Always2')
408
+ .setCharacteristic(this.platform.Characteristic.Identifier, 7)
409
+ .setCharacteristic(this.platform.Characteristic.ConfiguredName, this.courseTimerString)
410
+ .setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
411
+ .setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
412
+ .setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.showTimer
413
+ ? this.platform.Characteristic.TargetVisibilityState.SHOWN
414
+ : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
415
+ .setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.showTimer
416
+ ? this.platform.Characteristic.CurrentVisibilityState.SHOWN
417
+ : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
418
+ this.ovenTimer.getCharacteristic(this.platform.Characteristic.ConfiguredName)
419
+ .on('get', (callback) => {
420
+ const currentValue = this.courseTimerString;
421
+ callback(null, currentValue);
422
+ });
423
+ this.ovenService.addLinkedService(this.ovenTimer);
424
+ this.ovenTime = this.accessory.getService('Microwave Cook Time Status')
425
+ || this.accessory.addService(this.platform.Service.InputSource, 'Microwave Cook Time Status', 'NicoCata-Always2T')
426
+ .setCharacteristic(this.platform.Characteristic.Identifier, 8)
427
+ .setCharacteristic(this.platform.Characteristic.ConfiguredName, this.courseTimeString)
428
+ .setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
429
+ .setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
430
+ .setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.showTime
431
+ ? this.platform.Characteristic.TargetVisibilityState.SHOWN
432
+ : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
433
+ .setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.showTime
434
+ ? this.platform.Characteristic.CurrentVisibilityState.SHOWN
435
+ : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
436
+ this.ovenTime.getCharacteristic(this.platform.Characteristic.ConfiguredName)
437
+ .on('get', (callback) => {
438
+ const currentValue = this.courseTimeString;
439
+ callback(null, currentValue);
440
+ });
441
+ this.ovenService.addLinkedService(this.ovenTime);
442
+ this.ovenEndTime = this.accessory.getService('Microwave End Time')
443
+ || this.accessory.addService(this.platform.Service.InputSource, 'Microwave End Time', 'NicoCata-Always3')
444
+ .setCharacteristic(this.platform.Characteristic.Identifier, 9)
445
+ .setCharacteristic(this.platform.Characteristic.ConfiguredName, this.courseTimeEndString)
446
+ .setCharacteristic(this.platform.Characteristic.IsConfigured, this.platform.Characteristic.IsConfigured.CONFIGURED)
447
+ .setCharacteristic(this.platform.Characteristic.InputSourceType, this.platform.Characteristic.InputSourceType.APPLICATION)
448
+ .setCharacteristic(this.platform.Characteristic.TargetVisibilityState, this.showTime
449
+ ? this.platform.Characteristic.TargetVisibilityState.SHOWN
450
+ : this.platform.Characteristic.TargetVisibilityState.HIDDEN)
451
+ .setCharacteristic(this.platform.Characteristic.CurrentVisibilityState, this.showTime
452
+ ? this.platform.Characteristic.CurrentVisibilityState.SHOWN
453
+ : this.platform.Characteristic.CurrentVisibilityState.HIDDEN);
454
+ this.ovenEndTime.getCharacteristic(this.platform.Characteristic.ConfiguredName)
455
+ .on('get', (callback) => {
456
+ const currentValue = this.courseTimeEndString;
457
+ callback(null, currentValue);
458
+ });
459
+ this.ovenService.addLinkedService(this.ovenEndTime);
460
+ //////////Timers
461
+ this.ovenTimerService = this.accessory.getService('Microwave Cook Time') ||
462
+ this.accessory.addService(this.platform.Service.Valve, 'Microwave Cook Time', 'NicoCataGaTa-OvenT2');
463
+ this.ovenTimerService.setCharacteristic(Characteristic.Name, 'Microwave Cook Time');
464
+ this.ovenTimerService.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
465
+ this.ovenTimerService.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Microwave Cook Time');
466
+ this.ovenTimerService.setCharacteristic(Characteristic.ValveType, Characteristic.ValveType.IRRIGATION);
467
+ this.ovenTimerService.getCharacteristic(Characteristic.Active)
468
+ .on('get', (callback) => {
469
+ let currentValue = 0;
470
+ if (this.remainTime() !== 0) {
471
+ currentValue = 1;
472
+ }
473
+ callback(null, currentValue);
474
+ })
475
+ .on('set', (value, callback) => {
476
+ const enabled = normalizeBoolean(value);
477
+ if (!enabled) {
478
+ this.stopOven();
479
+ this.ovenTimerService.updateCharacteristic(Characteristic.Active, 0);
480
+ this.ovenTimerService.updateCharacteristic(Characteristic.RemainingDuration, 0);
481
+ this.ovenTimerService.updateCharacteristic(Characteristic.InUse, 0);
482
+ }
483
+ else {
484
+ this.sendOvenCommand();
485
+ }
486
+ callback(null);
487
+ });
488
+ this.ovenTimerService.setCharacteristic(Characteristic.InUse, this.remainTime() > 0 ? Characteristic.InUse.IN_USE : Characteristic.InUse.NOT_IN_USE);
489
+ this.ovenTimerService.getCharacteristic(Characteristic.RemainingDuration)
490
+ .setProps({
491
+ maxValue: 32400, // 9hours
492
+ })
493
+ .on('get', (callback) => {
494
+ const currentValue = this.remainTime();
495
+ callback(null, currentValue);
496
+ });
497
+ this.ovenTimerService.getCharacteristic(this.platform.Characteristic.SetDuration)
498
+ .setProps({
499
+ maxValue: 32400, // 9hours
500
+ })
501
+ .on('get', (callback) => {
502
+ const currentValue = this.oventTargetTime();
503
+ callback(null, currentValue);
504
+ })
505
+ .on('set', (value, callback) => {
506
+ const vNum = normalizeNumber(value);
507
+ if (vNum === null) {
508
+ this.logger.error('SetDuration is not a number');
509
+ callback();
510
+ return;
511
+ }
512
+ this.pauseUpdate = true;
513
+ this.logger.debug('Cooking Duration set to to: ' + this.secondsToTime(vNum));
514
+ this.ovenCommandList.ovenSetDuration = vNum;
515
+ callback(null);
516
+ });
517
+ this.ovenAlarmService = this.accessory.getService('Microwave Timer') ||
518
+ this.accessory.addService(this.platform.Service.Valve, 'Microwave Timer', 'NicoCataGaTa-OvenT32');
519
+ this.ovenAlarmService.setCharacteristic(Characteristic.Name, 'Microwave Timer');
520
+ this.ovenAlarmService.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
521
+ this.ovenAlarmService.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Microwave Timer');
522
+ this.ovenAlarmService.setCharacteristic(Characteristic.ValveType, Characteristic.ValveType.IRRIGATION);
523
+ this.ovenAlarmService.getCharacteristic(Characteristic.Active)
524
+ .on('get', (callback) => {
525
+ let currentValue = 0;
526
+ if (this.ovenTimerTime() !== 0) {
527
+ currentValue = 1;
528
+ }
529
+ callback(null, currentValue);
530
+ })
531
+ .on('set', (value, callback) => {
532
+ const enabled = normalizeBoolean(value);
533
+ if (!enabled) {
534
+ this.timerAlarmSec = 0;
535
+ this.sendTimerCommand(0);
536
+ this.ovenAlarmService.updateCharacteristic(Characteristic.Active, 0);
537
+ this.ovenAlarmService.updateCharacteristic(Characteristic.RemainingDuration, 0);
538
+ this.ovenAlarmService.updateCharacteristic(Characteristic.InUse, 0);
539
+ }
540
+ else {
541
+ this.sendTimerCommand(this.timerAlarmSec);
542
+ this.ovenAlarmService.updateCharacteristic(Characteristic.Active, 1);
543
+ this.ovenAlarmService.updateCharacteristic(Characteristic.RemainingDuration, this.timerAlarmSec);
544
+ this.ovenAlarmService.updateCharacteristic(Characteristic.InUse, 1);
545
+ }
546
+ callback(null);
547
+ });
548
+ this.ovenAlarmService.setCharacteristic(Characteristic.InUse, this.ovenTimerTime() > 0 ? Characteristic.InUse.IN_USE : Characteristic.InUse.NOT_IN_USE);
549
+ this.ovenAlarmService.getCharacteristic(Characteristic.RemainingDuration)
550
+ .setProps({
551
+ maxValue: (6000 - 1), // 100 minutes
552
+ })
553
+ .on('get', (callback) => {
554
+ const currentValue = this.ovenTimerTime();
555
+ callback(null, currentValue);
556
+ });
557
+ this.ovenAlarmService.getCharacteristic(this.platform.Characteristic.SetDuration)
558
+ .setProps({
559
+ maxValue: (6000 - 1), // 100 minutes
560
+ minStep: 60,
561
+ })
562
+ .on('get', (callback) => {
563
+ const currentValue = this.timerAlarmSec;
564
+ callback(null, currentValue);
565
+ })
566
+ .on('set', (value, callback) => {
567
+ let vNum = normalizeNumber(value);
568
+ if (vNum === null) {
569
+ this.logger.error('SetDuration is not a number');
570
+ callback();
571
+ return;
572
+ }
573
+ if (vNum >= 6000) {
574
+ vNum = 6000 - 1;
575
+ }
576
+ this.timerAlarmSec = vNum;
577
+ callback(null);
578
+ });
579
+ ///////////Switches
580
+ this.microwaveSwitch = accessory.getService('Microwave Mode') ||
581
+ accessory.addService(this.platform.Service.Switch, 'Microwave Mode', 'CataNicoGaTa-80M');
582
+ this.microwaveSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
583
+ this.microwaveSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Microwave Mode');
584
+ this.microwaveSwitch.getCharacteristic(this.platform.Characteristic.On)
585
+ .on('get', (callback) => {
586
+ const currentValue = false;
587
+ callback(null, currentValue);
588
+ })
589
+ .on('set', (value, callback) => {
590
+ if (value) {
591
+ this.ovenCommandList.ovenMode = 'MICROWAVE';
592
+ }
593
+ this.updateOvenModeSwitch();
594
+ callback(null);
595
+ });
596
+ this.combiBakeSwitch = accessory.getService('Combination Bake Mode') ||
597
+ accessory.addService(this.platform.Service.Switch, 'Combination Bake Mode', 'CataNicoGaTa-80B');
598
+ this.combiBakeSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
599
+ this.combiBakeSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Combination Bake Mode');
600
+ this.combiBakeSwitch.getCharacteristic(this.platform.Characteristic.On)
601
+ .on('get', (callback) => {
602
+ const currentValue = false;
603
+ callback(null, currentValue);
604
+ })
605
+ .on('set', (value, callback) => {
606
+ if (value) {
607
+ this.ovenCommandList.ovenMode = 'COMBI_BAKE';
608
+ }
609
+ this.updateOvenModeSwitch();
610
+ callback(null);
611
+ });
612
+ this.dehydrateSwitch = accessory.getService('Dehydrate Mode') ||
613
+ accessory.addService(this.platform.Service.Switch, 'Dehydrate Mode', 'CataNicoGaTa-80d');
614
+ this.dehydrateSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
615
+ this.dehydrateSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Dehydrate Mode');
616
+ this.dehydrateSwitch.getCharacteristic(this.platform.Characteristic.On)
617
+ .on('get', (callback) => {
618
+ const currentValue = false;
619
+ callback(null, currentValue);
620
+ })
621
+ .on('set', (value, callback) => {
622
+ if (value) {
623
+ this.ovenCommandList.ovenMode = 'DEHYDRATE';
624
+ }
625
+ this.updateOvenModeSwitch();
626
+ callback(null);
627
+ });
628
+ this.ovenSwitch = accessory.getService('Oven Mode') ||
629
+ accessory.addService(this.platform.Service.Switch, 'Oven Mode', 'CataNicoGaTa-80OVen');
630
+ this.ovenSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
631
+ this.ovenSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Oven Mode');
632
+ this.ovenSwitch.getCharacteristic(this.platform.Characteristic.On)
633
+ .on('get', (callback) => {
634
+ const currentValue = false;
635
+ callback(null, currentValue);
636
+ })
637
+ .on('set', (value, callback) => {
638
+ if (value) {
639
+ this.ovenCommandList.ovenMode = 'OVEN';
640
+ }
641
+ this.updateOvenModeSwitch();
642
+ callback(null);
643
+ });
644
+ this.convectionBakeSwitch = accessory.getService('Convection Bake Mode') ||
645
+ accessory.addService(this.platform.Service.Switch, 'Convection Bake Mode', 'CataNicoGaTa-Control1');
646
+ this.convectionBakeSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
647
+ this.convectionBakeSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Convection Bake Mode');
648
+ this.convectionBakeSwitch.getCharacteristic(this.platform.Characteristic.On)
649
+ .on('get', (callback) => {
650
+ const currentValue = false;
651
+ callback(null, currentValue);
652
+ })
653
+ .on('set', (value, callback) => {
654
+ const enabled = normalizeBoolean(value);
655
+ if (enabled) {
656
+ this.ovenCommandList.ovenMode = 'CONV_BAKE';
657
+ }
658
+ this.updateOvenModeSwitch();
659
+ callback(null);
660
+ });
661
+ this.convectionRoastSwitch = accessory.getService('Combination Roast Mode') ||
662
+ accessory.addService(this.platform.Service.Switch, 'Combination Roast Mode', 'CataNicoGaTa-Control2');
663
+ this.convectionRoastSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
664
+ this.convectionRoastSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Combination Roast Mode');
665
+ this.convectionRoastSwitch.getCharacteristic(this.platform.Characteristic.On)
666
+ .on('get', (callback) => {
667
+ const currentValue = false;
668
+ callback(null, currentValue);
669
+ })
670
+ .on('set', (value, callback) => {
671
+ const enabled = normalizeBoolean(value);
672
+ if (enabled) {
673
+ this.ovenCommandList.ovenMode = 'COMBI_ROAST';
674
+ }
675
+ this.updateOvenModeSwitch();
676
+ callback(null);
677
+ });
678
+ this.frozenMealSwitch = accessory.getService('Time Defrost Mode') ||
679
+ accessory.addService(this.platform.Service.Switch, 'Time Defrost Mode', 'CataNicoGaTa-Control3');
680
+ this.frozenMealSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
681
+ this.frozenMealSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Time Defrost Mode');
682
+ this.frozenMealSwitch.getCharacteristic(this.platform.Characteristic.On)
683
+ .on('get', (callback) => {
684
+ const currentValue = false;
685
+ callback(null, currentValue);
686
+ })
687
+ .on('set', (value, callback) => {
688
+ const enabled = normalizeBoolean(value);
689
+ if (enabled) {
690
+ this.ovenCommandList.ovenMode = 'TIME_DEFROST';
691
+ }
692
+ this.updateOvenModeSwitch();
693
+ callback(null);
694
+ });
695
+ this.defrostSwitch = accessory.getService('Defrost Mode') ||
696
+ accessory.addService(this.platform.Service.Switch, 'Defrost Mode', 'CataNicoGaTa-Control3D');
697
+ this.defrostSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
698
+ this.defrostSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Defrost Mode');
699
+ this.defrostSwitch.getCharacteristic(this.platform.Characteristic.On)
700
+ .on('get', (callback) => {
701
+ const currentValue = false;
702
+ callback(null, currentValue);
703
+ })
704
+ .on('set', (value, callback) => {
705
+ const enabled = normalizeBoolean(value);
706
+ if (enabled) {
707
+ this.ovenCommandList.ovenMode = 'INVERTER_DEFROST';
708
+ }
709
+ this.updateOvenModeSwitch();
710
+ callback(null);
711
+ });
712
+ this.airFrySwitch = accessory.getService('Air Fry Mode') ||
713
+ accessory.addService(this.platform.Service.Switch, 'Air Fry Mode', 'CataNicoGaTa-Control4');
714
+ this.airFrySwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
715
+ this.airFrySwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Air Fry Mode');
716
+ this.airFrySwitch.getCharacteristic(this.platform.Characteristic.On)
717
+ .on('get', (callback) => {
718
+ const currentValue = false;
719
+ callback(null, currentValue);
720
+ })
721
+ .on('set', (value, callback) => {
722
+ const enabled = normalizeBoolean(value);
723
+ if (enabled) {
724
+ this.ovenCommandList.ovenMode = 'AIRFRY';
725
+ }
726
+ this.updateOvenModeSwitch();
727
+ callback(null);
728
+ });
729
+ this.proofSwitch = accessory.getService('Proof Mode') ||
730
+ accessory.addService(this.platform.Service.Switch, 'Proof Mode', 'CataNicoGaTa-Control5');
731
+ this.proofSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
732
+ this.proofSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Proof Mode');
733
+ this.proofSwitch.getCharacteristic(this.platform.Characteristic.On)
734
+ .on('get', (callback) => {
735
+ const currentValue = false;
736
+ callback(null, currentValue);
737
+ })
738
+ .on('set', (value, callback) => {
739
+ const enabled = normalizeBoolean(value);
740
+ if (enabled) {
741
+ this.ovenCommandList.ovenMode = 'PROOF';
742
+ }
743
+ this.updateOvenModeSwitch();
744
+ callback(null);
745
+ });
746
+ this.warmModeSwitch = accessory.getService('Warm Mode (High)') ||
747
+ accessory.addService(this.platform.Service.Switch, 'Warm Mode (High)', 'CataNicoGaTa-Control5W');
748
+ this.warmModeSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
749
+ this.warmModeSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Warm Mode (High)');
750
+ this.warmModeSwitch.getCharacteristic(this.platform.Characteristic.On)
751
+ .on('get', (callback) => {
752
+ const currentValue = false;
753
+ callback(null, currentValue);
754
+ })
755
+ .on('set', (value, callback) => {
756
+ const enabled = normalizeBoolean(value);
757
+ if (enabled) {
758
+ this.ovenCommandList.ovenMode = 'WARM';
759
+ }
760
+ this.updateOvenModeSwitch();
761
+ callback(null);
762
+ });
763
+ this.cancelSwitch = accessory.getService('Stop Microwave') ||
764
+ accessory.addService(this.platform.Service.Switch, 'Stop Microwave', 'CataNicoGaTa-Control6');
765
+ this.cancelSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
766
+ this.cancelSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Stop Microwave');
767
+ this.cancelSwitch.getCharacteristic(this.platform.Characteristic.On)
768
+ .on('get', (callback) => {
769
+ const currentValue = false;
770
+ callback(null, currentValue);
771
+ })
772
+ .on('set', (value, callback) => {
773
+ const enabled = normalizeBoolean(value);
774
+ if (enabled) {
775
+ this.stopOven();
776
+ }
777
+ setTimeout(() => {
778
+ this.cancelSwitch.updateCharacteristic(this.platform.Characteristic.On, false);
779
+ }, ONE_SECOND_MS);
780
+ this.updateOvenModeSwitch();
781
+ callback(null);
782
+ });
783
+ this.startOvenSwitch = accessory.getService('Start Microwave') ||
784
+ accessory.addService(this.platform.Service.Switch, 'Start Microwave', 'CataNicoGaTa-Control8');
785
+ this.startOvenSwitch.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
786
+ this.startOvenSwitch.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Start Microwave');
787
+ this.startOvenSwitch.getCharacteristic(this.platform.Characteristic.On)
788
+ .on('get', (callback) => {
789
+ const currentValue = false;
790
+ callback(null, currentValue);
791
+ })
792
+ .on('set', (value, callback) => {
793
+ const enabled = normalizeBoolean(value);
794
+ if (enabled) {
795
+ this.sendOvenCommand();
796
+ setTimeout(() => {
797
+ this.startOvenSwitch.updateCharacteristic(this.platform.Characteristic.On, false);
798
+ }, ONE_SECOND_MS);
799
+ }
800
+ callback(null);
801
+ });
802
+ /////////Temperature Control
803
+ this.ovenTempControl = this.accessory.getService('Microwave Oven Temperature Control') ||
804
+ this.accessory.addService(this.platform.Service.Thermostat, 'Microwave Oven Temperature Control', 'NicoCataGaTa-OvenTC')
805
+ .setCharacteristic(this.platform.Characteristic.Name, 'Microwave Oven Temperature Control')
806
+ .setCharacteristic(this.platform.Characteristic.CurrentHeatingCoolingState, this.currentHeatingState())
807
+ .setCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits, 1);
808
+ this.ovenTempControl.addOptionalCharacteristic(this.platform.Characteristic.ConfiguredName);
809
+ this.ovenTempControl.setCharacteristic(this.platform.Characteristic.ConfiguredName, 'Microwave Oven Temperature Control');
810
+ this.ovenTempControl.getCharacteristic(this.platform.Characteristic.TargetHeatingCoolingState)
811
+ .setProps({ validValues: [this.platform.Characteristic.TargetHeatingCoolingState.OFF, this.platform.Characteristic.TargetHeatingCoolingState.HEAT] })
812
+ .on('get', (callback) => {
813
+ const currentValue = this.targetHeatingState();
814
+ callback(null, currentValue);
815
+ })
816
+ .on('set', (value, callback) => {
817
+ const enabled = normalizeBoolean(value);
818
+ if (!enabled) {
819
+ this.stopOven();
820
+ }
821
+ else {
822
+ this.pauseUpdate = true;
823
+ }
824
+ callback(null);
825
+ });
826
+ this.ovenTempControl.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
827
+ .setProps({
828
+ minValue: 10,
829
+ maxValue: 233,
830
+ minStep: 0.5,
831
+ })
832
+ .on('get', (callback) => {
833
+ const currentValue = this.ovenCurrentTemperature();
834
+ callback(null, currentValue);
835
+ });
836
+ this.ovenTempControl.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity)
837
+ .on('get', (callback) => {
838
+ const currentValue = this.localHumidity;
839
+ callback(null, currentValue);
840
+ });
841
+ this.ovenTempControl.getCharacteristic(this.platform.Characteristic.TargetTemperature)
842
+ .setProps({
843
+ minValue: 38,
844
+ maxValue: 233,
845
+ minStep: 0.5,
846
+ })
847
+ .on('get', (callback) => {
848
+ const currentValue = this.ovenTargetTemperature();
849
+ callback(null, currentValue);
850
+ })
851
+ .on('set', (value, callback) => {
852
+ const vNum = normalizeNumber(value);
853
+ if (vNum === null) {
854
+ this.logger.error('TargetTemperature is not a number');
855
+ callback();
856
+ return;
857
+ }
858
+ if (this.Status.data?.LWOTargetTemperatureUnit?.includes('FAH')) {
859
+ this.ovenCommandList.ovenSetTemperature = Math.round(this.tempCtoF(vNum) / 5) * 5;
860
+ }
861
+ else {
862
+ this.ovenCommandList.ovenSetTemperature = Math.round(vNum / 5) * 5;
863
+ }
864
+ callback(null);
865
+ });
866
+ }
867
+ //////////////////
868
+ async timeModeCommand() {
869
+ const ctrlKey = 'SetPreference';
870
+ const device = this.accessory.context.device;
871
+ try {
872
+ await this.platform.ThinQ?.deviceControl(device, {
873
+ dataKey: null,
874
+ dataValue: null,
875
+ dataSetList: {
876
+ ovenState: {
877
+ 'cmdOptionContentsType': 'REMOTE_SETTING',
878
+ 'cmdOptionDataLength': 'REMOTE_SETTING',
879
+ 'mwoSettingClockSetTimeHour': 128,
880
+ 'mwoSettingClockSetTimeMin': 128,
881
+ 'mwoSettingClockSetHourMode': '24H_MODE',
882
+ 'mwoSettingSound': 'NOT_SET',
883
+ 'mwoSettingClockDisplay': 'NOT_SET',
884
+ 'mwoSettingDisplayScrollSpeed': 'SLOW',
885
+ 'mwoSettingDefrostWeightMode': 'NOT_SET',
886
+ 'mwoSettingDemoMode': 'NOT_SET',
887
+ },
888
+ },
889
+ dataGetList: null,
890
+ }, 'Set', ctrlKey);
891
+ }
892
+ catch (error) {
893
+ this.logger.error('Error sending time mode command:', error);
894
+ }
895
+ }
896
+ async sendLightVentCommand() {
897
+ this.logger.debug('Fan Speed: ' + this.ventSpeed + ' Light: ' + this.lampLevel);
898
+ const ctrlKey = 'setVentLampLevel';
899
+ const device = this.accessory.context.device;
900
+ try {
901
+ await this.platform.ThinQ?.deviceControl(device, {
902
+ dataKey: null,
903
+ dataValue: null,
904
+ dataSetList: {
905
+ ovenState: {
906
+ 'cmdOptionContentsType': 'REMOTE_VENT_LAMP',
907
+ 'cmdOptionDataLength': 'REMOTE_VENT_LAMP',
908
+ 'mwoVentOnOff': this.ventSpeed > 0 ? 'ENABLE' : 'DISABLE',
909
+ 'mwoVentSpeedLevel': this.ventSpeed,
910
+ 'mwoLampOnOff': this.lampLevel > 0 ? 'ENABLE' : 'DISABLE',
911
+ 'mwoLampLevel': this.lampLevel,
912
+ },
913
+ },
914
+ dataGetList: null,
915
+ }, 'Set', ctrlKey);
916
+ }
917
+ catch (error) {
918
+ this.logger.error('Error sending light/vent command:', error);
919
+ }
920
+ }
921
+ async sendTimerCommand(time) {
922
+ if (!this.waitingForCommand) {
923
+ this.logger.debug('Alarm Set to: ' + this.secondsToTime(time));
924
+ const ctrlKey = 'SetTimer';
925
+ const device = this.accessory.context.device;
926
+ try {
927
+ await this.platform.ThinQ?.deviceControl(device, {
928
+ dataKey: null,
929
+ dataValue: null,
930
+ dataSetList: {
931
+ ovenState: {
932
+ 'cmdOptionContentsType': 'TIMER',
933
+ 'cmdOptionDataLength': 'TIMER',
934
+ 'lowerTimerHour': 128,
935
+ 'lowerTimerMinute': 128,
936
+ 'lowerTimerSecond': 128,
937
+ 'upperTimerHour': 0,
938
+ 'upperTimerMinute': Math.floor(time / 60),
939
+ 'upperTimerSecond': Math.floor(time % 60),
940
+ },
941
+ },
942
+ dataGetList: null,
943
+ }, 'Set', ctrlKey);
944
+ }
945
+ catch (error) {
946
+ this.logger.error('Error sending timer command:', error);
947
+ }
948
+ this.waitingForCommand = true;
949
+ setTimeout(() => {
950
+ this.pauseUpdate = false;
951
+ this.firstPause = true;
952
+ }, TEN_SECONDS_MS);
953
+ }
954
+ setTimeout(() => {
955
+ this.waitingForCommand = false;
956
+ }, 1000);
957
+ }
958
+ async sendOvenCommand() {
959
+ if (!this.monitorOnly) {
960
+ if (!this.waitingForCommand) {
961
+ this.pauseUpdate = true;
962
+ this.ovenCommandList.tempUnits = this.Status.data?.LWOTargetTemperatureUnit;
963
+ this.ovenCommandList.microwavePower = this.mwPower.toString();
964
+ if (this.ovenCommandList.ovenMode === 'NONE') {
965
+ this.ovenCommandList.ovenMode = 'WARM';
966
+ }
967
+ if (this.ovenCommandList.ovenSetDuration === 0) {
968
+ this.ovenCommandList.ovenSetDuration = 300;
969
+ }
970
+ const isBakeOrOven = this.ovenCommandList.ovenMode.includes('COMBI_BAKE')
971
+ || this.ovenCommandList.ovenMode.includes('CONV_BAKE')
972
+ || this.ovenCommandList.ovenMode.includes('COMBI_ROAST')
973
+ || this.ovenCommandList.ovenMode.includes('OVEN');
974
+ if (isBakeOrOven) {
975
+ if (this.ovenCommandList.tempUnits.includes('FAH')) {
976
+ if (this.ovenCommandList.ovenSetTemperature < 250) {
977
+ this.ovenCommandList.ovenSetTemperature = 250;
978
+ }
979
+ if (this.ovenCommandList.ovenSetTemperature > 450) {
980
+ this.ovenCommandList.ovenSetTemperature = 450;
981
+ }
982
+ }
983
+ else {
984
+ if (this.ovenCommandList.ovenSetTemperature < 125) {
985
+ this.ovenCommandList.ovenSetTemperature = 125;
986
+ }
987
+ if (this.ovenCommandList.ovenSetTemperature > 230) {
988
+ this.ovenCommandList.ovenSetTemperature = 230;
989
+ }
990
+ }
991
+ if (this.ovenCommandList.ovenMode.includes('COMBI_BAKE')) {
992
+ this.ovenCommandList.subCookNumber = 82;
993
+ this.ovenCommandList.microwavePower = '10';
994
+ this.ovenCommandList.targetWeight = 0;
995
+ this.ovenCommandList.weightUnits = 'KG';
996
+ }
997
+ if (this.ovenCommandList.ovenMode.includes('COMBI_ROAST')) {
998
+ this.ovenCommandList.subCookNumber = 82;
999
+ this.ovenCommandList.microwavePower = '30';
1000
+ this.ovenCommandList.targetWeight = 0;
1001
+ this.ovenCommandList.weightUnits = 'LBS';
1002
+ }
1003
+ if (this.ovenCommandList.ovenMode.includes('CONV_BAKE') || this.ovenCommandList.ovenMode.includes('OVEN')) {
1004
+ this.ovenCommandList.subCookNumber = 0;
1005
+ this.ovenCommandList.microwavePower = '100';
1006
+ this.ovenCommandList.targetWeight = 0;
1007
+ this.ovenCommandList.weightUnits = 'LBS';
1008
+ }
1009
+ }
1010
+ else if (this.ovenCommandList.ovenMode.includes('DEHYDRATE')) {
1011
+ if (this.ovenCommandList.tempUnits.includes('FAH')) {
1012
+ if (this.ovenCommandList.ovenSetTemperature < 100) {
1013
+ this.ovenCommandList.ovenSetTemperature = 100;
1014
+ }
1015
+ if (this.ovenCommandList.ovenSetTemperature > 200) {
1016
+ this.ovenCommandList.ovenSetTemperature = 200;
1017
+ }
1018
+ }
1019
+ else {
1020
+ if (this.ovenCommandList.ovenSetTemperature < 38) {
1021
+ this.ovenCommandList.ovenSetTemperature = 38;
1022
+ }
1023
+ if (this.ovenCommandList.ovenSetTemperature > 92) {
1024
+ this.ovenCommandList.ovenSetTemperature = 92;
1025
+ }
1026
+ }
1027
+ this.ovenCommandList.subCookNumber = 0;
1028
+ this.ovenCommandList.microwavePower = '100';
1029
+ this.ovenCommandList.targetWeight = 0;
1030
+ this.ovenCommandList.weightUnits = 'LBS';
1031
+ }
1032
+ else if (this.ovenCommandList.ovenMode.includes('PROOF')) {
1033
+ this.ovenCommandList.subCookNumber = 0;
1034
+ this.ovenCommandList.microwavePower = '100';
1035
+ this.ovenCommandList.ovenSetTemperature = 0;
1036
+ this.ovenCommandList.targetWeight = 0;
1037
+ this.ovenCommandList.weightUnits = 'KG';
1038
+ }
1039
+ else if (this.ovenCommandList.ovenMode.includes('MICROWAVE')) {
1040
+ this.ovenCommandList.subCookNumber = 0;
1041
+ if (this.mwPower === 0) {
1042
+ this.ovenCommandList.microwavePower = '100';
1043
+ }
1044
+ else {
1045
+ this.ovenCommandList.microwavePower = this.mwPower.toString();
1046
+ }
1047
+ this.ovenCommandList.ovenSetTemperature = 0;
1048
+ this.ovenCommandList.targetWeight = 0;
1049
+ }
1050
+ else if (this.ovenCommandList.ovenMode.includes('AIRFRY')) {
1051
+ this.ovenCommandList.ovenMode = 'AUTO_COOK';
1052
+ this.ovenCommandList.subCookNumber = 0;
1053
+ this.ovenCommandList.ovenSetDuration = 0;
1054
+ this.ovenCommandList.microwavePower = '100';
1055
+ this.ovenCommandList.ovenSetTemperature = 0;
1056
+ this.ovenCommandList.targetWeight = 0;
1057
+ }
1058
+ else if (this.ovenCommandList.ovenMode.includes('INVERTER_DEFROST')) {
1059
+ this.ovenCommandList.subCookNumber = 211;
1060
+ this.ovenCommandList.ovenSetDuration = 0;
1061
+ this.ovenCommandList.microwavePower = 'NONE';
1062
+ this.ovenCommandList.ovenSetTemperature = 0;
1063
+ this.ovenCommandList.targetWeight = 300;
1064
+ }
1065
+ else if (this.ovenCommandList.ovenMode.includes('TIME_DEFROST')) {
1066
+ this.ovenCommandList.subCookNumber = 0;
1067
+ this.ovenCommandList.microwavePower = '100';
1068
+ this.ovenCommandList.ovenSetTemperature = 0;
1069
+ this.ovenCommandList.targetWeight = 0;
1070
+ this.ovenCommandList.weightUnits = 'KG';
1071
+ }
1072
+ else if (this.ovenCommandList.ovenMode.includes('WARM')) {
1073
+ this.ovenCommandList = {
1074
+ ovenMode: 'WARM',
1075
+ ovenSetTemperature: 0,
1076
+ tempUnits: this.Status.data?.LWOTargetTemperatureUnit,
1077
+ ovenSetDuration: 0,
1078
+ subCookNumber: 0,
1079
+ weightUnits: 'KG',
1080
+ microwavePower: '100',
1081
+ targetWeight: 0,
1082
+ };
1083
+ }
1084
+ const debugMsg = 'Sending the Folowing Commands to the Microwave: ' + JSON.stringify(this.ovenCommandList);
1085
+ this.logger.debug(debugMsg);
1086
+ const isDehydrateOrProof = this.ovenCommandList.ovenMode.includes('DEHYDRATE')
1087
+ || this.ovenCommandList.ovenMode.includes('PROOF');
1088
+ const ctrlKey = 'SetCookStart';
1089
+ const device = this.accessory.context.device;
1090
+ try {
1091
+ if (isDehydrateOrProof) {
1092
+ await this.platform.ThinQ?.deviceControl(device.id, {
1093
+ dataKey: null,
1094
+ dataValue: null,
1095
+ dataSetList: {
1096
+ ovenState: {
1097
+ 'cmdOptionContentsType': 'REMOTE_COOK_START',
1098
+ 'cmdOptionDataLength': 'REMOTE_COOK_START',
1099
+ 'cmdOptionSetCookName': this.ovenCommandList.ovenMode,
1100
+ 'cmdOptionSetReserved': 0,
1101
+ 'cmdOptionSetSubCookNumber': this.ovenCommandList.subCookNumber,
1102
+ 'cmdOptionSetTargetTemperatureUnit': this.ovenCommandList.tempUnits,
1103
+ 'cmdOptionSetTargetTimeHour': Math.floor(this.ovenCommandList.ovenSetDuration / ONE_HOUR_IN_SECONDS),
1104
+ 'cmdOptionSetTargetTimeMinute': Math.floor(this.ovenCommandList.ovenSetDuration % ONE_HOUR_IN_SECONDS / 60),
1105
+ 'cmdOptionSetTargetTimeSecond': Math.floor(this.ovenCommandList.ovenSetDuration % 60),
1106
+ 'cmdOptionSetWeightUnit': this.ovenCommandList.weightUnits,
1107
+ 'cmdOptionStep': 0,
1108
+ 'setMwoPowerLevel': this.ovenCommandList.microwavePower,
1109
+ 'setTargetSteamLevel': 'NONE',
1110
+ 'setTargetTemp': this.ovenCommandList.ovenSetTemperature,
1111
+ 'setTargetTempLevel': this.ovenCommandList.ovenMode === 'WARM' ? 'HIGH' : 0,
1112
+ 'setTargetWeight': this.ovenCommandList.targetWeight,
1113
+ 'setWarmType': 'NONE',
1114
+ },
1115
+ },
1116
+ dataGetList: null,
1117
+ }, 'Set', ctrlKey);
1118
+ }
1119
+ else {
1120
+ await this.platform.ThinQ?.deviceControl(device.id, {
1121
+ dataKey: null,
1122
+ dataValue: null,
1123
+ dataSetList: {
1124
+ ovenState: {
1125
+ 'cmdOptionContentsType': 'REMOTE_COOK_START',
1126
+ 'cmdOptionDataLength': 'REMOTE_COOK_START',
1127
+ 'cmdOptionSetCookName': this.ovenCommandList.ovenMode,
1128
+ 'cmdOptionSetReserved': 0,
1129
+ 'cmdOptionSetSubCookNumber': this.ovenCommandList.subCookNumber,
1130
+ 'cmdOptionSetTargetTemperatureUnit': this.ovenCommandList.tempUnits,
1131
+ 'cmdOptionSetTargetTimeHour': 0,
1132
+ 'cmdOptionSetTargetTimeMinute': Math.floor(this.ovenCommandList.ovenSetDuration / 60),
1133
+ 'cmdOptionSetTargetTimeSecond': Math.floor(this.ovenCommandList.ovenSetDuration % 60),
1134
+ 'cmdOptionSetWeightUnit': this.ovenCommandList.weightUnits,
1135
+ 'cmdOptionStep': 0,
1136
+ 'setMwoPowerLevel': this.ovenCommandList.microwavePower,
1137
+ 'setTargetSteamLevel': 'NONE',
1138
+ 'setTargetTemp': this.ovenCommandList.ovenSetTemperature,
1139
+ 'setTargetTempLevel': this.ovenCommandList.ovenMode === 'WARM' ? 'HIGH' : 0,
1140
+ 'setTargetWeight': this.ovenCommandList.targetWeight,
1141
+ 'setWarmType': 'NONE',
1142
+ },
1143
+ },
1144
+ dataGetList: null,
1145
+ }, 'Set', ctrlKey);
1146
+ }
1147
+ }
1148
+ catch (error) {
1149
+ this.logger.error('Error sending oven command:', error);
1150
+ }
1151
+ this.waitingForCommand = true;
1152
+ setTimeout(() => {
1153
+ this.pauseUpdate = false;
1154
+ this.firstPause = true;
1155
+ }, TEN_SECONDS_MS);
1156
+ }
1157
+ setTimeout(() => {
1158
+ this.waitingForCommand = false;
1159
+ }, ONE_SECOND_MS);
1160
+ }
1161
+ }
1162
+ async stopOven() {
1163
+ if (!this.monitorOnly) {
1164
+ if (!this.waitingForCommand) {
1165
+ this.pauseUpdate = true;
1166
+ this.logger.debug('Stop Command Sent to Microwave');
1167
+ const ctrlKey = 'SetCookStop';
1168
+ const device = this.accessory.context.device;
1169
+ try {
1170
+ await this.platform.ThinQ?.deviceControl(device.id, {
1171
+ dataKey: null,
1172
+ dataValue: null,
1173
+ dataSetList: {
1174
+ ovenState: {
1175
+ 'cmdOptionCookStop': 'UPPER',
1176
+ },
1177
+ },
1178
+ dataGetList: null,
1179
+ }, 'Set', ctrlKey);
1180
+ }
1181
+ catch (error) {
1182
+ this.logger.error('Error stopping microwave:', error);
1183
+ }
1184
+ this.waitingForCommand = true;
1185
+ setTimeout(() => {
1186
+ this.pauseUpdate = false;
1187
+ this.firstPause = true;
1188
+ }, TEN_SECONDS_MS);
1189
+ }
1190
+ setTimeout(() => {
1191
+ this.waitingForCommand = false;
1192
+ }, ONE_SECOND_MS);
1193
+ }
1194
+ }
1195
+ setActive() {
1196
+ this.logger.debug('Microwave Response: ', this.Status.data);
1197
+ // this.platform.log('Oven Response 2', this.Status.deviceModel.DeviceModel.data.ControlWifi);
1198
+ // this.platform.log('Oven Response 3', this.Status.deviceModel.DeviceModel.data.UpperManualCook);
1199
+ //this.platform.log('Oven Response 4', this.Status.deviceModel.DeviceModel.data.Monitoring);
1200
+ // this.platform.log('Dishwasher rinse', this.Status.data.rinseLevel);
1201
+ // this.platform.log('Dishwasher rinse typeof', typeof this.Status.data.rinseLevel);
1202
+ //this.updateRinseLevel();
1203
+ // this.platform.log('Dishwasher rinse status', this.rinseStatus);
1204
+ // this.serviceDishwasher.updateCharacteristic(this.platform.Characteristic.StatusFault, this.rinseStatus);
1205
+ // this.platform.log('Dishwasher Response', this.Status);
1206
+ // throw new this.platform.api.hap.HapStatusError(-70412 /* this.platform.api.hap.HAPStatus.NOT_ALLOWED_IN_CURRENT_STATE */);
1207
+ }
1208
+ onStatus() {
1209
+ if (!this.Status.data?.LWOState?.includes('INITIAL')) {
1210
+ return true;
1211
+ }
1212
+ else {
1213
+ return false;
1214
+ }
1215
+ }
1216
+ lightVentState() {
1217
+ if (!this.Status.data?.LWOState?.includes('INITIAL') || this.Status.data?.mwoVentSpeedLevel !== 0 || this.Status.data?.mwoLampLevel !== 0) {
1218
+ return true;
1219
+ }
1220
+ else {
1221
+ return false;
1222
+ }
1223
+ }
1224
+ nameLengthCheck(newName) {
1225
+ if (newName.length >= 64) {
1226
+ newName = newName.slice(0, 60) + '...';
1227
+ }
1228
+ return newName;
1229
+ }
1230
+ secondsToTime(seconds) {
1231
+ const h = Math.floor(seconds / ONE_HOUR_IN_SECONDS);
1232
+ const m = Math.floor(seconds % ONE_HOUR_IN_SECONDS / 60);
1233
+ const s = Math.floor(seconds % 60);
1234
+ return h + ':' + m + ':' + s + ' Hours';
1235
+ }
1236
+ remainTime() {
1237
+ let remainingDuration = 0;
1238
+ if (typeof this.Status.data?.LWORemainTimeHour !== 'undefined') {
1239
+ remainingDuration += this.Status.data?.LWORemainTimeHour * ONE_HOUR_IN_SECONDS;
1240
+ }
1241
+ if (typeof this.Status.data?.LWORemainTimeMinute !== 'undefined') {
1242
+ remainingDuration += this.Status.data?.LWORemainTimeMinute * 60;
1243
+ }
1244
+ if (typeof this.Status.data?.LWORemainTimeSecond !== 'undefined') {
1245
+ remainingDuration += this.Status.data?.LWORemainTimeSecond;
1246
+ }
1247
+ return remainingDuration;
1248
+ }
1249
+ ovenModeName() {
1250
+ this.inputNameMode = 'Microwave Mode: ';
1251
+ switch (this.Status.data?.LWOManualCookName) {
1252
+ case 'STANDBY':
1253
+ this.inputNameMode += 'Standby';
1254
+ break;
1255
+ case 'MICROWAVE':
1256
+ this.inputNameMode += 'Microwave';
1257
+ break;
1258
+ case 'GRILL':
1259
+ this.inputNameMode += 'Grill';
1260
+ break;
1261
+ case 'OVEN':
1262
+ this.inputNameMode += 'Oven';
1263
+ break;
1264
+ case 'COMBI':
1265
+ this.inputNameMode += 'Combination';
1266
+ break;
1267
+ case 'COMBI_BAKE':
1268
+ this.inputNameMode += 'Combination Bake';
1269
+ break;
1270
+ case 'COMBI_ROAST':
1271
+ this.inputNameMode += 'Combination Roast';
1272
+ break;
1273
+ case 'INVERTER_DEFROST':
1274
+ this.inputNameMode += 'Inverter Defrost';
1275
+ break;
1276
+ case 'AUTO_COOK':
1277
+ this.inputNameMode += 'Air Fry';
1278
+ break;
1279
+ case 'AIRFRY':
1280
+ this.inputNameMode += 'Air Fry';
1281
+ break;
1282
+ case 'WARM':
1283
+ this.inputNameMode += 'Warm';
1284
+ break;
1285
+ case 'CONV_BAKE':
1286
+ this.inputNameMode += 'Convection Bake';
1287
+ break;
1288
+ case 'BROIL':
1289
+ this.inputNameMode += 'Broil';
1290
+ break;
1291
+ case 'DEHYDRATE':
1292
+ this.inputNameMode += 'Dehydrate';
1293
+ break;
1294
+ case 'SPEED_CONV':
1295
+ this.inputNameMode += 'Speed Convection';
1296
+ break;
1297
+ case 'SPEED_ROAST':
1298
+ this.inputNameMode += 'Speed Roast';
1299
+ break;
1300
+ case 'SPEED_BROIL':
1301
+ this.inputNameMode += 'Speed Broil';
1302
+ break;
1303
+ case 'PROOF':
1304
+ this.inputNameMode += 'Proof';
1305
+ break;
1306
+ case 'SENSOR_COOK':
1307
+ this.inputNameMode += 'Sensor Cook';
1308
+ break;
1309
+ case 'TIME_DEFROST':
1310
+ this.inputNameMode += 'Timed Defrost';
1311
+ break;
1312
+ default:
1313
+ // eslint-disable-next-line no-case-declarations
1314
+ let cookName = this.Status.data?.LWOManualCookName;
1315
+ cookName = cookName.toLocaleLowerCase();
1316
+ // eslint-disable-next-line no-case-declarations
1317
+ const cookNameCap = cookName.charAt(0).toUpperCase()
1318
+ + cookName.slice(1);
1319
+ this.inputNameMode += cookNameCap;
1320
+ }
1321
+ if (!this.inputNameMode.includes('Standby')) {
1322
+ this.inputNameMode = this.OvenSubCookMenu(this.inputNameMode);
1323
+ }
1324
+ return this.nameLengthCheck(this.inputNameMode);
1325
+ }
1326
+ ovenStatus() {
1327
+ this.inputNameStatus = 'Microwave is ';
1328
+ switch (this.Status.data?.LWOState) {
1329
+ case 'INITIAL':
1330
+ this.inputNameStatus += 'in Standby';
1331
+ break;
1332
+ case 'PREHEATING':
1333
+ this.inputNameStatus += 'Preheating';
1334
+ break;
1335
+ case 'COOKING_IN_PROGRESS':
1336
+ this.inputNameStatus += 'Cooking';
1337
+ break;
1338
+ case 'DONE':
1339
+ this.inputNameStatus += 'Done Baking';
1340
+ break;
1341
+ case 'COOLING':
1342
+ this.inputNameStatus += 'Cooling Down';
1343
+ break;
1344
+ case 'CLEANING':
1345
+ this.inputNameStatus += 'Cleaning Itself';
1346
+ break;
1347
+ case 'CLEANING_DONE':
1348
+ this.inputNameStatus += 'Done Cleaning Itself';
1349
+ break;
1350
+ case 'PAUSED':
1351
+ this.inputNameStatus += 'Paused';
1352
+ break;
1353
+ case 'PREFERENCE':
1354
+ this.inputNameStatus += 'Preference';
1355
+ break;
1356
+ case 'ERROR':
1357
+ this.inputNameStatus += 'Not Working';
1358
+ break;
1359
+ case 'READY_TO_START':
1360
+ this.inputNameStatus += 'Ready To Start';
1361
+ break;
1362
+ case 'PREHEATING_IS_DONE':
1363
+ this.inputNameStatus += 'Done Preheating';
1364
+ break;
1365
+ default:
1366
+ // eslint-disable-next-line no-case-declarations
1367
+ let stateName = this.Status.data?.LWOState;
1368
+ stateName = stateName.toLocaleLowerCase();
1369
+ // eslint-disable-next-line no-case-declarations
1370
+ const stateNameCap = stateName.charAt(0).toUpperCase()
1371
+ + stateName.slice(1);
1372
+ this.inputNameStatus += stateNameCap;
1373
+ }
1374
+ return this.nameLengthCheck(this.inputNameStatus);
1375
+ }
1376
+ ovenTemperature() {
1377
+ /////Current Temp
1378
+ let temperature = 'Microwave Oven Temperature Information';
1379
+ if (this.Status.data?.upperCurrentTemperatureValue !== 0) {
1380
+ temperature = 'Current Temp is ' + this.Status.data?.upperCurrentTemperatureValue + '°';
1381
+ }
1382
+ ////Set temperature
1383
+ if (this.Status.data?.LWOTargetTemperatureValue !== 0) {
1384
+ temperature += ' With Set Temp ' + this.Status.data?.LWOTargetTemperatureValue + '°';
1385
+ }
1386
+ ////Default
1387
+ if (this.Status.data.LWOTargetTemperatureValue === 0 && this.defaultTemp !== 0 && this.Status.data.upperCurrentTemperatureValue === 0) {
1388
+ temperature += 'Current Temp is ' + this.defaultTemp + '°' + ' With Set Temp ' + this.defaultTemp + '°';
1389
+ }
1390
+ return this.nameLengthCheck(temperature);
1391
+ }
1392
+ ovenCurrentTemperature() {
1393
+ /////Current Temp
1394
+ if (this.Status.data?.upperCurrentTemperatureValue !== 0) {
1395
+ if (this.Status.data?.LWOTargetTemperatureUnit?.includes('FAH')) {
1396
+ return this.tempFtoC(this.Status.data?.upperCurrentTemperatureValue);
1397
+ }
1398
+ else {
1399
+ return 0.5 * Math.round(2 * this.Status.data?.upperCurrentTemperatureValue);
1400
+ }
1401
+ }
1402
+ else if (this.Status.data?.LWOTargetTemperatureValue !== 0) {
1403
+ if (this.Status.data?.LWOTargetTemperatureUnit?.includes('FAH')) {
1404
+ return this.tempFtoC(this.Status.data?.LWOTargetTemperatureValue);
1405
+ }
1406
+ else {
1407
+ return 0.5 * Math.round(2 * this.Status.data?.LWOTargetTemperatureValue);
1408
+ }
1409
+ }
1410
+ else if (this.Status.data?.LWOState?.includes('COOKING_IN_PROGRESS') && this.defaultTemp !== 0) {
1411
+ return this.tempFtoC(this.defaultTemp);
1412
+ }
1413
+ else if (this.Status.data?.LWOState?.includes('PREHEATING') && this.defaultTemp !== 0) {
1414
+ return this.tempFtoC(this.defaultTemp);
1415
+ }
1416
+ else {
1417
+ return this.localTemperature;
1418
+ }
1419
+ }
1420
+ ovenTargetTemperature() {
1421
+ ////Set temperature
1422
+ if (this.Status.data?.LWOTargetTemperatureValue !== 0) {
1423
+ if (this.Status.data?.LWOTargetTemperatureUnit?.includes('FAH')) {
1424
+ return this.tempFtoC(this.Status.data?.LWOTargetTemperatureValue);
1425
+ }
1426
+ else {
1427
+ return 0.5 * Math.round(2 * this.Status.data?.LWOTargetTemperatureValue);
1428
+ }
1429
+ }
1430
+ else if (this.Status.data?.LWOState?.includes('COOKING_IN_PROGRESS') && this.defaultTemp !== 0) {
1431
+ return this.tempFtoC(this.defaultTemp);
1432
+ }
1433
+ else if (this.Status.data?.LWOState?.includes('PREHEATING') && this.defaultTemp !== 0) {
1434
+ return this.tempFtoC(this.defaultTemp);
1435
+ }
1436
+ else {
1437
+ return 38;
1438
+ }
1439
+ }
1440
+ OvenSubCookMenu(name) {
1441
+ if (this.Status.data?.LWOSubCookName !==
1442
+ 0 && typeof this.Status.data?.LWOSubCookName !== 'undefined') {
1443
+ let subCookCap = '';
1444
+ switch (this.Status.data?.LWOSubCookName) {
1445
+ case 3335:
1446
+ subCookCap = 'Buffalo Wings';
1447
+ this.defaultTemp = 450;
1448
+ break;
1449
+ case 3212:
1450
+ subCookCap = 'Chicken Nuggets';
1451
+ this.defaultTemp = 450;
1452
+ break;
1453
+ case 3227:
1454
+ subCookCap = 'Chicken Tenders';
1455
+ this.defaultTemp = 450;
1456
+ break;
1457
+ case 3339:
1458
+ subCookCap = 'Fish Sticks';
1459
+ this.defaultTemp = 450;
1460
+ break;
1461
+ case 3253:
1462
+ subCookCap = 'French Fries';
1463
+ this.defaultTemp = 450;
1464
+ break;
1465
+ case 3345:
1466
+ subCookCap = 'Hash Brown Patties';
1467
+ this.defaultTemp = 450;
1468
+ break;
1469
+ case 3336:
1470
+ subCookCap = 'Mozzarella Sticks';
1471
+ this.defaultTemp = 450;
1472
+ break;
1473
+ case 3343:
1474
+ subCookCap = 'Popcorn Shrimp';
1475
+ this.defaultTemp = 450;
1476
+ break;
1477
+ case 3225:
1478
+ subCookCap = 'Potato Wedges';
1479
+ this.defaultTemp = 450;
1480
+ break;
1481
+ case 211:
1482
+ subCookCap = 'Meat';
1483
+ this.defaultTemp = 350;
1484
+ break;
1485
+ case 212:
1486
+ subCookCap = 'Poultry';
1487
+ this.defaultTemp = 425;
1488
+ break;
1489
+ case 213:
1490
+ subCookCap = 'Fish';
1491
+ this.defaultTemp = 400;
1492
+ break;
1493
+ case 214:
1494
+ subCookCap = 'Bread';
1495
+ this.defaultTemp = 400;
1496
+ break;
1497
+ default:
1498
+ subCookCap = 'Other Food';
1499
+ this.defaultTemp = 450;
1500
+ }
1501
+ return name + ' (' + subCookCap + ')';
1502
+ }
1503
+ return name;
1504
+ }
1505
+ oventTargetTime() {
1506
+ let setDuration = 0;
1507
+ if (typeof this.Status.data?.LWOTargetTimeHour !== 'undefined') {
1508
+ setDuration += this.Status.data?.LWOTargetTimeHour * ONE_HOUR_IN_SECONDS;
1509
+ }
1510
+ if (typeof this.Status.data?.LWOTargetTimeMinute !== 'undefined') {
1511
+ setDuration += this.Status.data?.LWOTargetTimeMinute * 60;
1512
+ }
1513
+ if (typeof this.Status.data?.LWOTargetTimeSecond !== 'undefined') {
1514
+ setDuration += this.Status.data?.LWOTargetTimeSecond;
1515
+ }
1516
+ return setDuration;
1517
+ }
1518
+ ovenTimerTime() {
1519
+ let remainTimer = 0;
1520
+ if (typeof this.Status.data?.LWOTimerHour !== 'undefined') {
1521
+ remainTimer += this.Status.data?.LWOTimerHour * ONE_HOUR_IN_SECONDS;
1522
+ }
1523
+ if (typeof this.Status.data?.LWOTimerMinute !== 'undefined') {
1524
+ remainTimer += this.Status.data?.LWOTimerMinute * 60;
1525
+ }
1526
+ if (typeof this.Status.data?.LWOTimerSecond !== 'undefined') {
1527
+ remainTimer += this.Status.data?.LWOTimerSecond;
1528
+ }
1529
+ return remainTimer;
1530
+ }
1531
+ tempCtoF(temp) {
1532
+ return Math.round(temp * 1.8 + 32);
1533
+ }
1534
+ tempFtoC(temp) {
1535
+ return 0.5 * Math.round(2 * (temp - 32) / 1.8);
1536
+ }
1537
+ //////////////////
1538
+ ovenCookingDuration() {
1539
+ /////Cycle duration
1540
+ const courseTime = new Date(0);
1541
+ courseTime.setSeconds(this.oventTargetTime());
1542
+ let courseTimeString = courseTime.toISOString().substr(11, 8);
1543
+ if (courseTimeString.startsWith('0')) {
1544
+ courseTimeString = courseTimeString.substring(1);
1545
+ }
1546
+ let hourMinutes = 'Minutes';
1547
+ if (this.oventTargetTime() > ONE_HOUR_IN_SECONDS) {
1548
+ hourMinutes = 'Hours';
1549
+ }
1550
+ if (this.oventTargetTime() === ONE_HOUR_IN_SECONDS) {
1551
+ hourMinutes = 'Hour';
1552
+ }
1553
+ return 'Duration: ' + courseTimeString + ' ' + hourMinutes;
1554
+ }
1555
+ ovenCookingTimer() {
1556
+ const courseTimer = new Date(0);
1557
+ courseTimer.setSeconds(this.ovenTimerTime());
1558
+ let courseTimerString = courseTimer.toISOString().substr(11, 8);
1559
+ if (courseTimerString.startsWith('0')) {
1560
+ courseTimerString = courseTimerString.substring(1);
1561
+ }
1562
+ let hourMinutes = 'Minutes';
1563
+ if (this.ovenTimerTime() > ONE_HOUR_IN_SECONDS) {
1564
+ hourMinutes = 'Hours';
1565
+ }
1566
+ if (this.ovenTimerTime() === ONE_HOUR_IN_SECONDS) {
1567
+ hourMinutes = 'Hour';
1568
+ }
1569
+ return 'Timer: ' + courseTimerString + ' ' + hourMinutes;
1570
+ }
1571
+ ovenCookingStartTime() {
1572
+ ////Starting time
1573
+ const courseStart = new Date();
1574
+ const newDate = courseStart.toLocaleString('en-US', {
1575
+ weekday: 'long',
1576
+ year: 'numeric',
1577
+ month: 'long',
1578
+ day: 'numeric',
1579
+ hour12: false,
1580
+ hour: 'numeric',
1581
+ minute: 'numeric',
1582
+ second: 'numeric',
1583
+ timeZoneName: 'short',
1584
+ });
1585
+ return 'Start: ' + newDate;
1586
+ }
1587
+ ovenCookingEndTime() {
1588
+ const courseCurrentTime = new Date();
1589
+ this.courseStartMS = courseCurrentTime.getTime();
1590
+ const dateEnd = new Date(this.oventTargetTime() * ONE_SECOND_MS + this.courseStartMS);
1591
+ const newEndDate = dateEnd.toLocaleString('en-US', {
1592
+ weekday: 'long',
1593
+ year: 'numeric',
1594
+ month: 'long',
1595
+ day: 'numeric',
1596
+ hour12: false,
1597
+ hour: 'numeric',
1598
+ minute: 'numeric',
1599
+ second: 'numeric',
1600
+ timeZoneName: 'short',
1601
+ });
1602
+ return 'End: ' + newEndDate;
1603
+ }
1604
+ oventOptions() {
1605
+ this.inputNameOptions = 'Settings: ';
1606
+ if (this.Status.data?.LWOTargetTemperatureUnit?.includes('FAH')) {
1607
+ this.inputNameOptions += 'Temp in °F';
1608
+ }
1609
+ else {
1610
+ this.inputNameOptions += 'Temp in °C';
1611
+ }
1612
+ if (!this.Status.data?.LWOSabbath?.includes('NOT')) {
1613
+ this.inputNameOptions += ', Sabbath On';
1614
+ }
1615
+ if (this.Status.data?.LWOControlLock?.includes('ENA')) {
1616
+ this.inputNameOptions += ', Control Lock';
1617
+ }
1618
+ return this.nameLengthCheck(this.inputNameOptions);
1619
+ }
1620
+ ///////////
1621
+ currentHeatingState() {
1622
+ if (this.Status.data?.upperCurrentTemperatureValue !== 0 || this.defaultTemp !== 0 || this.Status.data.LWOTargetTemperatureValue !== 0) {
1623
+ return 1;
1624
+ }
1625
+ else {
1626
+ return 0;
1627
+ }
1628
+ }
1629
+ targetHeatingState() {
1630
+ if (this.Status.data.LWOTargetTemperatureValue !== 0 || this.defaultTemp !== 0) {
1631
+ return 1;
1632
+ }
1633
+ else {
1634
+ return 0;
1635
+ }
1636
+ }
1637
+ updateOvenModeSwitch() {
1638
+ this.pauseUpdate = true;
1639
+ this.updateOvenModeSwitchNoPause();
1640
+ }
1641
+ updateOvenModeSwitchNoPause() {
1642
+ this.microwaveSwitch.updateCharacteristic(this.platform.Characteristic.On, this.ovenCommandList.ovenMode === 'MICROWAVE' ? true : false);
1643
+ this.combiBakeSwitch.updateCharacteristic(this.platform.Characteristic.On, this.ovenCommandList.ovenMode === 'COMBI_BAKE' ? true : false);
1644
+ this.dehydrateSwitch.updateCharacteristic(this.platform.Characteristic.On, this.ovenCommandList.ovenMode === 'DEHYDRATE' ? true : false);
1645
+ this.airFrySwitch.updateCharacteristic(this.platform.Characteristic.On, this.ovenCommandList.ovenMode === 'AIRFRY' ? true : false);
1646
+ this.proofSwitch.updateCharacteristic(this.platform.Characteristic.On, this.ovenCommandList.ovenMode === 'PROOF' ? true : false);
1647
+ this.warmModeSwitch.updateCharacteristic(this.platform.Characteristic.On, this.ovenCommandList.ovenMode === 'WARM' ? true : false);
1648
+ this.convectionBakeSwitch.updateCharacteristic(this.platform.Characteristic.On, this.ovenCommandList.ovenMode === 'CONV_BAKE' ? true : false);
1649
+ this.convectionRoastSwitch.updateCharacteristic(this.platform.Characteristic.On, this.ovenCommandList.ovenMode === 'COMBI_ROAST' ? true : false);
1650
+ this.defrostSwitch.updateCharacteristic(this.platform.Characteristic.On, this.ovenCommandList.ovenMode === 'INVERTER_DEFROST' ? true : false);
1651
+ this.frozenMealSwitch.updateCharacteristic(this.platform.Characteristic.On, this.ovenCommandList.ovenMode === 'TIME_DEFROST' ? true : false);
1652
+ }
1653
+ getOperationTime(timeInSeconds) {
1654
+ const newTime = new Date(0);
1655
+ newTime.setSeconds(timeInSeconds);
1656
+ const newTimeString = newTime.toLocaleTimeString();
1657
+ let hourMinutes = 'Minutes';
1658
+ if (timeInSeconds > ONE_HOUR_IN_SECONDS) {
1659
+ hourMinutes = 'Hours';
1660
+ }
1661
+ if (timeInSeconds === ONE_HOUR_IN_SECONDS) {
1662
+ hourMinutes = 'Hour';
1663
+ }
1664
+ return newTimeString + ' ' + hourMinutes;
1665
+ }
1666
+ lightVentStatus() {
1667
+ let lightVent = '';
1668
+ if (this.Status.data?.mwoLampLevel === 0) {
1669
+ lightVent = 'Light is Off';
1670
+ }
1671
+ else if (this.Status.data?.mwoLampLevel === 1) {
1672
+ lightVent = 'Light is set to Low';
1673
+ }
1674
+ else if (this.Status.data?.mwoLampLevel === 2) {
1675
+ lightVent = 'Light is set to High';
1676
+ }
1677
+ if (this.Status.data?.mwoVentSpeedLevel > 0) {
1678
+ lightVent += ' and Vent is set to Level ' + this.Status.data?.mwoVentSpeedLevel;
1679
+ }
1680
+ else {
1681
+ lightVent += ' and Vent is Off';
1682
+ }
1683
+ return lightVent;
1684
+ }
1685
+ ovenServiceActive() {
1686
+ if (this.Status.data?.LWOState?.includes('INITIAL') && this.Status.data?.mwoVentSpeedLevel === 0 && this.Status.data?.mwoLampLevel === 0) {
1687
+ return 0;
1688
+ }
1689
+ else {
1690
+ return 1;
1691
+ }
1692
+ }
1693
+ //////////////
1694
+ updateAccessoryCharacteristic(device) {
1695
+ super.updateAccessoryCharacteristic(device);
1696
+ //this.platform.log('Device Response', device)
1697
+ //const ovenState = device.snapshot.ovenState;
1698
+ //const isVentOn = ovenState['ventSet'] === device.deviceModel.lookupMonitorName('VentSet', '@CP_ENABLE_W');
1699
+ //const isLampOn = ovenState['lampSet'] === device.deviceModel.lookupMonitorName('LampSet', '@CP_ENABLE_W');
1700
+ const { Characteristic } = this.platform;
1701
+ //this.serviceHood.updateCharacteristic(Characteristic.On, isVentOn);
1702
+ // this.serviceHood.updateCharacteristic(Characteristic.RotationSpeed, ovenState['ventLevel']);
1703
+ //this.serviceLight.updateCharacteristic(Characteristic.On, isLampOn);
1704
+ // this.serviceLight.updateCharacteristic(Characteristic.Brightness, ovenState['lampLevel']);
1705
+ if (!this.pauseUpdate) {
1706
+ if (this.Status.data?.LWOState?.includes('INITIAL')) {
1707
+ this.defaultTemp = 0;
1708
+ }
1709
+ if (this.ovenService.getCharacteristic(this.platform.Characteristic.Active).value !== this.ovenServiceActive()) {
1710
+ this.ovenService.updateCharacteristic(this.platform.Characteristic.Active, this.ovenServiceActive());
1711
+ }
1712
+ if (this.ovenServiceActive() === 0) {
1713
+ this.ovenCommandList = {
1714
+ ovenMode: 'NONE',
1715
+ ovenSetTemperature: 0,
1716
+ tempUnits: this.Status.data?.LWOTargetTemperatureUnit,
1717
+ ovenSetDuration: 0,
1718
+ subCookNumber: 0,
1719
+ weightUnits: 'KG',
1720
+ microwavePower: '100',
1721
+ targetWeight: 0,
1722
+ };
1723
+ const anyModeOn = this.microwaveSwitch.getCharacteristic(this.platform.Characteristic.On).value === true
1724
+ || this.combiBakeSwitch.getCharacteristic(this.platform.Characteristic.On).value === true
1725
+ || this.dehydrateSwitch.getCharacteristic(this.platform.Characteristic.On).value === true
1726
+ || this.airFrySwitch.getCharacteristic(this.platform.Characteristic.On).value === true
1727
+ || this.proofSwitch.getCharacteristic(this.platform.Characteristic.On).value === true
1728
+ || this.warmModeSwitch.getCharacteristic(this.platform.Characteristic.On).value === true
1729
+ || this.convectionBakeSwitch.getCharacteristic(this.platform.Characteristic.On).value === true
1730
+ || this.convectionRoastSwitch.getCharacteristic(this.platform.Characteristic.On).value === true
1731
+ || this.defrostSwitch.getCharacteristic(this.platform.Characteristic.On).value === true
1732
+ || this.frozenMealSwitch.getCharacteristic(this.platform.Characteristic.On).value === true;
1733
+ if (anyModeOn) {
1734
+ this.updateOvenModeSwitch();
1735
+ }
1736
+ }
1737
+ ///// how to handle the time Here
1738
+ if (!this.Status.data?.LWOManualCookName.includes('STAND')) {
1739
+ if (this.firstStart) {
1740
+ this.courseStartString = this.ovenCookingStartTime();
1741
+ }
1742
+ this.showTime = true;
1743
+ this.ovenCommandList.ovenMode = this.Status.data?.LWOManualCookName;
1744
+ this.updateOvenModeSwitchNoPause();
1745
+ }
1746
+ else {
1747
+ this.firstStart = true;
1748
+ this.showTime = false;
1749
+ this.courseStartString = 'Microwave Start Time Not Set';
1750
+ }
1751
+ if (this.oventTargetTime() !== 0) {
1752
+ if (this.oventTargetTime() !== this.firstDuration) {
1753
+ this.firstDuration = this.oventTargetTime();
1754
+ this.courseTimeString = this.ovenCookingDuration();
1755
+ this.courseTimeEndString = this.ovenCookingEndTime();
1756
+ }
1757
+ this.showTime = true;
1758
+ }
1759
+ else {
1760
+ this.firstDuration = 0;
1761
+ this.courseTimeString = 'Microwave Cooking Time Not Set';
1762
+ this.courseTimeEndString = 'Microwave End Time Not Set';
1763
+ }
1764
+ if (this.ovenTimerTime() !== 0) {
1765
+ if (this.ovenTimerTime() !== this.firstTimer) {
1766
+ this.firstTimer = this.ovenTimerTime();
1767
+ this.courseTimerString = this.ovenCookingTimer();
1768
+ }
1769
+ this.showTimer = true;
1770
+ }
1771
+ else {
1772
+ this.firstTimer = 0;
1773
+ this.showTimer = false;
1774
+ this.courseTimerString = 'Microwave Cooking Timer Not Set';
1775
+ }
1776
+ ///////////////////
1777
+ if (this.ovenState.getCharacteristic(this.platform.Characteristic.ConfiguredName).value !== this.ovenStatus()) {
1778
+ this.ovenState.updateCharacteristic(this.platform.Characteristic.ConfiguredName, this.ovenStatus());
1779
+ }
1780
+ if (this.ovenMode.getCharacteristic(this.platform.Characteristic.ConfiguredName).value !== this.ovenModeName()) {
1781
+ this.ovenMode.updateCharacteristic(this.platform.Characteristic.ConfiguredName, this.ovenModeName());
1782
+ }
1783
+ if (this.lightVent.getCharacteristic(this.platform.Characteristic.ConfiguredName).value !== this.lightVentStatus()) {
1784
+ this.lightVent.updateCharacteristic(this.platform.Characteristic.ConfiguredName, this.lightVentStatus());
1785
+ }
1786
+ if (this.ovenTemp.getCharacteristic(this.platform.Characteristic.ConfiguredName).value !== this.ovenTemperature()) {
1787
+ this.ovenTemp.updateCharacteristic(this.platform.Characteristic.ConfiguredName, this.ovenTemperature());
1788
+ }
1789
+ if (this.ovenStart.getCharacteristic(this.platform.Characteristic.ConfiguredName).value !== this.nameLengthCheck(this.courseStartString)) {
1790
+ this.ovenStart.updateCharacteristic(this.platform.Characteristic.ConfiguredName, this.nameLengthCheck(this.courseStartString));
1791
+ }
1792
+ if (this.ovenTimer.getCharacteristic(this.platform.Characteristic.ConfiguredName).value !== this.nameLengthCheck(this.courseTimerString)) {
1793
+ this.ovenTimer.updateCharacteristic(this.platform.Characteristic.ConfiguredName, this.nameLengthCheck(this.courseTimerString));
1794
+ }
1795
+ if (this.ovenTime.getCharacteristic(this.platform.Characteristic.ConfiguredName).value !== this.nameLengthCheck(this.courseTimeString)) {
1796
+ this.ovenTime.updateCharacteristic(this.platform.Characteristic.ConfiguredName, this.nameLengthCheck(this.courseTimeString));
1797
+ }
1798
+ if (this.ovenEndTime.getCharacteristic(this.platform.Characteristic.ConfiguredName).value !== this.nameLengthCheck(this.courseTimeEndString)) {
1799
+ this.ovenEndTime.updateCharacteristic(this.platform.Characteristic.ConfiguredName, this.nameLengthCheck(this.courseTimeEndString));
1800
+ }
1801
+ if (this.ovenOptions.getCharacteristic(this.platform.Characteristic.ConfiguredName).value !== this.oventOptions()) {
1802
+ this.ovenOptions.updateCharacteristic(this.platform.Characteristic.ConfiguredName, this.oventOptions());
1803
+ }
1804
+ /////////////Show State
1805
+ const onStatusTargetVis = this.onStatus()
1806
+ ? this.platform.Characteristic.TargetVisibilityState.SHOWN
1807
+ : this.platform.Characteristic.TargetVisibilityState.HIDDEN;
1808
+ const onStatusCurrentVis = this.onStatus()
1809
+ ? this.platform.Characteristic.CurrentVisibilityState.SHOWN
1810
+ : this.platform.Characteristic.CurrentVisibilityState.HIDDEN;
1811
+ this.ovenMode.updateCharacteristic(this.platform.Characteristic.TargetVisibilityState, onStatusTargetVis);
1812
+ this.ovenMode.updateCharacteristic(this.platform.Characteristic.CurrentVisibilityState, onStatusCurrentVis);
1813
+ this.ovenTemp.updateCharacteristic(this.platform.Characteristic.TargetVisibilityState, onStatusTargetVis);
1814
+ this.ovenTemp.updateCharacteristic(this.platform.Characteristic.CurrentVisibilityState, onStatusCurrentVis);
1815
+ const lightVentTargetVis = this.lightVentState()
1816
+ ? this.platform.Characteristic.TargetVisibilityState.SHOWN
1817
+ : this.platform.Characteristic.TargetVisibilityState.HIDDEN;
1818
+ const lightVentCurrentVis = this.lightVentState()
1819
+ ? this.platform.Characteristic.CurrentVisibilityState.SHOWN
1820
+ : this.platform.Characteristic.CurrentVisibilityState.HIDDEN;
1821
+ this.lightVent.updateCharacteristic(this.platform.Characteristic.TargetVisibilityState, lightVentTargetVis);
1822
+ this.lightVent.updateCharacteristic(this.platform.Characteristic.CurrentVisibilityState, lightVentCurrentVis);
1823
+ this.ovenOptions.updateCharacteristic(this.platform.Characteristic.TargetVisibilityState, onStatusTargetVis);
1824
+ this.ovenOptions.updateCharacteristic(this.platform.Characteristic.CurrentVisibilityState, onStatusCurrentVis);
1825
+ const showTimeTargetVis = this.showTime
1826
+ ? this.platform.Characteristic.TargetVisibilityState.SHOWN
1827
+ : this.platform.Characteristic.TargetVisibilityState.HIDDEN;
1828
+ const showTimeCurrentVis = this.showTime
1829
+ ? this.platform.Characteristic.CurrentVisibilityState.SHOWN
1830
+ : this.platform.Characteristic.CurrentVisibilityState.HIDDEN;
1831
+ this.ovenStart.updateCharacteristic(this.platform.Characteristic.TargetVisibilityState, showTimeTargetVis);
1832
+ this.ovenStart.updateCharacteristic(this.platform.Characteristic.CurrentVisibilityState, showTimeCurrentVis);
1833
+ this.ovenTime.updateCharacteristic(this.platform.Characteristic.TargetVisibilityState, showTimeTargetVis);
1834
+ this.ovenTime.updateCharacteristic(this.platform.Characteristic.CurrentVisibilityState, showTimeCurrentVis);
1835
+ this.ovenEndTime.updateCharacteristic(this.platform.Characteristic.TargetVisibilityState, showTimeTargetVis);
1836
+ this.ovenEndTime.updateCharacteristic(this.platform.Characteristic.CurrentVisibilityState, showTimeCurrentVis);
1837
+ const showTimerTargetVis = this.showTimer
1838
+ ? this.platform.Characteristic.TargetVisibilityState.SHOWN
1839
+ : this.platform.Characteristic.TargetVisibilityState.HIDDEN;
1840
+ const showTimerCurrentVis = this.showTimer
1841
+ ? this.platform.Characteristic.CurrentVisibilityState.SHOWN
1842
+ : this.platform.Characteristic.CurrentVisibilityState.HIDDEN;
1843
+ this.ovenTimer.updateCharacteristic(this.platform.Characteristic.TargetVisibilityState, showTimerTargetVis);
1844
+ this.ovenTimer.updateCharacteristic(this.platform.Characteristic.CurrentVisibilityState, showTimerCurrentVis);
1845
+ /////////Temperature Monitor
1846
+ const tempDisplayUnits = this.Status.data?.LWOTargetTemperatureUnit?.includes('FAH') ? 1 : 0;
1847
+ if (this.ovenTempControl.getCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits).value !== tempDisplayUnits) {
1848
+ this.ovenTempControl.updateCharacteristic(this.platform.Characteristic.TemperatureDisplayUnits, tempDisplayUnits);
1849
+ }
1850
+ if (this.ovenTempControl.getCharacteristic(this.platform.Characteristic.CurrentTemperature).value !== this.ovenCurrentTemperature()) {
1851
+ this.ovenTempControl.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.ovenCurrentTemperature());
1852
+ }
1853
+ if (this.ovenTempControl.getCharacteristic(this.platform.Characteristic.TargetTemperature).value !== this.ovenTargetTemperature()) {
1854
+ this.ovenTempControl.updateCharacteristic(this.platform.Characteristic.TargetTemperature, this.ovenTargetTemperature());
1855
+ }
1856
+ if (this.ovenTempControl.getCharacteristic(this.platform.Characteristic.TargetHeatingCoolingState).value !== this.targetHeatingState()) {
1857
+ this.ovenTempControl.updateCharacteristic(this.platform.Characteristic.TargetHeatingCoolingState, this.targetHeatingState());
1858
+ }
1859
+ if (this.ovenTempControl.getCharacteristic(this.platform.Characteristic.CurrentHeatingCoolingState).value !== this.currentHeatingState()) {
1860
+ this.ovenTempControl.updateCharacteristic(this.platform.Characteristic.CurrentHeatingCoolingState, this.currentHeatingState());
1861
+ }
1862
+ if (this.ovenTempControl.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value !== this.localHumidity) {
1863
+ this.ovenTempControl.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.localHumidity);
1864
+ }
1865
+ const isPowerOn = safeParseInt(this.Status.data?.LWOMGTPowerLevel) > 0;
1866
+ if (this.microwavePower.getCharacteristic(this.platform.Characteristic.On).value !== isPowerOn) {
1867
+ this.microwavePower.updateCharacteristic(this.platform.Characteristic.On, isPowerOn);
1868
+ }
1869
+ if (this.microwavePower.getCharacteristic(this.platform.Characteristic.Brightness).value !== safeParseInt(this.Status.data?.LWOMGTPowerLevel)) {
1870
+ this.microwavePower.updateCharacteristic(this.platform.Characteristic.Brightness, safeParseInt(this.Status.data?.LWOMGTPowerLevel));
1871
+ }
1872
+ if (this.serviceLight.getCharacteristic(this.platform.Characteristic.On).value !== this.Status.data?.mwoLampLevel > 0 ? true : false) {
1873
+ this.serviceLight.updateCharacteristic(this.platform.Characteristic.On, this.Status.data?.mwoLampLevel > 0 ? true : false);
1874
+ }
1875
+ if (this.serviceLight.getCharacteristic(this.platform.Characteristic.Brightness).value !== this.Status.data?.mwoLampLevel) {
1876
+ this.serviceLight.updateCharacteristic(this.platform.Characteristic.Brightness, this.Status.data?.mwoLampLevel);
1877
+ }
1878
+ if (this.serviceHood.getCharacteristic(this.platform.Characteristic.Active).value !== this.Status.data?.mwoVentSpeedLevel > 0 ? 1 : 0) {
1879
+ this.serviceHood.updateCharacteristic(this.platform.Characteristic.Active, this.Status.data?.mwoVentSpeedLevel > 0 ? 1 : 0);
1880
+ }
1881
+ if (this.serviceHood.getCharacteristic(this.platform.Characteristic.RotationSpeed).value !== this.Status.data?.mwoVentSpeedLevel) {
1882
+ this.serviceHood.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.Status.data?.mwoVentSpeedLevel);
1883
+ }
1884
+ ///////Timer Monitor
1885
+ this.ovenTimerService.updateCharacteristic(this.platform.Characteristic.Active, this.remainTime() > 0 ? 1 : 0);
1886
+ if (this.oventTargetTime() === 0) {
1887
+ this.ovenTimerService.updateCharacteristic(this.platform.Characteristic.InUse, Characteristic.InUse.NOT_IN_USE);
1888
+ }
1889
+ else if (this.onStatus() && this.oventTargetTime() !== 0) {
1890
+ this.ovenTimerService.updateCharacteristic(this.platform.Characteristic.InUse, Characteristic.InUse.IN_USE);
1891
+ }
1892
+ if (this.ovenTimerService.getCharacteristic(this.platform.Characteristic.RemainingDuration).value !== this.remainTime()) {
1893
+ this.ovenTimerService.updateCharacteristic(this.platform.Characteristic.RemainingDuration, this.remainTime());
1894
+ }
1895
+ if (this.ovenTimerService.getCharacteristic(this.platform.Characteristic.SetDuration).value !== this.oventTargetTime()) {
1896
+ this.ovenTimerService.updateCharacteristic(this.platform.Characteristic.SetDuration, this.oventTargetTime());
1897
+ }
1898
+ this.ovenAlarmService.updateCharacteristic(Characteristic.Active, this.ovenTimerTime() > 0 ? 1 : 0);
1899
+ this.ovenAlarmService.updateCharacteristic(Characteristic.RemainingDuration, this.ovenTimerTime());
1900
+ this.ovenAlarmService.updateCharacteristic(Characteristic.InUse, this.ovenTimerTime() > 0 ? 1 : 0);
1901
+ }
1902
+ else {
1903
+ if (this.firstPause) {
1904
+ setTimeout(() => {
1905
+ this.pauseUpdate = false;
1906
+ this.firstPause = true;
1907
+ }, TWO_MINUTES_MS);
1908
+ this.firstPause = false;
1909
+ }
1910
+ }
1911
+ }
1912
+ update(snapshot) {
1913
+ super.update(snapshot);
1914
+ const oven = snapshot.oven;
1915
+ if (!oven) {
1916
+ return;
1917
+ }
1918
+ }
1919
+ get Status() {
1920
+ return new MicrowaveStatus(this.accessory.context.device.snapshot?.ovenState, this.accessory.context.device.deviceModel);
1921
+ }
1922
+ get config() {
1923
+ return Object.assign({}, {
1924
+ oven_trigger: false,
1925
+ }, super.config);
1926
+ }
1927
+ }
1928
+ export class MicrowaveStatus {
1929
+ data;
1930
+ deviceModel;
1931
+ constructor(data, deviceModel) {
1932
+ this.data = data;
1933
+ this.deviceModel = deviceModel;
1934
+ }
1935
+ getState(key) {
1936
+ return this.data[key + 'State'];
1937
+ }
1938
+ }
1939
+ //# sourceMappingURL=Microwave.js.map