@mp-consulting/homebridge-daikin-cloud 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 (202) hide show
  1. package/.claude/settings.json +3 -0
  2. package/.claude/settings.local.json +8 -0
  3. package/CLAUDE.md +34 -0
  4. package/LICENSE +176 -0
  5. package/README.md +180 -0
  6. package/changelog.md +217 -0
  7. package/config.md +2 -0
  8. package/config.schema.json +146 -0
  9. package/dist/src/accessories/air-conditioning-accessory.d.ts +9 -0
  10. package/dist/src/accessories/air-conditioning-accessory.d.ts.map +1 -0
  11. package/dist/src/accessories/air-conditioning-accessory.js +19 -0
  12. package/dist/src/accessories/air-conditioning-accessory.js.map +1 -0
  13. package/dist/src/accessories/altherma-accessory.d.ts +11 -0
  14. package/dist/src/accessories/altherma-accessory.d.ts.map +1 -0
  15. package/dist/src/accessories/altherma-accessory.js +31 -0
  16. package/dist/src/accessories/altherma-accessory.js.map +1 -0
  17. package/dist/src/accessories/base-accessory.d.ts +16 -0
  18. package/dist/src/accessories/base-accessory.d.ts.map +1 -0
  19. package/dist/src/accessories/base-accessory.js +56 -0
  20. package/dist/src/accessories/base-accessory.js.map +1 -0
  21. package/dist/src/accessories/index.d.ts +4 -0
  22. package/dist/src/accessories/index.d.ts.map +1 -0
  23. package/dist/src/accessories/index.js +20 -0
  24. package/dist/src/accessories/index.js.map +1 -0
  25. package/dist/src/api/daikin-cloud.repository.d.ts +4 -0
  26. package/dist/src/api/daikin-cloud.repository.d.ts.map +1 -0
  27. package/dist/src/api/daikin-cloud.repository.js +31 -0
  28. package/dist/src/api/daikin-cloud.repository.js.map +1 -0
  29. package/dist/src/api/index.d.ts +2 -0
  30. package/dist/src/api/index.d.ts.map +1 -0
  31. package/dist/src/api/index.js +18 -0
  32. package/dist/src/api/index.js.map +1 -0
  33. package/dist/src/device/accessory-factory.d.ts +36 -0
  34. package/dist/src/device/accessory-factory.d.ts.map +1 -0
  35. package/dist/src/device/accessory-factory.js +61 -0
  36. package/dist/src/device/accessory-factory.js.map +1 -0
  37. package/dist/src/device/capability-detector.d.ts +36 -0
  38. package/dist/src/device/capability-detector.d.ts.map +1 -0
  39. package/dist/src/device/capability-detector.js +130 -0
  40. package/dist/src/device/capability-detector.js.map +1 -0
  41. package/dist/src/device/capability-docs.d.ts +20 -0
  42. package/dist/src/device/capability-docs.d.ts.map +1 -0
  43. package/dist/src/device/capability-docs.js +98 -0
  44. package/dist/src/device/capability-docs.js.map +1 -0
  45. package/dist/src/device/index.d.ts +5 -0
  46. package/dist/src/device/index.d.ts.map +1 -0
  47. package/dist/src/device/index.js +21 -0
  48. package/dist/src/device/index.js.map +1 -0
  49. package/dist/src/device/profiles/device-profile.d.ts +42 -0
  50. package/dist/src/device/profiles/device-profile.d.ts.map +1 -0
  51. package/dist/src/device/profiles/device-profile.js +103 -0
  52. package/dist/src/device/profiles/device-profile.js.map +1 -0
  53. package/dist/src/device/profiles/index.d.ts +2 -0
  54. package/dist/src/device/profiles/index.d.ts.map +1 -0
  55. package/dist/src/device/profiles/index.js +18 -0
  56. package/dist/src/device/profiles/index.js.map +1 -0
  57. package/dist/src/features/base-feature.d.ts +65 -0
  58. package/dist/src/features/base-feature.d.ts.map +1 -0
  59. package/dist/src/features/base-feature.js +99 -0
  60. package/dist/src/features/base-feature.js.map +1 -0
  61. package/dist/src/features/feature-manager.d.ts +37 -0
  62. package/dist/src/features/feature-manager.d.ts.map +1 -0
  63. package/dist/src/features/feature-manager.js +68 -0
  64. package/dist/src/features/feature-manager.js.map +1 -0
  65. package/dist/src/features/index.d.ts +4 -0
  66. package/dist/src/features/index.d.ts.map +1 -0
  67. package/dist/src/features/index.js +20 -0
  68. package/dist/src/features/index.js.map +1 -0
  69. package/dist/src/features/modes/dry-operation-mode.feature.d.ts +16 -0
  70. package/dist/src/features/modes/dry-operation-mode.feature.d.ts.map +1 -0
  71. package/dist/src/features/modes/dry-operation-mode.feature.js +40 -0
  72. package/dist/src/features/modes/dry-operation-mode.feature.js.map +1 -0
  73. package/dist/src/features/modes/econo-mode.feature.d.ts +15 -0
  74. package/dist/src/features/modes/econo-mode.feature.d.ts.map +1 -0
  75. package/dist/src/features/modes/econo-mode.feature.js +37 -0
  76. package/dist/src/features/modes/econo-mode.feature.js.map +1 -0
  77. package/dist/src/features/modes/fan-only-operation-mode.feature.d.ts +16 -0
  78. package/dist/src/features/modes/fan-only-operation-mode.feature.d.ts.map +1 -0
  79. package/dist/src/features/modes/fan-only-operation-mode.feature.js +40 -0
  80. package/dist/src/features/modes/fan-only-operation-mode.feature.js.map +1 -0
  81. package/dist/src/features/modes/index.d.ts +8 -0
  82. package/dist/src/features/modes/index.d.ts.map +1 -0
  83. package/dist/src/features/modes/index.js +24 -0
  84. package/dist/src/features/modes/index.js.map +1 -0
  85. package/dist/src/features/modes/indoor-silent-mode.feature.d.ts +17 -0
  86. package/dist/src/features/modes/indoor-silent-mode.feature.d.ts.map +1 -0
  87. package/dist/src/features/modes/indoor-silent-mode.feature.js +47 -0
  88. package/dist/src/features/modes/indoor-silent-mode.feature.js.map +1 -0
  89. package/dist/src/features/modes/outdoor-silent-mode.feature.d.ts +15 -0
  90. package/dist/src/features/modes/outdoor-silent-mode.feature.d.ts.map +1 -0
  91. package/dist/src/features/modes/outdoor-silent-mode.feature.js +37 -0
  92. package/dist/src/features/modes/outdoor-silent-mode.feature.js.map +1 -0
  93. package/dist/src/features/modes/powerful-mode.feature.d.ts +15 -0
  94. package/dist/src/features/modes/powerful-mode.feature.d.ts.map +1 -0
  95. package/dist/src/features/modes/powerful-mode.feature.js +37 -0
  96. package/dist/src/features/modes/powerful-mode.feature.js.map +1 -0
  97. package/dist/src/features/modes/streamer-mode.feature.d.ts +15 -0
  98. package/dist/src/features/modes/streamer-mode.feature.d.ts.map +1 -0
  99. package/dist/src/features/modes/streamer-mode.feature.js +37 -0
  100. package/dist/src/features/modes/streamer-mode.feature.js.map +1 -0
  101. package/dist/src/index.d.ts +7 -0
  102. package/dist/src/index.d.ts.map +1 -0
  103. package/dist/src/index.js +7 -0
  104. package/dist/src/index.js.map +1 -0
  105. package/dist/src/platform.d.ts +33 -0
  106. package/dist/src/platform.d.ts.map +1 -0
  107. package/dist/src/platform.js +209 -0
  108. package/dist/src/platform.js.map +1 -0
  109. package/dist/src/services/climate-control.service.d.ts +43 -0
  110. package/dist/src/services/climate-control.service.d.ts.map +1 -0
  111. package/dist/src/services/climate-control.service.js +366 -0
  112. package/dist/src/services/climate-control.service.js.map +1 -0
  113. package/dist/src/services/hot-water-tank.service.d.ts +23 -0
  114. package/dist/src/services/hot-water-tank.service.d.ts.map +1 -0
  115. package/dist/src/services/hot-water-tank.service.js +214 -0
  116. package/dist/src/services/hot-water-tank.service.js.map +1 -0
  117. package/dist/src/services/index.d.ts +3 -0
  118. package/dist/src/services/index.d.ts.map +1 -0
  119. package/dist/src/services/index.js +19 -0
  120. package/dist/src/services/index.js.map +1 -0
  121. package/dist/src/settings.d.ts +9 -0
  122. package/dist/src/settings.d.ts.map +1 -0
  123. package/dist/src/settings.js +12 -0
  124. package/dist/src/settings.js.map +1 -0
  125. package/dist/src/types/daikin-enums.d.ts +61 -0
  126. package/dist/src/types/daikin-enums.d.ts.map +1 -0
  127. package/dist/src/types/daikin-enums.js +76 -0
  128. package/dist/src/types/daikin-enums.js.map +1 -0
  129. package/dist/src/types/device-capabilities.d.ts +47 -0
  130. package/dist/src/types/device-capabilities.d.ts.map +1 -0
  131. package/dist/src/types/device-capabilities.js +7 -0
  132. package/dist/src/types/device-capabilities.js.map +1 -0
  133. package/dist/src/types/index.d.ts +3 -0
  134. package/dist/src/types/index.d.ts.map +1 -0
  135. package/dist/src/types/index.js +19 -0
  136. package/dist/src/types/index.js.map +1 -0
  137. package/dist/src/utils/strings.d.ts +5 -0
  138. package/dist/src/utils/strings.d.ts.map +1 -0
  139. package/dist/src/utils/strings.js +22 -0
  140. package/dist/src/utils/strings.js.map +1 -0
  141. package/docs/Screenshot 2024-07-04 at 18.41.28.png +0 -0
  142. package/docs/api-response-for-BRP069A8x.json +520 -0
  143. package/docs/api-response-for-BRP069C4x-2.json +881 -0
  144. package/docs/api-response-for-BRP069C4x.json +916 -0
  145. package/docs/api-response-for-altherma.json +759 -0
  146. package/docs/api-response-for-altherma2.json +2735 -0
  147. package/docs/api-response-with-multiple-devices-incl-heatpump.json +2544 -0
  148. package/docs/cr-insance-altherma-id-0.json +834 -0
  149. package/docs/mock-air-to-air-dx23.json +759 -0
  150. package/docs/mock-air-to-air-dx4.json +1134 -0
  151. package/docs/mock-airpurifier-with-humidifier.json +732 -0
  152. package/docs/mock-airpurifier.json +450 -0
  153. package/docs/mock-altherma-air-to-water-lan.json +845 -0
  154. package/docs/mock-altherma-air-to-water-wlan.json +845 -0
  155. package/docs/mock-d2cnd-gas-boiler.json +649 -0
  156. package/docs/setpointmode-vs-controlmode-vs-setpoints-vs-sensorydata.txt +6 -0
  157. package/homebridge-ui/README.md +35 -0
  158. package/homebridge-ui/public/index.html +222 -0
  159. package/homebridge-ui/public/script.js +796 -0
  160. package/homebridge-ui/public/styles.css +456 -0
  161. package/homebridge-ui/server.js +909 -0
  162. package/jest.config.ts +13 -0
  163. package/package.json +63 -0
  164. package/test/fixtures/altherma-crSense-2.ts +834 -0
  165. package/test/fixtures/altherma-fraction.ts +719 -0
  166. package/test/fixtures/altherma-heat-pump-2.ts +479 -0
  167. package/test/fixtures/altherma-heat-pump.ts +758 -0
  168. package/test/fixtures/altherma-miladcerkic-off.ts +524 -0
  169. package/test/fixtures/altherma-miladcerkic.ts +524 -0
  170. package/test/fixtures/altherma-v1ckoeln.ts +645 -0
  171. package/test/fixtures/altherma-with-embedded-id-zero.ts +834 -0
  172. package/test/fixtures/dx23-airco-2.ts +343 -0
  173. package/test/fixtures/dx23-airco.ts +519 -0
  174. package/test/fixtures/dx4-airco.ts +915 -0
  175. package/test/fixtures/unknown-jan.ts +489 -0
  176. package/test/fixtures/unknown-kitchen-guests.ts +489 -0
  177. package/test/hbConfig/.daikin-controller-cloud-tokenset +8 -0
  178. package/test/hbConfig/.uix-dashboard.json +1 -0
  179. package/test/hbConfig/.uix-secrets +1 -0
  180. package/test/hbConfig/accessories/.cachedAccessories.bak +1 -0
  181. package/test/hbConfig/accessories/cachedAccessories +1 -0
  182. package/test/hbConfig/accessories/uiAccessoriesLayout.json +1 -0
  183. package/test/hbConfig/auth.json +10 -0
  184. package/test/hbConfig/backups/config-backups/config.json.1767953686461 +25 -0
  185. package/test/hbConfig/backups/config-backups/config.json.1767953695236 +29 -0
  186. package/test/hbConfig/backups/config-backups/config.json.1767953814763 +29 -0
  187. package/test/hbConfig/backups/config-backups/config.json.1767953823101 +29 -0
  188. package/test/hbConfig/backups/config-backups/config.json.1767954822835 +29 -0
  189. package/test/hbConfig/backups/config-backups/config.json.1767954859218 +29 -0
  190. package/test/hbConfig/config.json +33 -0
  191. package/test/hbConfig/daikin-cloud-certs/server.crt +22 -0
  192. package/test/hbConfig/daikin-cloud-certs/server.key +28 -0
  193. package/test/hbConfig/persist/AccessoryInfo.1E4A432551BA.json +1 -0
  194. package/test/hbConfig/persist/IdentifierCache.1E4A432551BA.json +1 -0
  195. package/test/integration/air-conditioning.test.ts +396 -0
  196. package/test/integration/altherma.test.ts +288 -0
  197. package/test/integration/platform.test.ts +101 -0
  198. package/test/mocks/index.ts +27 -0
  199. package/test/unit/api/__snapshots__/daikinCloud.test.ts.snap +1323 -0
  200. package/test/unit/api/daikinCloud.test.ts +12 -0
  201. package/test/unit/device/daikin-device.test.ts +29 -0
  202. package/test/unit/services/hot-water-tank.service.test.ts +107 -0
