homebridge-tuya-without-developer-account 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 (97) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +20 -0
  3. package/PUBLISHING.md +80 -0
  4. package/README.md +233 -0
  5. package/SUPPORTED_DEVICES.md +206 -0
  6. package/config.schema.json +131 -0
  7. package/dist/cloud/api/TuyaHACloudAPI.js +286 -0
  8. package/dist/cloud/api/TuyaHASharingMQ.js +114 -0
  9. package/dist/cloud/device/TuyaDevice.js +50 -0
  10. package/dist/cloud/device/TuyaHADeviceManager.js +355 -0
  11. package/dist/index.js +7 -0
  12. package/dist/platform.js +397 -0
  13. package/dist/settings.js +18 -0
  14. package/dist/shared/AccessoryFactory.js +276 -0
  15. package/dist/shared/accessories/AccessoryFactory.js +305 -0
  16. package/dist/shared/accessories/AirConditionerAccessory.js +307 -0
  17. package/dist/shared/accessories/AirPurifierAccessory.js +90 -0
  18. package/dist/shared/accessories/AirQualitySensorAccessory.js +30 -0
  19. package/dist/shared/accessories/BaseAccessory.js +406 -0
  20. package/dist/shared/accessories/BlindsAccessory.js +199 -0
  21. package/dist/shared/accessories/CameraAccessory.js +121 -0
  22. package/dist/shared/accessories/CarbonDioxideSensorAccessory.js +52 -0
  23. package/dist/shared/accessories/CarbonMonoxideSensorAccessory.js +52 -0
  24. package/dist/shared/accessories/ContactSensorAccessory.js +30 -0
  25. package/dist/shared/accessories/DehumidifierAccessory.js +68 -0
  26. package/dist/shared/accessories/DiffuserAccessory.js +55 -0
  27. package/dist/shared/accessories/DimmerAccessory.js +94 -0
  28. package/dist/shared/accessories/DoorbellAccessory.js +91 -0
  29. package/dist/shared/accessories/ExtractionHoodAccessory.js +120 -0
  30. package/dist/shared/accessories/FanAccessory.js +129 -0
  31. package/dist/shared/accessories/GarageDoorAccessory.js +69 -0
  32. package/dist/shared/accessories/HeaterAccessory.js +102 -0
  33. package/dist/shared/accessories/HeaterAccessory_old.js +96 -0
  34. package/dist/shared/accessories/HumanPresenceSensorAccessory.js +20 -0
  35. package/dist/shared/accessories/HumidifierAccessory.js +137 -0
  36. package/dist/shared/accessories/IRAirConditionerAccessory.js +278 -0
  37. package/dist/shared/accessories/IRControlHubAccessory.js +49 -0
  38. package/dist/shared/accessories/IRControlHubSubAccessory.js +52 -0
  39. package/dist/shared/accessories/IRGenericAccessory.js +49 -0
  40. package/dist/shared/accessories/LeakSensorAccessory.js +36 -0
  41. package/dist/shared/accessories/LightAccessory.js +36 -0
  42. package/dist/shared/accessories/LightSensorAccessory.js +32 -0
  43. package/dist/shared/accessories/LocationWeatherAccessory.js +72 -0
  44. package/dist/shared/accessories/LockAccessory.js +56 -0
  45. package/dist/shared/accessories/MotionSensorAccessory.js +20 -0
  46. package/dist/shared/accessories/OutletAccessory.js +23 -0
  47. package/dist/shared/accessories/PetFeederAccessory.js +139 -0
  48. package/dist/shared/accessories/SceneAccessory.js +32 -0
  49. package/dist/shared/accessories/SceneSwitchAccessory.js +44 -0
  50. package/dist/shared/accessories/SecuritySystemAccessory.js +30 -0
  51. package/dist/shared/accessories/SmokeSensorAccessory.js +35 -0
  52. package/dist/shared/accessories/SwitchAccessory.js +148 -0
  53. package/dist/shared/accessories/TemperatureHumiditySensorAccessory.js +24 -0
  54. package/dist/shared/accessories/ThermostatAccessory.js +192 -0
  55. package/dist/shared/accessories/TowerRackAccessory.js +157 -0
  56. package/dist/shared/accessories/ValveAccessory.js +45 -0
  57. package/dist/shared/accessories/VibrationSensorAccessory.js +46 -0
  58. package/dist/shared/accessories/WeatherStationAccessory.js +58 -0
  59. package/dist/shared/accessories/WetBulbGlobeTemperatureAccessory.js +23 -0
  60. package/dist/shared/accessories/WhiteNoiseLightAccessory.js +59 -0
  61. package/dist/shared/accessories/WindowAccessory.js +14 -0
  62. package/dist/shared/accessories/WindowCoveringAccessory.js +156 -0
  63. package/dist/shared/accessories/WirelessSwitchAccessory.js +42 -0
  64. package/dist/shared/accessories/characteristic/Active.js +22 -0
  65. package/dist/shared/accessories/characteristic/AirQuality.js +74 -0
  66. package/dist/shared/accessories/characteristic/CurrentRelativeHumidity.js +23 -0
  67. package/dist/shared/accessories/characteristic/CurrentTemperature.js +23 -0
  68. package/dist/shared/accessories/characteristic/CurrentWeather.js +49 -0
  69. package/dist/shared/accessories/characteristic/CurrentWeatherByOpenMeteo.js +49 -0
  70. package/dist/shared/accessories/characteristic/CurrentWetBulbGlobeTemperature.js +48 -0
  71. package/dist/shared/accessories/characteristic/EnergyUsage.js +98 -0
  72. package/dist/shared/accessories/characteristic/Light.js +268 -0
  73. package/dist/shared/accessories/characteristic/LightSensor.js +23 -0
  74. package/dist/shared/accessories/characteristic/LockPhysicalControls.js +21 -0
  75. package/dist/shared/accessories/characteristic/MotionDetected.js +22 -0
  76. package/dist/shared/accessories/characteristic/Name.js +15 -0
  77. package/dist/shared/accessories/characteristic/OccupancyDetected.js +19 -0
  78. package/dist/shared/accessories/characteristic/On.js +25 -0
  79. package/dist/shared/accessories/characteristic/OutletInUse.js +14 -0
  80. package/dist/shared/accessories/characteristic/ProgrammableSwitchEvent.js +89 -0
  81. package/dist/shared/accessories/characteristic/RelativeHumidityDehumidifierThreshold.js +28 -0
  82. package/dist/shared/accessories/characteristic/RotationSpeed.js +78 -0
  83. package/dist/shared/accessories/characteristic/SecuritySystemState.js +74 -0
  84. package/dist/shared/accessories/characteristic/SwingMode.js +21 -0
  85. package/dist/shared/accessories/characteristic/TargetTemperature.js +29 -0
  86. package/dist/shared/accessories/characteristic/TemperatureDisplayUnits.js +25 -0
  87. package/dist/shared/util/ConfigHash.js +79 -0
  88. package/dist/shared/util/FfmpegStreamingProcess.js +126 -0
  89. package/dist/shared/util/InfraredTool.js +392 -0
  90. package/dist/shared/util/Logger.js +42 -0
  91. package/dist/shared/util/TuyaRecordingDelegate.js +22 -0
  92. package/dist/shared/util/TuyaStreamDelegate.js +329 -0
  93. package/dist/shared/util/color.js +23 -0
  94. package/dist/shared/util/util.js +135 -0
  95. package/homebridge-ui/public/index.html +329 -0
  96. package/homebridge-ui/server.js +224 -0
  97. package/package.json +61 -0