@@ -0,0 +1,288 @@
1
+ import {PlatformAccessory} from 'homebridge/lib/platformAccessory';
2
+ import {DaikinCloudAccessoryContext, DaikinCloudPlatform} from '../../src/platform';
3
+ import {MockPlatformConfig} from '../mocks';
4
+ import {AlthermaAccessory} from '../../src/accessories';
5
+ import {DaikinCloudDevice} from 'daikin-controller-cloud/dist/device';
6
+ import {OnectaClient} from 'daikin-controller-cloud/dist/onecta/oidc-client';
7
+ import {DaikinCloudController} from 'daikin-controller-cloud/dist/index.js';
8
+ import {althermaV1ckoeln} from '../fixtures/altherma-v1ckoeln';
9
+ import {althermaCrSense2} from '../fixtures/altherma-crSense-2';
10
+ import {althermaWithEmbeddedIdZero} from '../fixtures/altherma-with-embedded-id-zero';
11
+ import {althermaHeatPump} from '../fixtures/altherma-heat-pump';
12
+ import {althermaHeatPump2} from '../fixtures/altherma-heat-pump-2';
13
+ import {althermaFraction} from '../fixtures/altherma-fraction';
14
+ import {althermaMiladcerkic} from '../fixtures/altherma-miladcerkic';
15
+
16
+ import {HomebridgeAPI} from 'homebridge/lib/api.js';
17
+ import { Logger } from 'homebridge/lib/logger.js';
18
+
19
+ type DeviceState = {
20
+ activeState: boolean;
21
+ currentTemperature: number;
22
+ targetHeaterCoolerState: string;
23
+ coolingThresholdTemperature: number;
24
+ heatingThresholdTemperature: number;
25
+ hotWaterTankCurrentHeatingCoolingState: number;
26
+ hotWaterTankCurrentTemperature: number;
27
+ hotWaterTankHeatingTargetTemperature: number;
28
+ hotWaterTankTargetHeaterCoolerState: number;
29
+ powerfulMode: number;
30
+ };
31
+
32
+ test.each<Array<string | string | any | DeviceState>>([
33
+ [
34
+ 'altherma',
35
+ 'climateControlMainZone',
36
+ althermaHeatPump,
37
+ {
38
+ activeState: true,
39
+ currentTemperature: 22.4,
40
+ targetHeaterCoolerState: 1,
41
+ coolingThresholdTemperature: undefined,
42
+ heatingThresholdTemperature: 22,
43
+ hotWaterTankCurrentHeatingCoolingState: 1,
44
+ hotWaterTankCurrentTemperature: 48,
45
+ hotWaterTankHeatingTargetTemperature: 48,
46
+ hotWaterTankTargetHeaterCoolerState: 1,
47
+ powerfulMode: false,
48
+
49
+ },
50
+ ],
51
+ [
52
+ 'altherma',
53
+ 'climateControlMainZone',
54
+ althermaHeatPump2,
55
+ {
56
+ activeState: false,
57
+ currentTemperature: 33,
58
+ targetHeaterCoolerState: 1,
59
+ coolingThresholdTemperature: 0,
60
+ heatingThresholdTemperature: 0,
61
+ hotWaterTankCurrentHeatingCoolingState: 1,
62
+ hotWaterTankCurrentTemperature: 50,
63
+ hotWaterTankHeatingTargetTemperature: 50,
64
+ hotWaterTankTargetHeaterCoolerState: 1,
65
+ powerfulMode: false,
66
+
67
+ },
68
+ ],
69
+ [
70
+ 'altherma2',
71
+ '1',
72
+ althermaWithEmbeddedIdZero,
73
+ {
74
+ activeState: false,
75
+ currentTemperature: 27.7,
76
+ targetHeaterCoolerState: 1,
77
+ coolingThresholdTemperature: 20,
78
+ heatingThresholdTemperature: 21,
79
+ hotWaterTankCurrentHeatingCoolingState: 1,
80
+ hotWaterTankCurrentTemperature: 42,
81
+ hotWaterTankHeatingTargetTemperature: 45,
82
+ hotWaterTankTargetHeaterCoolerState: 1,
83
+ powerfulMode: false,
84
+
85
+ },
86
+ ],
87
+ [
88
+ 'altherma3',
89
+ '1',
90
+ althermaCrSense2,
91
+ {
92
+ activeState: false,
93
+ currentTemperature: 27.8,
94
+ targetHeaterCoolerState: 1,
95
+ coolingThresholdTemperature: 20,
96
+ heatingThresholdTemperature: 21,
97
+ hotWaterTankCurrentHeatingCoolingState: 1,
98
+ hotWaterTankCurrentTemperature: 45,
99
+ hotWaterTankHeatingTargetTemperature: 45,
100
+ hotWaterTankTargetHeaterCoolerState: 1,
101
+ powerfulMode: false,
102
+
103
+ },
104
+ ],
105
+ [
106
+ 'altherma4',
107
+ 'climateControlMainZone',
108
+ althermaV1ckoeln,
109
+ {
110
+ activeState: false,
111
+ currentTemperature: 34, // or should we always show the roomTemperature here which is 27.5
112
+ targetHeaterCoolerState: 1,
113
+ coolingThresholdTemperature: 20,
114
+ heatingThresholdTemperature: 0,
115
+ hotWaterTankCurrentHeatingCoolingState: 1,
116
+ hotWaterTankCurrentTemperature: 42,
117
+ hotWaterTankHeatingTargetTemperature: 46,
118
+ hotWaterTankTargetHeaterCoolerState: 1,
119
+ powerfulMode: false,
120
+
121
+ },
122
+ ],
123
+ [
124
+ 'althermaFraction',
125
+ 'climateControlMainZone',
126
+ althermaFraction,
127
+ {
128
+ activeState: true,
129
+ currentTemperature: 35, // has no roomTemperature :(
130
+ targetHeaterCoolerState: 1,
131
+ coolingThresholdTemperature: 0,
132
+ heatingThresholdTemperature: 0,
133
+ hotWaterTankCurrentHeatingCoolingState: 1,
134
+ hotWaterTankCurrentTemperature: 45,
135
+ hotWaterTankHeatingTargetTemperature: 47,
136
+ hotWaterTankTargetHeaterCoolerState: 1,
137
+ powerfulMode: false,
138
+
139
+ },
140
+ ],
141
+ [
142
+ 'althermaMiladcerkic',
143
+ 'climateControlMainZone',
144
+ althermaMiladcerkic,
145
+ {
146
+ activeState: true,
147
+ currentTemperature: 45,
148
+ targetHeaterCoolerState: 1,
149
+ coolingThresholdTemperature: 20,
150
+ heatingThresholdTemperature: 45,
151
+ hotWaterTankCurrentHeatingCoolingState: 1,
152
+ hotWaterTankCurrentTemperature: 49,
153
+ hotWaterTankHeatingTargetTemperature: 50,
154
+ hotWaterTankTargetHeaterCoolerState: 1,
155
+ powerfulMode: false,
156
+ },
157
+ ],
158
+ ])('Create DaikinCloudThermostatAccessory with %s device', async (name, climateControlEmbeddedId, deviceJson, state) => {
159
+ const device = new DaikinCloudDevice(deviceJson, undefined as unknown as OnectaClient);
160
+
161
+ jest.spyOn(DaikinCloudController.prototype, 'getCloudDevices').mockImplementation(async () => {
162
+ return [device];
163
+ });
164
+
165
+ const config = new MockPlatformConfig(true);
166
+ const api = new HomebridgeAPI();
167
+
168
+ const uuid = api.hap.uuid.generate(device.getId());
169
+ const accessory = new api.platformAccessory("NAME_FOR_TEST", uuid);
170
+ accessory.context['device'] = device;
171
+
172
+ expect(() => {
173
+ new AlthermaAccessory(new DaikinCloudPlatform(new Logger(), config, api), accessory as unknown as PlatformAccessory<DaikinCloudAccessoryContext>);
174
+ }).not.toThrow();
175
+
176
+ const homebridgeAccessory = new AlthermaAccessory(new DaikinCloudPlatform(new Logger(), config, api), accessory as unknown as PlatformAccessory<DaikinCloudAccessoryContext>);
177
+
178
+
179
+ if (typeof state.activeState !== 'undefined') {
180
+ expect(await homebridgeAccessory.service?.handleActiveStateGet()).toBe(state.activeState);
181
+ expect(async () => {
182
+ await homebridgeAccessory.service?.handleActiveStateSet(1);
183
+ }).not.toThrow();
184
+ expect(async () => {
185
+ await homebridgeAccessory.service?.handleActiveStateSet(0);
186
+ }).not.toThrow();
187
+ }
188
+
189
+ expect(await homebridgeAccessory.service?.handleCurrentTemperatureGet()).toBe(state.currentTemperature);
190
+
191
+ if (typeof state.coolingThresholdTemperature !== 'undefined') {
192
+ expect(await homebridgeAccessory.service?.handleCoolingThresholdTemperatureGet()).toBe(state.coolingThresholdTemperature);
193
+ expect(async () => {
194
+ await homebridgeAccessory.service?.handleCoolingThresholdTemperatureSet(21);
195
+ }).not.toThrow();
196
+ }
197
+
198
+ if (typeof state.heatingThresholdTemperature !== 'undefined') {
199
+ expect(await homebridgeAccessory.service?.handleHeatingThresholdTemperatureGet()).toBe(state.heatingThresholdTemperature);
200
+ expect(async () => {
201
+ await homebridgeAccessory.service?.handleHeatingThresholdTemperatureSet(25);
202
+ }).not.toThrow();
203
+ }
204
+
205
+ if (typeof state.targetHeaterCoolerState !== 'undefined') {
206
+ expect(await homebridgeAccessory.service?.handleTargetHeaterCoolerStateGet()).toBe(state.targetHeaterCoolerState);
207
+ expect(async () => {
208
+ await homebridgeAccessory.service?.handleTargetHeaterCoolerStateSet(1);
209
+ }).not.toThrow();
210
+ }
211
+
212
+
213
+ if (typeof state.hotWaterTankCurrentHeatingCoolingState !== 'undefined') {
214
+ expect(await homebridgeAccessory.hotWaterTankService?.handleHotWaterTankCurrentHeatingCoolingStateGet()).toBe(state.hotWaterTankCurrentHeatingCoolingState);
215
+ }
216
+ if (typeof state.hotWaterTankCurrentTemperature !== 'undefined') {
217
+ expect(await homebridgeAccessory.hotWaterTankService?.handleHotWaterTankCurrentTemperatureGet()).toBe(state.hotWaterTankCurrentTemperature);
218
+ }
219
+ if (typeof state.hotWaterTankHeatingTargetTemperature !== 'undefined') {
220
+ expect(await homebridgeAccessory.hotWaterTankService?.handleHotWaterTankHeatingTargetTemperatureGet()).toBe(state.hotWaterTankHeatingTargetTemperature);
221
+ }
222
+ if (typeof state.hotWaterTankTargetHeaterCoolerState !== 'undefined') {
223
+ expect(await homebridgeAccessory.hotWaterTankService?.handleHotWaterTankTargetHeatingCoolingStateGet()).toBe(state.hotWaterTankTargetHeaterCoolerState);
224
+ }
225
+ if (typeof state.powerfulMode !== 'undefined') {
226
+ expect(await homebridgeAccessory.hotWaterTankService?.handlePowerfulModeGet()).toBe(state.powerfulMode);
227
+ }
228
+
229
+ });
230
+
231
+ test('DaikinCloudAirConditioningAccessory Getters', async () => {
232
+ const device = new DaikinCloudDevice(althermaHeatPump, undefined as unknown as OnectaClient);
233
+
234
+ jest.spyOn(DaikinCloudController.prototype, 'getCloudDevices').mockImplementation(async () => {
235
+ return [device];
236
+ });
237
+
238
+ const config = new MockPlatformConfig(false);
239
+ const api = new HomebridgeAPI();
240
+
241
+ const uuid = api.hap.uuid.generate(device.getId());
242
+ const accessory = new api.platformAccessory(device.getData('climateControlMainZone', 'name', undefined).value, uuid);
243
+ accessory.context['device'] = device;
244
+
245
+ const homebridgeAccessory = new AlthermaAccessory(new DaikinCloudPlatform(new Logger(), config, api), accessory as unknown as PlatformAccessory<DaikinCloudAccessoryContext>);
246
+
247
+ expect(await homebridgeAccessory.service?.handleActiveStateGet()).toEqual(true);
248
+ expect(await homebridgeAccessory.service?.handleCurrentTemperatureGet()).toEqual(22.4);
249
+ expect(await homebridgeAccessory.service?.handleHeatingThresholdTemperatureGet()).toEqual(22);
250
+ expect(await homebridgeAccessory.service?.handleTargetHeaterCoolerStateGet()).toEqual(1);
251
+ });
252
+
253
+ test('DaikinCloudAirConditioningAccessory Setters', async () => {
254
+ const device = new DaikinCloudDevice(althermaHeatPump, undefined as unknown as OnectaClient);
255
+
256
+ jest.spyOn(DaikinCloudController.prototype, 'getCloudDevices').mockImplementation(async () => {
257
+ return [device];
258
+ });
259
+
260
+ const setDataSpy = jest.spyOn(DaikinCloudDevice.prototype, 'setData').mockImplementation();
261
+
262
+ const config = new MockPlatformConfig(false);
263
+ const api = new HomebridgeAPI();
264
+
265
+ const uuid = api.hap.uuid.generate(device.getId());
266
+ const accessory = new api.platformAccessory(device.getData('climateControlMainZone', 'name', undefined).value, uuid);
267
+ accessory.context['device'] = device;
268
+
269
+ const homebridgeAccessory = new AlthermaAccessory(new DaikinCloudPlatform(new Logger(), config, api), accessory as unknown as PlatformAccessory<DaikinCloudAccessoryContext>);
270
+
271
+ await homebridgeAccessory.service?.handleActiveStateSet(1);
272
+ expect(setDataSpy).toHaveBeenNthCalledWith(1, 'climateControlMainZone', 'onOffMode', 'on', undefined);
273
+
274
+ await homebridgeAccessory.service?.handleActiveStateSet(0);
275
+ expect(setDataSpy).toHaveBeenNthCalledWith(2, 'climateControlMainZone', 'onOffMode', 'off', undefined);
276
+
277
+ await homebridgeAccessory.service?.handleCoolingThresholdTemperatureSet(21);
278
+ expect(setDataSpy).toHaveBeenNthCalledWith(3, 'climateControlMainZone', 'temperatureControl', '/operationModes/cooling/setpoints/roomTemperature', 21);
279
+
280
+ await homebridgeAccessory.service?.handleHeatingThresholdTemperatureSet(25);
281
+ expect(setDataSpy).toHaveBeenNthCalledWith(4, 'climateControlMainZone', 'temperatureControl', '/operationModes/heating/setpoints/roomTemperature', 25);
282
+
283
+ await homebridgeAccessory.service?.handleTargetHeaterCoolerStateSet(1);
284
+ expect(setDataSpy).toHaveBeenNthCalledWith(5, 'climateControlMainZone', 'operationMode', 'heating', undefined);
285
+ expect(setDataSpy).toHaveBeenNthCalledWith(6, 'climateControlMainZone', 'onOffMode', 'on', undefined);
286
+
287
+
288
+ });
@@ -0,0 +1,101 @@
1
+ import {DaikinCloudPlatform} from '../../src/platform';
2
+ import {MockPlatformConfig} from '../mocks';
3
+ import {DaikinCloudController} from 'daikin-controller-cloud';
4
+ import {AirConditioningAccessory, AlthermaAccessory} from '../../src/accessories';
5
+ import {HomebridgeAPI} from 'homebridge/lib/api.js';
6
+ import {Logger} from 'homebridge/lib/logger.js';
7
+ import {DaikinCloudDevice} from 'daikin-controller-cloud/dist/device';
8
+
9
+ jest.mock('daikin-controller-cloud');
10
+ jest.mock('homebridge');
11
+ jest.mock('../../src/accessories/air-conditioning-accessory');
12
+ jest.mock('../../src/accessories/altherma-accessory');
13
+ jest.mock('daikin-controller-cloud/dist/device');
14
+
15
+ afterEach(() => {
16
+ jest.resetAllMocks();
17
+ });
18
+
19
+ test('Initialize platform', async () => {
20
+ const api = new HomebridgeAPI();
21
+ const platform = new DaikinCloudPlatform(new Logger(), new MockPlatformConfig(), api);
22
+
23
+ expect(DaikinCloudController).toHaveBeenCalledWith({
24
+ 'oidcAuthorizationTimeoutS': 300,
25
+ 'oidcCallbackServerBindAddr': 'SERVER_BIND_ADDRESS',
26
+ 'oidcCallbackServerExternalAddress': 'SERVER_EXTERNAL_ADDRESS',
27
+ 'oidcCallbackServerPort': 'SERVER_PORT',
28
+ 'oidcClientId': 'CLIENT_ID',
29
+ 'oidcClientSecret': 'CLIENT_SECRET',
30
+ 'oidcTokenSetFilePath': `${api.user.storagePath()}/.daikin-controller-cloud-tokenset`,
31
+ });
32
+ expect(platform.updateIntervalDelay).toBe(900000);
33
+ });
34
+
35
+ test('DaikinCloudPlatform with new Aircondition accessory', (done) => {
36
+ jest.spyOn(DaikinCloudController.prototype, 'getCloudDevices').mockResolvedValue([{
37
+ getId: () => 'MOCK_ID',
38
+ getDescription: () => {
39
+ return {
40
+ deviceModel: 'Airco',
41
+ };
42
+ },
43
+ getData: () => 'MOCK_DATE',
44
+ desc: {
45
+ managementPoints: [
46
+ {
47
+ 'embeddedId': 'climateControl',
48
+ 'managementPointType': 'climateControl',
49
+ },
50
+ ],
51
+ },
52
+ } as unknown as DaikinCloudDevice]);
53
+
54
+ const api = new HomebridgeAPI();
55
+
56
+ const registerPlatformAccessoriesSpy = jest.spyOn(api, 'registerPlatformAccessories');
57
+
58
+ new DaikinCloudPlatform(new Logger(), new MockPlatformConfig(true), api);
59
+ api.signalFinished();
60
+
61
+ setTimeout(() => {
62
+ expect(AirConditioningAccessory).toHaveBeenCalled();
63
+ expect(AlthermaAccessory).not.toHaveBeenCalled();
64
+ expect(registerPlatformAccessoriesSpy).toBeCalledWith('@mp-consulting/homebridge-daikin-cloud', 'DaikinCloud', expect.anything());
65
+ done();
66
+ }, 10);
67
+ });
68
+
69
+ test('DaikinCloudPlatform with new Altherma accessory', (done) => {
70
+ jest.spyOn(DaikinCloudController.prototype, 'getCloudDevices').mockResolvedValue([{
71
+ getId: () => 'MOCK_ID',
72
+ getDescription: () => {
73
+ return {
74
+ deviceModel: 'Altherma',
75
+ };
76
+ },
77
+ getData: () => 'MOCK_DATE',
78
+ desc: {
79
+ managementPoints: [
80
+ {
81
+ 'embeddedId': 'climateControl',
82
+ 'managementPointType': 'climateControl',
83
+ },
84
+ ],
85
+ },
86
+ } as unknown as DaikinCloudDevice]);
87
+
88
+ const api = new HomebridgeAPI();
89
+
90
+ const registerPlatformAccessoriesSpy = jest.spyOn(api, 'registerPlatformAccessories');
91
+
92
+ new DaikinCloudPlatform(new Logger(), new MockPlatformConfig(true), api);
93
+ api.signalFinished();
94
+
95
+ setTimeout(() => {
96
+ expect(AlthermaAccessory).toHaveBeenCalled();
97
+ expect(AirConditioningAccessory).not.toHaveBeenCalled();
98
+ expect(registerPlatformAccessoriesSpy).toHaveBeenCalledWith('@mp-consulting/homebridge-daikin-cloud', 'DaikinCloud', expect.anything());
99
+ done();
100
+ }, 10);
101
+ });
@@ -0,0 +1,27 @@
1
+ // https://github.com/timcharper/homebridge-vivint/blob/5b3bfa4cc886c5680af3b2e31706ef9b1bf2705f/test/device_set_test.js
2
+ // https://github.com/break-pointer/homebridge-tion/blob/13f1c410c6ee8ca13b41b8700c4b1de96e04b263/test/mocks.ts#L49
3
+
4
+ import {PlatformConfig} from "homebridge";
5
+
6
+ export const MockLogger = (...args) => jest.fn();
7
+ MockLogger.debug = MockLogger;
8
+ MockLogger.info = MockLogger;
9
+ MockLogger.success = MockLogger;
10
+ MockLogger.warn = MockLogger;
11
+ MockLogger.error = MockLogger;
12
+ MockLogger.log = MockLogger;
13
+
14
+ export class MockPlatformConfig implements PlatformConfig {
15
+ name = 'Home';
16
+ platform = 'DaikinCloud';
17
+ clientId = 'CLIENT_ID';
18
+ clientSecret = 'CLIENT_SECRET';
19
+ oidcCallbackServerBindAddr = 'SERVER_BIND_ADDRESS';
20
+ callbackServerExternalAddress = 'SERVER_EXTERNAL_ADDRESS';
21
+ callbackServerPort = 'SERVER_PORT';
22
+ showExtraFeatures: boolean;
23
+
24
+ constructor(showExtraFeatures = false) {
25
+ this.showExtraFeatures = showExtraFeatures;
26
+ }
27
+ }