@@ -0,0 +1,268 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureLight = configureLight;
4
+ const color_1 = require("../../util/color");
5
+ const util_1 = require("../../util/util");
6
+ const On_1 = require("./On");
7
+ const DEFAULT_COLOR_TEMPERATURE_KELVIN = 6500;
8
+ var LightType;
9
+ (function (LightType) {
10
+ LightType["Unknown"] = "Unknown";
11
+ LightType["Normal"] = "Normal";
12
+ LightType["C"] = "C";
13
+ LightType["CW"] = "CW";
14
+ LightType["RGB"] = "RGB";
15
+ LightType["RGBC"] = "RGBC";
16
+ LightType["RGBCW"] = "RGBCW";
17
+ })(LightType || (LightType = {}));
18
+ function getLightType(accessory, on, bright, temp, color, mode) {
19
+ const modeRange = mode && mode.property.range;
20
+ const { h, s, v } = (color?.property || {});
21
+ let lightType;
22
+ if (on && bright && temp && h && s && v && modeRange && modeRange.includes('colour') && modeRange.includes('white')) {
23
+ lightType = LightType.RGBCW;
24
+ }
25
+ else if (on && bright && !temp && h && s && v && modeRange && modeRange.includes('colour') && modeRange.includes('white')) {
26
+ lightType = LightType.RGBC;
27
+ }
28
+ else if (on && !temp && h && s && v) {
29
+ lightType = LightType.RGB;
30
+ }
31
+ else if (on && bright && temp) {
32
+ lightType = LightType.CW;
33
+ }
34
+ else if (on && bright && !temp) {
35
+ lightType = LightType.C;
36
+ }
37
+ else if (on && !bright && !temp) {
38
+ lightType = LightType.Normal;
39
+ }
40
+ else {
41
+ lightType = LightType.Unknown;
42
+ }
43
+ return lightType;
44
+ }
45
+ function getColorValue(accessory, schema) {
46
+ const status = accessory.getStatus(schema.code);
47
+ if (!status || !status.value || status.value === '' || status.value === '{}') {
48
+ return { h: 0, s: 0, v: 0 };
49
+ }
50
+ const { h, s, v } = JSON.parse(status.value);
51
+ return {
52
+ h: h,
53
+ s: s,
54
+ v: v,
55
+ };
56
+ }
57
+ function inWhiteMode(accessory, lightType, modeSchema) {
58
+ if (lightType === LightType.C || lightType === LightType.CW) {
59
+ return true;
60
+ }
61
+ else if (lightType === LightType.RGB) {
62
+ return false;
63
+ }
64
+ if (!modeSchema) {
65
+ return false;
66
+ }
67
+ const status = accessory.getStatus(modeSchema.code);
68
+ return (status.value === 'white');
69
+ }
70
+ function inColorMode(accessory, lightType, modeSchema) {
71
+ if (lightType === LightType.RGB) {
72
+ return true;
73
+ }
74
+ else if (lightType === LightType.C || lightType === LightType.CW) {
75
+ return false;
76
+ }
77
+ if (!modeSchema) {
78
+ return false;
79
+ }
80
+ const status = accessory.getStatus(modeSchema.code);
81
+ return (status.value === 'colour');
82
+ }
83
+ function configureBrightness(accessory, service, lightType, brightSchema, colorSchema, modeSchema) {
84
+ service.getCharacteristic(accessory.Characteristic.Brightness)
85
+ .onGet(() => {
86
+ if (inColorMode(accessory, lightType, modeSchema) && colorSchema) {
87
+ // Color mode, get brightness from `color_data.v`
88
+ const { max } = colorSchema.property.v;
89
+ const colorValue = getColorValue(accessory, colorSchema);
90
+ const value = Math.round(100 * colorValue.v / max);
91
+ return (0, util_1.limit)(value, 0, 100);
92
+ }
93
+ else if (inWhiteMode(accessory, lightType, modeSchema) && brightSchema) {
94
+ // White mode, get brightness from `brightness_value`
95
+ const { max } = brightSchema.property;
96
+ const status = accessory.getStatus(brightSchema.code);
97
+ const value = Math.round(100 * status.value / max);
98
+ return (0, util_1.limit)(value, 0, 100);
99
+ }
100
+ else {
101
+ // Unsupported mode
102
+ return 100;
103
+ }
104
+ })
105
+ .onSet(async (value) => {
106
+ accessory.log.debug(`Characteristic.Brightness set to: ${value}`);
107
+ if (inColorMode(accessory, lightType, modeSchema) && colorSchema) {
108
+ // Color mode, set brightness to `color_data.v`
109
+ const { min, max } = colorSchema.property.v;
110
+ const colorValue = getColorValue(accessory, colorSchema);
111
+ colorValue.v = Math.round(value * max / 100);
112
+ colorValue.v = (0, util_1.limit)(colorValue.v, min, max);
113
+ await accessory.sendCommands([{ code: colorSchema.code, value: JSON.stringify(colorValue) }], true);
114
+ }
115
+ else if (inWhiteMode(accessory, lightType, modeSchema) && brightSchema) {
116
+ // White mode, set brightness to `brightness_value`
117
+ const { min, max } = brightSchema.property;
118
+ let brightValue = Math.round(value * max / 100);
119
+ brightValue = (0, util_1.limit)(brightValue, min, max);
120
+ await accessory.sendCommands([{ code: brightSchema.code, value: brightValue }], true);
121
+ }
122
+ else {
123
+ // Unsupported mode
124
+ accessory.log.warn('Neither color mode nor white mode.');
125
+ }
126
+ });
127
+ }
128
+ function configureColourTemperature(accessory, service, lightType, tempSchema, modeSchema) {
129
+ const props = { minValue: 140, maxValue: 500, minStep: 1 };
130
+ if (lightType === LightType.RGBC) {
131
+ props.minValue = props.maxValue = Math.round((0, color_1.kelvinToMired)(DEFAULT_COLOR_TEMPERATURE_KELVIN));
132
+ }
133
+ accessory.log.debug('Set props for ColorTemperature:', props);
134
+ service.getCharacteristic(accessory.Characteristic.ColorTemperature)
135
+ .onGet(() => {
136
+ if (lightType === LightType.RGBC) {
137
+ return props.minValue;
138
+ }
139
+ // const schema = accessory.getSchema(...SCHEMA_CODE.COLOR_TEMP)!;
140
+ const { min, max } = tempSchema.property;
141
+ const status = accessory.getStatus(tempSchema.code);
142
+ const kelvin = (0, util_1.remap)(status.value, min, max, (0, color_1.miredToKelvin)(props.maxValue), (0, color_1.miredToKelvin)(props.minValue));
143
+ const mired = Math.round((0, color_1.kelvinToMired)(kelvin));
144
+ return (0, util_1.limit)(mired, props.minValue, props.maxValue);
145
+ })
146
+ .onSet(async (value) => {
147
+ accessory.log.debug(`Characteristic.ColorTemperature set to: ${value}`);
148
+ const commands = [];
149
+ if (modeSchema) {
150
+ commands.push({ code: modeSchema.code, value: 'white' });
151
+ }
152
+ if (lightType !== LightType.RGBC) {
153
+ const { min, max } = tempSchema.property;
154
+ const kelvin = (0, color_1.miredToKelvin)(value);
155
+ const temp = Math.round((0, util_1.remap)(kelvin, (0, color_1.miredToKelvin)(props.maxValue), (0, color_1.miredToKelvin)(props.minValue), min, max));
156
+ commands.push({ code: tempSchema.code, value: temp });
157
+ }
158
+ await accessory.sendCommands(commands, true);
159
+ })
160
+ .setProps(props);
161
+ }
162
+ function configureHue(accessory, service, lightType, colorSchema, modeSchema) {
163
+ const { min, max } = colorSchema.property.h;
164
+ service.getCharacteristic(accessory.Characteristic.Hue)
165
+ .onGet(() => {
166
+ if (inWhiteMode(accessory, lightType, modeSchema)) {
167
+ return (0, color_1.kelvinToHSV)(DEFAULT_COLOR_TEMPERATURE_KELVIN).h;
168
+ }
169
+ const hue = Math.round(360 * getColorValue(accessory, colorSchema).h / max);
170
+ return (0, util_1.limit)(hue, 0, 360);
171
+ })
172
+ .onSet(async (value) => {
173
+ accessory.log.debug(`Characteristic.Hue set to: ${value}`);
174
+ const colorValue = getColorValue(accessory, colorSchema);
175
+ colorValue.h = Math.round(value * max / 360);
176
+ colorValue.h = (0, util_1.limit)(colorValue.h, min, max);
177
+ const commands = [{
178
+ code: colorSchema.code,
179
+ value: JSON.stringify(colorValue),
180
+ }];
181
+ if (modeSchema) {
182
+ commands.push({ code: modeSchema.code, value: 'colour' });
183
+ }
184
+ await accessory.sendCommands(commands, true);
185
+ });
186
+ }
187
+ function configureSaturation(accessory, service, lightType, colorSchema, modeSchema) {
188
+ const { min, max } = colorSchema.property.s;
189
+ service.getCharacteristic(accessory.Characteristic.Saturation)
190
+ .onGet(() => {
191
+ if (inWhiteMode(accessory, lightType, modeSchema)) {
192
+ return (0, color_1.kelvinToHSV)(DEFAULT_COLOR_TEMPERATURE_KELVIN).s;
193
+ }
194
+ const saturation = Math.round(100 * getColorValue(accessory, colorSchema).s / max);
195
+ return (0, util_1.limit)(saturation, 0, 100);
196
+ })
197
+ .onSet(async (value) => {
198
+ accessory.log.debug(`Characteristic.Saturation set to: ${value}`);
199
+ const colorValue = getColorValue(accessory, colorSchema);
200
+ colorValue.s = Math.round(value * max / 100);
201
+ colorValue.s = (0, util_1.limit)(colorValue.s, min, max);
202
+ const commands = [{
203
+ code: colorSchema.code,
204
+ value: JSON.stringify(colorValue),
205
+ }];
206
+ if (modeSchema) {
207
+ commands.push({ code: modeSchema.code, value: 'colour' });
208
+ }
209
+ await accessory.sendCommands(commands, true);
210
+ });
211
+ }
212
+ function configureLight(accessory, service, onSchema, brightSchema, tempSchema, colorSchema, modeSchema) {
213
+ if (!onSchema) {
214
+ return;
215
+ }
216
+ if (!service) {
217
+ service = accessory.accessory.getService(accessory.Service.Lightbulb)
218
+ || accessory.accessory.addService(accessory.Service.Lightbulb, accessory.accessory.displayName + ' Light');
219
+ }
220
+ const lightType = getLightType(accessory, onSchema, brightSchema, tempSchema, colorSchema, modeSchema);
221
+ accessory.log.info('Light type:', lightType);
222
+ switch (lightType) {
223
+ case LightType.Normal:
224
+ (0, On_1.configureOn)(accessory, service, onSchema);
225
+ break;
226
+ case LightType.C:
227
+ (0, On_1.configureOn)(accessory, service, onSchema);
228
+ configureBrightness(accessory, service, lightType, brightSchema, colorSchema, modeSchema);
229
+ break;
230
+ case LightType.CW:
231
+ (0, On_1.configureOn)(accessory, service, onSchema);
232
+ configureBrightness(accessory, service, lightType, brightSchema, colorSchema, modeSchema);
233
+ configureColourTemperature(accessory, service, lightType, tempSchema, modeSchema);
234
+ break;
235
+ case LightType.RGB:
236
+ (0, On_1.configureOn)(accessory, service, onSchema);
237
+ configureBrightness(accessory, service, lightType, brightSchema, colorSchema, modeSchema);
238
+ configureHue(accessory, service, lightType, colorSchema, modeSchema);
239
+ configureSaturation(accessory, service, lightType, colorSchema, modeSchema);
240
+ break;
241
+ case LightType.RGBC:
242
+ case LightType.RGBCW:
243
+ (0, On_1.configureOn)(accessory, service, onSchema);
244
+ configureBrightness(accessory, service, lightType, brightSchema, colorSchema, modeSchema);
245
+ configureColourTemperature(accessory, service, lightType, tempSchema, modeSchema);
246
+ configureHue(accessory, service, lightType, colorSchema, modeSchema);
247
+ configureSaturation(accessory, service, lightType, colorSchema, modeSchema);
248
+ break;
249
+ }
250
+ configureAdaptiveLighting(accessory, service, brightSchema, tempSchema);
251
+ }
252
+ function configureAdaptiveLighting(accessory, service, brightSchema, tempSchema) {
253
+ const config = accessory.platform.getDeviceConfig(accessory.device);
254
+ if (!config || config.adaptiveLighting !== true) {
255
+ accessory.log.info('Adaptive Lighting disabled.');
256
+ return;
257
+ }
258
+ accessory.log.info('Adaptive Lighting enabled.');
259
+ if (!brightSchema || !tempSchema) {
260
+ accessory.log.warn('Adaptive Lighting not supported. Missing brightness or color temperature schema.');
261
+ return;
262
+ }
263
+ const { AdaptiveLightingController } = accessory.platform.api.hap;
264
+ const controller = new AdaptiveLightingController(service);
265
+ accessory.accessory.configureController(controller);
266
+ accessory.adaptiveLightingController = controller;
267
+ }
268
+ //# sourceMappingURL=Light.js.map
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureLightSensor = configureLightSensor;
4
+ const util_1 = require("../../util/util");
5
+ function configureLightSensor(accessory, service, schema) {
6
+ if (!schema) {
7
+ return;
8
+ }
9
+ if (!service) {
10
+ service = accessory.accessory.getService(accessory.Service.LightSensor)
11
+ || accessory.accessory.addService(accessory.Service.LightSensor);
12
+ }
13
+ const property = schema.property || {};
14
+ const props = (0, util_1.toHapProperty)(property);
15
+ const multiple = Math.pow(10, property['scale'] || 0);
16
+ service.getCharacteristic(accessory.Characteristic.CurrentAmbientLightLevel)
17
+ .onGet(() => {
18
+ const status = accessory.getStatus(schema.code);
19
+ return (0, util_1.limit)(status.value / multiple, props['minValue'], props['maxValue']);
20
+ })
21
+ .setProps(props);
22
+ }
23
+ //# sourceMappingURL=LightSensor.js.map
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureLockPhysicalControls = configureLockPhysicalControls;
4
+ function configureLockPhysicalControls(accessory, service, schema) {
5
+ if (!schema) {
6
+ return;
7
+ }
8
+ const { CONTROL_LOCK_DISABLED, CONTROL_LOCK_ENABLED } = accessory.Characteristic.LockPhysicalControls;
9
+ service.getCharacteristic(accessory.Characteristic.LockPhysicalControls)
10
+ .onGet(() => {
11
+ const status = accessory.getStatus(schema.code);
12
+ return status.value ? CONTROL_LOCK_ENABLED : CONTROL_LOCK_DISABLED;
13
+ })
14
+ .onSet(async (value) => {
15
+ await accessory.sendCommands([{
16
+ code: schema.code,
17
+ value: (value === CONTROL_LOCK_ENABLED) ? true : false,
18
+ }], true);
19
+ });
20
+ }
21
+ //# sourceMappingURL=LockPhysicalControls.js.map
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureMotionDetected = configureMotionDetected;
4
+ const TuyaDevice_1 = require("../../../cloud/device/TuyaDevice");
5
+ function configureMotionDetected(accessory, service, schema) {
6
+ if (!schema) {
7
+ return;
8
+ }
9
+ if (!service) {
10
+ service = accessory.accessory.getService(accessory.Service.MotionSensor)
11
+ || accessory.accessory.addService(accessory.Service.MotionSensor);
12
+ }
13
+ service.getCharacteristic(accessory.Characteristic.MotionDetected)
14
+ .onGet(() => {
15
+ const status = accessory.getStatus(schema.code);
16
+ if (schema.type === TuyaDevice_1.TuyaDeviceSchemaType.Enum) { // pir
17
+ return (status.value === 'pir');
18
+ }
19
+ return false;
20
+ });
21
+ }
22
+ //# sourceMappingURL=MotionDetected.js.map
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureName = configureName;
4
+ const util_1 = require("../../util/util");
5
+ function configureName(accessory, service, name) {
6
+ const fallbackName = name.replace(/[^A-Za-z0-9 '\s]/g, ' ').replace(/\s+/g, ' ').trim();
7
+ const safeName = (0, util_1.sanitizeName)(name) ?? (fallbackName || 'Tuya Service');
8
+ service.setCharacteristic(accessory.Characteristic.Name, safeName);
9
+ if (!service.testCharacteristic(accessory.Characteristic.ConfiguredName)) {
10
+ service.addOptionalCharacteristic(accessory.Characteristic.ConfiguredName); // silence warning
11
+ }
12
+ // update every time so cached invalid names get corrected on restart
13
+ service.setCharacteristic(accessory.Characteristic.ConfiguredName, safeName);
14
+ }
15
+ //# sourceMappingURL=Name.js.map
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureOccupancyDetected = configureOccupancyDetected;
4
+ function configureOccupancyDetected(accessory, service, schema) {
5
+ if (!schema) {
6
+ return;
7
+ }
8
+ if (!service) {
9
+ service = accessory.accessory.getService(accessory.Service.OccupancySensor)
10
+ || accessory.accessory.addService(accessory.Service.OccupancySensor);
11
+ }
12
+ const { OCCUPANCY_DETECTED, OCCUPANCY_NOT_DETECTED } = accessory.Characteristic.OccupancyDetected;
13
+ service.getCharacteristic(accessory.Characteristic.OccupancyDetected)
14
+ .onGet(() => {
15
+ const status = accessory.getStatus(schema.code);
16
+ return (status.value === 'presence') ? OCCUPANCY_DETECTED : OCCUPANCY_NOT_DETECTED;
17
+ });
18
+ }
19
+ //# sourceMappingURL=OccupancyDetected.js.map
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureOn = configureOn;
4
+ function configureOn(accessory, service, schema) {
5
+ if (!schema) {
6
+ return;
7
+ }
8
+ if (!service) {
9
+ service = accessory.accessory.getService(schema.code)
10
+ || accessory.accessory.addService(accessory.Service.Switch, schema.code, schema.code);
11
+ }
12
+ service.getCharacteristic(accessory.Characteristic.On)
13
+ .onGet(() => {
14
+ accessory.checkOnlineStatus();
15
+ const status = accessory.getStatus(schema.code);
16
+ return status?.value ?? false;
17
+ })
18
+ .onSet(async (value) => {
19
+ await accessory.sendCommands([{
20
+ code: schema.code,
21
+ value: value,
22
+ }], true);
23
+ });
24
+ }
25
+ //# sourceMappingURL=On.js.map
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureOutletInUse = configureOutletInUse;
4
+ function configureOutletInUse(accessory, service, schema) {
5
+ if (!schema) {
6
+ return;
7
+ }
8
+ const test = accessory.getStatus(schema.code)?.value;
9
+ service?.getCharacteristic(accessory.Characteristic.OutletInUse)
10
+ .onGet(() => {
11
+ return test ? true : false;
12
+ });
13
+ }
14
+ //# sourceMappingURL=OutletInUse.js.map
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureProgrammableSwitchEvent = configureProgrammableSwitchEvent;
4
+ exports.onProgrammableSwitchEvent = onProgrammableSwitchEvent;
5
+ const TuyaDevice_1 = require("../../../cloud/device/TuyaDevice");
6
+ const SINGLE_PRESS = 0;
7
+ const DOUBLE_PRESS = 1;
8
+ const LONG_PRESS = 2;
9
+ function configureProgrammableSwitchEvent(accessory, service, schema) {
10
+ if (!schema) {
11
+ return;
12
+ }
13
+ let props;
14
+ if (schema.type === TuyaDevice_1.TuyaDeviceSchemaType.Enum) {
15
+ const { range } = schema.property;
16
+ props = GetStatelessSwitchProps(range.includes('click') || range.includes('single_click') || range.includes('1'), range.includes('double_click'), range.includes('press') || range.includes('long_press'));
17
+ }
18
+ else {
19
+ props = GetStatelessSwitchProps(true, false, false);
20
+ }
21
+ service.getCharacteristic(accessory.Characteristic.ProgrammableSwitchEvent)
22
+ .setProps(props);
23
+ }
24
+ function onProgrammableSwitchEvent(accessory, service, status) {
25
+ if (!accessory.initialized) {
26
+ return;
27
+ }
28
+ let value;
29
+ const schema = accessory.getSchema(status.code);
30
+ if (schema.type === TuyaDevice_1.TuyaDeviceSchemaType.Raw || schema.type === TuyaDevice_1.TuyaDeviceSchemaType.String) { // doorbell_pic or alarm_message
31
+ const url = Buffer.from(status.value, 'base64').toString('binary');
32
+ if (url.length === 0) {
33
+ return;
34
+ }
35
+ accessory.log.info('Alarm message:', url);
36
+ value = SINGLE_PRESS;
37
+ }
38
+ else if (schema.type === TuyaDevice_1.TuyaDeviceSchemaType.Enum) {
39
+ if (status.value === 'click' || status.value === 'single_click' || status.value === '1') {
40
+ value = SINGLE_PRESS;
41
+ }
42
+ else if (status.value === 'double_click') {
43
+ value = DOUBLE_PRESS;
44
+ }
45
+ else if (status.value === 'press' || status.value === 'long_press') {
46
+ value = LONG_PRESS;
47
+ }
48
+ }
49
+ else if (schema.type === TuyaDevice_1.TuyaDeviceSchemaType.Integer) {
50
+ if (status.value > 0) {
51
+ value = SINGLE_PRESS;
52
+ }
53
+ }
54
+ if (value === undefined) {
55
+ accessory.log.warn('Unknown ProgrammableSwitchEvent status:', status);
56
+ return;
57
+ }
58
+ accessory.log.debug('ProgrammableSwitchEvent updateValue: %o %o', status.code, value);
59
+ service.getCharacteristic(accessory.Characteristic.ProgrammableSwitchEvent)
60
+ .updateValue(value);
61
+ }
62
+ // Modified version of
63
+ // https://github.com/benzman81/homebridge-http-webhooks/blob/master/src/homekit/accessories/HttpWebHookStatelessSwitchAccessory.js
64
+ function GetStatelessSwitchProps(single_press, double_press, long_press) {
65
+ const props = {};
66
+ if (single_press) {
67
+ props.minValue = SINGLE_PRESS;
68
+ }
69
+ else if (double_press) {
70
+ props.minValue = DOUBLE_PRESS;
71
+ }
72
+ else if (long_press) {
73
+ props.minValue = LONG_PRESS;
74
+ }
75
+ if (single_press) {
76
+ props.maxValue = SINGLE_PRESS;
77
+ }
78
+ if (double_press) {
79
+ props.maxValue = DOUBLE_PRESS;
80
+ }
81
+ if (long_press) {
82
+ props.maxValue = LONG_PRESS;
83
+ }
84
+ if (single_press && !double_press && long_press) {
85
+ props.validValues = [SINGLE_PRESS, LONG_PRESS];
86
+ }
87
+ return props;
88
+ }
89
+ //# sourceMappingURL=ProgrammableSwitchEvent.js.map
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureRelativeHumidityDehumidifierThreshold = configureRelativeHumidityDehumidifierThreshold;
4
+ const util_1 = require("../../util/util");
5
+ function configureRelativeHumidityDehumidifierThreshold(accessory, service, schema) {
6
+ if (!schema) {
7
+ return;
8
+ }
9
+ const property = schema.property;
10
+ const multiple = Math.pow(10, property.scale);
11
+ const props = {
12
+ minValue: 0,
13
+ maxValue: 100,
14
+ minStep: Math.max(1, property.step / multiple),
15
+ };
16
+ accessory.log.debug('Set props for RelativeHumidityDehumidifierThreshold:', props);
17
+ service.getCharacteristic(accessory.Characteristic.RelativeHumidityDehumidifierThreshold)
18
+ .onGet(() => {
19
+ const status = accessory.getStatus(schema.code);
20
+ return (0, util_1.limit)(status.value / multiple, 0, 100);
21
+ })
22
+ .onSet(async (value) => {
23
+ const dehumidity_set = (0, util_1.limit)(value * multiple, property.min, property.max);
24
+ await accessory.sendCommands([{ code: schema.code, value: dehumidity_set }]);
25
+ })
26
+ .setProps(props);
27
+ }
28
+ //# sourceMappingURL=RelativeHumidityDehumidifierThreshold.js.map
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureRotationSpeed = configureRotationSpeed;
4
+ exports.configureRotationSpeedLevel = configureRotationSpeedLevel;
5
+ exports.configureRotationSpeedOn = configureRotationSpeedOn;
6
+ const util_1 = require("../../util/util");
7
+ function configureRotationSpeed(accessory, service, schema) {
8
+ if (!schema) {
9
+ return;
10
+ }
11
+ const property = schema.property;
12
+ const multiple = Math.pow(10, property.scale);
13
+ const props = {
14
+ minValue: property.min / multiple,
15
+ maxValue: property.max / multiple,
16
+ minStep: Math.max(1, property.step / multiple),
17
+ };
18
+ service.getCharacteristic(accessory.Characteristic.RotationSpeed)
19
+ .onGet(() => {
20
+ const status = accessory.getStatus(schema.code);
21
+ const value = status.value / multiple;
22
+ return (0, util_1.limit)(value, props.minValue, props.maxValue);
23
+ })
24
+ .onSet(async (value) => {
25
+ const speed = value * multiple;
26
+ await accessory.sendCommands([{ code: schema.code, value: speed }], true);
27
+ })
28
+ .setProps(props);
29
+ }
30
+ function configureRotationSpeedLevel(accessory, service, schema, ignoreValues) {
31
+ if (!schema) {
32
+ return;
33
+ }
34
+ const property = schema.property;
35
+ const range = [];
36
+ for (const value of property.range) {
37
+ if (ignoreValues?.includes(value)) {
38
+ continue;
39
+ }
40
+ range.push(value);
41
+ }
42
+ const props = { minValue: 0, maxValue: range.length, minStep: 1, unit: 'speed' };
43
+ accessory.log.debug('Set props for RotationSpeed:', props);
44
+ const onGetHandler = () => {
45
+ const status = accessory.getStatus(schema.code);
46
+ const index = range.indexOf(status.value);
47
+ return (0, util_1.limit)(index + 1, props.minValue, props.maxValue);
48
+ };
49
+ service.getCharacteristic(accessory.Characteristic.RotationSpeed)
50
+ .onGet(onGetHandler)
51
+ .onSet(async (value) => {
52
+ accessory.log.debug('Set RotationSpeed to:', value);
53
+ const index = Math.round(value - 1);
54
+ if (index < 0 || index >= range.length) {
55
+ accessory.log.debug('Out of range, return.');
56
+ return;
57
+ }
58
+ const speedLevel = range[index].toString();
59
+ accessory.log.debug('Set RotationSpeedLevel to:', speedLevel);
60
+ await accessory.sendCommands([{ code: schema.code, value: speedLevel }], true);
61
+ })
62
+ .updateValue(onGetHandler()) // ensure the value is correct before set props
63
+ .setProps(props);
64
+ }
65
+ function configureRotationSpeedOn(accessory, service, schema) {
66
+ if (!schema) {
67
+ return;
68
+ }
69
+ const props = { minValue: 0, maxValue: 100, minStep: 100 };
70
+ accessory.log.debug('Set props for RotationSpeed:', props);
71
+ service.getCharacteristic(accessory.Characteristic.RotationSpeed)
72
+ .onGet(() => {
73
+ const status = accessory.getStatus(schema.code);
74
+ return status.value ? 100 : 0;
75
+ })
76
+ .setProps(props);
77
+ }
78
+ //# sourceMappingURL=RotationSpeed.js.map