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,278 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const util_1 = require("../util/util");
7
+ const BaseAccessory_1 = __importDefault(require("./BaseAccessory"));
8
+ const POWER_OFF = 0;
9
+ const POWER_ON = 1;
10
+ const AC_MODE_COOL = 0;
11
+ const AC_MODE_HEAT = 1;
12
+ const AC_MODE_AUTO = 2;
13
+ const AC_MODE_FAN = 3;
14
+ const AC_MODE_DEHUMIDIFIER = 4;
15
+ const FAN_SPEED_AUTO = 0;
16
+ const FAN_SPEED_LOW = 1;
17
+ // const FAN_SPEED_MEDIUM = 2;
18
+ const FAN_SPEED_HIGH = 3;
19
+ class IRAirConditionerAccessory extends BaseAccessory_1.default {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.debounceSendACCommands = (0, util_1.debounce)(this.sendACCommands, 100);
23
+ }
24
+ configureServices() {
25
+ this.configureAirConditioner();
26
+ this.configureDehumidifier();
27
+ this.configureFan();
28
+ }
29
+ configureAirConditioner() {
30
+ const service = this.mainService();
31
+ const { INACTIVE, ACTIVE } = this.Characteristic.Active;
32
+ // Required Characteristics
33
+ service.getCharacteristic(this.Characteristic.Active)
34
+ .onGet(() => {
35
+ return ([AC_MODE_COOL, AC_MODE_HEAT, AC_MODE_AUTO].includes(this.getMode()) && this.getPower() === POWER_ON) ? ACTIVE : INACTIVE;
36
+ })
37
+ .onSet(async (value) => {
38
+ if (value === ACTIVE) {
39
+ // Turn off Dehumidifier & Fan
40
+ this.supportDehumidifier() && this.dehumidifierService().getCharacteristic(this.Characteristic.Active).updateValue(INACTIVE);
41
+ this.supportFan() && this.fanService().getCharacteristic(this.Characteristic.Active).updateValue(INACTIVE);
42
+ this.fanService().getCharacteristic(this.Characteristic.Active).value = INACTIVE;
43
+ }
44
+ if (value === ACTIVE && ![AC_MODE_COOL, AC_MODE_HEAT, AC_MODE_AUTO].includes(this.getMode())) {
45
+ this.setMode(AC_MODE_AUTO);
46
+ }
47
+ this.setPower((value === ACTIVE) ? POWER_ON : POWER_OFF);
48
+ });
49
+ const { IDLE } = this.Characteristic.CurrentHeaterCoolerState;
50
+ service.setCharacteristic(this.Characteristic.CurrentHeaterCoolerState, IDLE);
51
+ this.configureTargetState();
52
+ this.configureCurrentTemperature();
53
+ // Optional Characteristics
54
+ this.configureRotationSpeed(service);
55
+ const key_range = this.device.remote_keys?.key_range || [];
56
+ if (key_range.find(item => item.mode === AC_MODE_HEAT)) {
57
+ const [minValue, maxValue] = this.getTempRange(AC_MODE_HEAT);
58
+ service.getCharacteristic(this.Characteristic.HeatingThresholdTemperature)
59
+ .onGet(() => {
60
+ if (this.getMode() === AC_MODE_AUTO) {
61
+ return minValue;
62
+ }
63
+ return this.getTemp();
64
+ })
65
+ .onSet(async (value) => {
66
+ if (this.getMode() === AC_MODE_AUTO) {
67
+ return;
68
+ }
69
+ this.setTemp(value);
70
+ })
71
+ .setProps({ minValue, maxValue, minStep: 1 });
72
+ }
73
+ if (key_range.find(item => item.mode === AC_MODE_COOL)) {
74
+ const [minValue, maxValue] = this.getTempRange(AC_MODE_COOL);
75
+ service.getCharacteristic(this.Characteristic.CoolingThresholdTemperature)
76
+ .onGet(this.getTemp.bind(this))
77
+ .onSet(this.setTemp.bind(this))
78
+ .setProps({ minValue, maxValue, minStep: 1 });
79
+ }
80
+ }
81
+ configureDehumidifier() {
82
+ if (!this.supportDehumidifier()) {
83
+ return;
84
+ }
85
+ const service = this.dehumidifierService();
86
+ const { INACTIVE, ACTIVE } = this.Characteristic.Active;
87
+ // Required Characteristics
88
+ service.getCharacteristic(this.Characteristic.Active)
89
+ .onGet(() => {
90
+ return (this.getMode() === AC_MODE_DEHUMIDIFIER && this.getPower() === POWER_ON) ? ACTIVE : INACTIVE;
91
+ })
92
+ .onSet(async (value) => {
93
+ if (value === ACTIVE) {
94
+ // Turn off AC & Fan
95
+ this.mainService().getCharacteristic(this.Characteristic.Active).updateValue(INACTIVE);
96
+ this.supportFan() && this.fanService().getCharacteristic(this.Characteristic.Active).updateValue(INACTIVE);
97
+ }
98
+ this.setMode(AC_MODE_DEHUMIDIFIER);
99
+ this.setPower((value === ACTIVE) ? POWER_ON : POWER_OFF);
100
+ });
101
+ const { DEHUMIDIFYING } = this.Characteristic.CurrentHumidifierDehumidifierState;
102
+ service.setCharacteristic(this.Characteristic.CurrentHumidifierDehumidifierState, DEHUMIDIFYING);
103
+ const { DEHUMIDIFIER } = this.Characteristic.TargetHumidifierDehumidifierState;
104
+ service.getCharacteristic(this.Characteristic.TargetHumidifierDehumidifierState)
105
+ .updateValue(DEHUMIDIFIER)
106
+ .setProps({ validValues: [DEHUMIDIFIER] });
107
+ service.getCharacteristic(this.Characteristic.CurrentRelativeHumidity)
108
+ .onGet(() => {
109
+ const handler = this.getParentAccessory().accessory
110
+ .getService(this.Service.HumiditySensor)
111
+ ?.getCharacteristic(this.Characteristic.CurrentRelativeHumidity)['getHandler'];
112
+ const humidity = handler ? handler() : 0;
113
+ return humidity;
114
+ });
115
+ // Optional Characteristics
116
+ this.configureRotationSpeed(service);
117
+ }
118
+ configureFan() {
119
+ if (!this.supportFan()) {
120
+ return;
121
+ }
122
+ const service = this.fanService();
123
+ const { INACTIVE, ACTIVE } = this.Characteristic.Active;
124
+ // Required Characteristics
125
+ service.getCharacteristic(this.Characteristic.Active)
126
+ .onGet(() => {
127
+ return (this.getMode() === AC_MODE_FAN && this.getPower() === POWER_ON) ? ACTIVE : INACTIVE;
128
+ })
129
+ .onSet(async (value) => {
130
+ if (value === ACTIVE) {
131
+ // Turn off AC & Dehumidifier
132
+ this.mainService().getCharacteristic(this.Characteristic.Active).updateValue(INACTIVE);
133
+ this.supportDehumidifier() && this.dehumidifierService().getCharacteristic(this.Characteristic.Active).updateValue(INACTIVE);
134
+ }
135
+ this.setMode(AC_MODE_FAN);
136
+ this.setPower((value === ACTIVE) ? POWER_ON : POWER_OFF);
137
+ });
138
+ // Optional Characteristics
139
+ this.configureTargetFanState(service);
140
+ this.configureRotationSpeed(service);
141
+ }
142
+ mainService() {
143
+ return this.accessory.getService(this.Service.HeaterCooler)
144
+ || this.accessory.addService(this.Service.HeaterCooler);
145
+ }
146
+ dehumidifierService() {
147
+ return this.accessory.getService(this.Service.HumidifierDehumidifier)
148
+ || this.accessory.addService(this.Service.HumidifierDehumidifier, this.accessory.displayName + ' Dehumidifier');
149
+ }
150
+ fanService() {
151
+ return this.accessory.getService(this.Service.Fanv2)
152
+ || this.accessory.addService(this.Service.Fanv2, this.accessory.displayName + ' Fan');
153
+ }
154
+ getPower() {
155
+ const value = this.getStatus('power')?.value || '0';
156
+ return (value === true || parseInt(value.toString()) === 1) ? POWER_ON : POWER_OFF;
157
+ }
158
+ setPower(value) {
159
+ this.getStatus('power').value = value;
160
+ this.debounceSendACCommands();
161
+ }
162
+ getMode() {
163
+ const value = this.getStatus('mode')?.value || '0';
164
+ return parseInt(value.toString());
165
+ }
166
+ setMode(value) {
167
+ this.getStatus('mode').value = value;
168
+ this.debounceSendACCommands();
169
+ }
170
+ getWind() {
171
+ const value = this.getStatus('wind')?.value || '0';
172
+ return parseInt(value.toString());
173
+ }
174
+ setWind(value) {
175
+ this.getStatus('wind').value = value;
176
+ this.debounceSendACCommands();
177
+ }
178
+ getTemp() {
179
+ const value = this.getStatus('temp')?.value || '0';
180
+ return parseInt(value.toString());
181
+ }
182
+ setTemp(value) {
183
+ this.getStatus('temp').value = value;
184
+ this.debounceSendACCommands();
185
+ }
186
+ getKeyRangeItem(mode) {
187
+ const key_range = this.device.remote_keys?.key_range || [];
188
+ return key_range.find(item => item.mode === mode);
189
+ }
190
+ supportDehumidifier() {
191
+ return this.getKeyRangeItem(AC_MODE_DEHUMIDIFIER) !== undefined;
192
+ }
193
+ supportFan() {
194
+ return this.getKeyRangeItem(AC_MODE_FAN) !== undefined;
195
+ }
196
+ getTempRange(mode) {
197
+ const keyRangeItem = this.getKeyRangeItem(mode);
198
+ if (!keyRangeItem || !keyRangeItem.temp_list || keyRangeItem.temp_list.length === 0) {
199
+ return undefined;
200
+ }
201
+ const tempList = keyRangeItem.temp_list.map((temp) => temp.temp);
202
+ const min = Math.min(...tempList);
203
+ const max = Math.max(...tempList);
204
+ return [min, max];
205
+ }
206
+ getParentAccessory() {
207
+ return this.platform.accessoryHandlers.find(accessory => accessory.device.id === this.device.parent_id);
208
+ }
209
+ configureTargetState() {
210
+ const { AUTO, HEAT, COOL } = this.Characteristic.TargetHeaterCoolerState;
211
+ const validValues = [];
212
+ const key_range = this.device.remote_keys?.key_range || [];
213
+ if (key_range.find(item => item.mode === AC_MODE_AUTO)) {
214
+ validValues.push(AUTO);
215
+ }
216
+ if (key_range.find(item => item.mode === AC_MODE_HEAT)) {
217
+ validValues.push(HEAT);
218
+ }
219
+ if (key_range.find(item => item.mode === AC_MODE_COOL)) {
220
+ validValues.push(COOL);
221
+ }
222
+ if (validValues.length === 0) {
223
+ this.log.warn('Invalid mode range for TargetHeaterCoolerState:', key_range);
224
+ return;
225
+ }
226
+ this.mainService().getCharacteristic(this.Characteristic.TargetHeaterCoolerState)
227
+ .onGet(() => ({
228
+ [AC_MODE_COOL.toString()]: COOL,
229
+ [AC_MODE_HEAT.toString()]: HEAT,
230
+ [AC_MODE_AUTO.toString()]: AUTO,
231
+ }[this.getMode().toString()] || AUTO))
232
+ .onSet(async (value) => {
233
+ this.setMode({
234
+ [COOL.toString()]: AC_MODE_COOL,
235
+ [HEAT.toString()]: AC_MODE_HEAT,
236
+ [AUTO.toString()]: AC_MODE_AUTO,
237
+ }[value.toString()]);
238
+ })
239
+ .setProps({ validValues });
240
+ }
241
+ configureCurrentTemperature() {
242
+ this.mainService().getCharacteristic(this.Characteristic.CurrentTemperature)
243
+ .onGet(() => {
244
+ const handler = this.getParentAccessory().accessory
245
+ .getService(this.Service.TemperatureSensor)
246
+ ?.getCharacteristic(this.Characteristic.CurrentTemperature)['getHandler'];
247
+ const temp = handler ? handler() : this.getTemp();
248
+ return temp;
249
+ });
250
+ }
251
+ configureTargetFanState(service) {
252
+ const { MANUAL, AUTO } = this.Characteristic.TargetFanState;
253
+ service.getCharacteristic(this.Characteristic.TargetFanState)
254
+ .onGet(() => (this.getWind() === FAN_SPEED_AUTO) ? AUTO : MANUAL)
255
+ .onSet(async (value) => {
256
+ this.setWind((value === AUTO) ? FAN_SPEED_AUTO : FAN_SPEED_LOW);
257
+ });
258
+ }
259
+ configureRotationSpeed(service) {
260
+ service.getCharacteristic(this.Characteristic.RotationSpeed)
261
+ .onGet(() => (this.getWind() === FAN_SPEED_AUTO) ? FAN_SPEED_HIGH : this.getWind())
262
+ .onSet(async (value) => {
263
+ // if (this.getWind() === FAN_SPEED_AUTO) {
264
+ // return;
265
+ // }
266
+ if (value !== 0) {
267
+ this.setWind(value);
268
+ }
269
+ })
270
+ .setProps({ minValue: 0, maxValue: 3, minStep: 1, unit: 'speed' });
271
+ }
272
+ async sendACCommands() {
273
+ const { parent_id, id } = this.device;
274
+ await this.deviceManager.sendInfraredACCommands(parent_id, id, this.getPower(), this.getMode(), this.getTemp(), this.getWind());
275
+ }
276
+ }
277
+ exports.default = IRAirConditionerAccessory;
278
+ //# sourceMappingURL=IRAirConditionerAccessory.js.map
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const BaseAccessory_1 = __importDefault(require("./BaseAccessory"));
7
+ // import { configureCurrentAbsoluteHumidity } from './characteristic/CurrentAbsoluteHumidity';
8
+ const CurrentRelativeHumidity_1 = require("./characteristic/CurrentRelativeHumidity");
9
+ const CurrentTemperature_1 = require("./characteristic/CurrentTemperature");
10
+ const LightSensor_1 = require("./characteristic/LightSensor");
11
+ const SCHEMA_CODE = {
12
+ CURRENT_TEMP: ['va_temperature', 'temp_value'],
13
+ CURRENT_HUMIDITY: ['va_humidity', 'humidity_value'],
14
+ LIGHT_SENSOR: ['bright_value'],
15
+ };
16
+ class IRControlHubAccessory extends BaseAccessory_1.default {
17
+ requiredSchema() {
18
+ return [];
19
+ }
20
+ configureServices() {
21
+ (0, CurrentTemperature_1.configureCurrentTemperature)(this, undefined, this.getSchema(...SCHEMA_CODE.CURRENT_TEMP));
22
+ (0, CurrentRelativeHumidity_1.configureCurrentRelativeHumidity)(this, undefined, this.getSchema(...SCHEMA_CODE.CURRENT_HUMIDITY));
23
+ (0, LightSensor_1.configureLightSensor)(this, undefined, this.getSchema(...SCHEMA_CODE.LIGHT_SENSOR));
24
+ // eslint-disable-next-line max-len
25
+ // configureCurrentAbsoluteHumidity(this.platform.api, this, undefined, this.getSchema(...SCHEMA_CODE.CURRENT_HUMIDITY), this.getSchema(...SCHEMA_CODE.CURRENT_TEMP));
26
+ const key = `wbgt-${this.device.id}`;
27
+ const uuid = this.platform.api.hap.uuid.generate(key);
28
+ if (!this.deviceManager.devices.some(device => device.uuid === uuid)) {
29
+ this.log.info(`add wbgt device:${key}`);
30
+ const virtualDevice = this.deviceManager.createVirtualDevice(this.device, uuid);
31
+ virtualDevice.product_id = 'virtual-product-id-wbgt';
32
+ virtualDevice.category = 'wsdcg';
33
+ virtualDevice.name = 'WBGT';
34
+ this.deviceManager.devices.push(virtualDevice);
35
+ }
36
+ }
37
+ getSubAccessories() {
38
+ return this.platform.accessoryHandlers.filter(accessory => accessory.device.parent_id === this.device.id);
39
+ }
40
+ async onDeviceStatusUpdate(status) {
41
+ super.onDeviceStatusUpdate(status);
42
+ // Trigger sub device update temperature & humidity from parent device.
43
+ for (const subAccessory of this.getSubAccessories()) {
44
+ await subAccessory.updateAllValues();
45
+ }
46
+ }
47
+ }
48
+ exports.default = IRControlHubAccessory;
49
+ //# sourceMappingURL=IRControlHubAccessory.js.map
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const InfraredTool_1 = require("../util/InfraredTool");
7
+ const BaseAccessory_1 = __importDefault(require("./BaseAccessory"));
8
+ const Name_1 = require("./characteristic/Name");
9
+ class IRControlHubSubAccessory extends BaseAccessory_1.default {
10
+ configureServices() {
11
+ let key_list = this.device.remote_keys?.key_list || [];
12
+ // Max 99 services allowed (one for AccessoryInformation)
13
+ if (key_list.length > 99) {
14
+ this.log.warn(`Skipping ${key_list.length - 99} keys for ${this.device.name}, ` +
15
+ 'as we reached the limit of HomeKit (100 services per accessory)');
16
+ }
17
+ key_list = key_list.slice(0, 99);
18
+ for (const key of key_list) {
19
+ this.configureSwitch(key);
20
+ }
21
+ }
22
+ configureSwitch(key) {
23
+ const service = this.accessory.getService(key.key)
24
+ || this.accessory.addService(this.Service.Switch, key.key, key.key);
25
+ (0, Name_1.configureName)(this, service, key.key_name);
26
+ service.getCharacteristic(this.Characteristic.On)
27
+ .onGet(() => false)
28
+ .onSet(async (value) => {
29
+ if (value === false) {
30
+ return;
31
+ }
32
+ this.sendInfraredCommands(key);
33
+ setTimeout(() => {
34
+ service.getCharacteristic(this.Characteristic.On).updateValue(false);
35
+ }, 150);
36
+ });
37
+ }
38
+ async sendInfraredCommands(key) {
39
+ const { parent_id, id } = this.device;
40
+ const { category_id, remote_index } = this.device.remote_keys;
41
+ if (key.learning_code) {
42
+ const buffer = (0, InfraredTool_1.internalCodeToBase64)(key.learning_code, { trimPadding: true, endian: 'LE' });
43
+ const commands = [{ 'code': 'key_data', 'value': buffer }];
44
+ await this.deviceManager.sendCommands(parent_id || id, commands);
45
+ }
46
+ else {
47
+ await this.deviceManager.sendInfraredCommands(parent_id, id, category_id, remote_index, key.key, key.key_id);
48
+ }
49
+ }
50
+ }
51
+ exports.default = IRControlHubSubAccessory;
52
+ //# sourceMappingURL=IRControlHubSubAccessory.js.map
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const BaseAccessory_1 = __importDefault(require("./BaseAccessory"));
7
+ const Name_1 = require("./characteristic/Name");
8
+ class IRGenericAccessory extends BaseAccessory_1.default {
9
+ configureServices() {
10
+ let key_list = this.device.remote_keys?.key_list || [];
11
+ // Max 99 services allowed (one for AccessoryInformation)
12
+ if (key_list.length > 99) {
13
+ this.log.warn(`Skipping ${key_list.length - 99} keys for ${this.device.name}, ` +
14
+ 'as we reached the limit of HomeKit (100 services per accessory)');
15
+ }
16
+ key_list = key_list.slice(0, 99);
17
+ for (const key of key_list) {
18
+ this.configureSwitch(key);
19
+ }
20
+ }
21
+ configureSwitch(key) {
22
+ const service = this.accessory.getService(key.key)
23
+ || this.accessory.addService(this.Service.Switch, key.key, key.key);
24
+ (0, Name_1.configureName)(this, service, key.key_name);
25
+ service.getCharacteristic(this.Characteristic.On)
26
+ .onGet(() => false)
27
+ .onSet(async (value) => {
28
+ if (value === false) {
29
+ return;
30
+ }
31
+ this.sendInfraredCommands(key);
32
+ setTimeout(() => {
33
+ service.getCharacteristic(this.Characteristic.On).updateValue(false);
34
+ }, 150);
35
+ });
36
+ }
37
+ async sendInfraredCommands(key) {
38
+ const { parent_id, id } = this.device;
39
+ const { category_id, remote_index } = this.device.remote_keys;
40
+ if (key.learning_code) {
41
+ await this.deviceManager.sendInfraredDIYCommands(parent_id, id, key.learning_code);
42
+ }
43
+ else {
44
+ await this.deviceManager.sendInfraredCommands(parent_id, id, category_id, remote_index, key.key, key.key_id);
45
+ }
46
+ }
47
+ }
48
+ exports.default = IRGenericAccessory;
49
+ //# sourceMappingURL=IRGenericAccessory.js.map
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const BaseAccessory_1 = __importDefault(require("./BaseAccessory"));
7
+ const SCHEMA_CODE = {
8
+ LEAK: ['gas_sensor_status', 'gas_sensor_state', 'ch4_sensor_state', 'watersensor_state'],
9
+ };
10
+ class LeakSensor extends BaseAccessory_1.default {
11
+ requiredSchema() {
12
+ return [SCHEMA_CODE.LEAK];
13
+ }
14
+ configureServices() {
15
+ const { LEAK_NOT_DETECTED, LEAK_DETECTED } = this.Characteristic.LeakDetected;
16
+ const service = this.accessory.getService(this.Service.LeakSensor)
17
+ || this.accessory.addService(this.Service.LeakSensor);
18
+ service.getCharacteristic(this.Characteristic.LeakDetected)
19
+ .onGet(() => {
20
+ const gas = this.getStatus('gas_sensor_status')
21
+ || this.getStatus('gas_sensor_state');
22
+ const ch4 = this.getStatus('ch4_sensor_state');
23
+ const water = this.getStatus('watersensor_state');
24
+ if ((gas && (gas.value === 'alarm' || gas.value === '1'))
25
+ || (ch4 && ch4.value === 'alarm')
26
+ || (water && water.value === 'alarm')) {
27
+ return LEAK_DETECTED;
28
+ }
29
+ else {
30
+ return LEAK_NOT_DETECTED;
31
+ }
32
+ });
33
+ }
34
+ }
35
+ exports.default = LeakSensor;
36
+ //# sourceMappingURL=LeakSensorAccessory.js.map
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const BaseAccessory_1 = __importDefault(require("./BaseAccessory"));
7
+ const On_1 = require("./characteristic/On");
8
+ const MotionDetected_1 = require("./characteristic/MotionDetected");
9
+ const Light_1 = require("./characteristic/Light");
10
+ const SCHEMA_CODE = {
11
+ ON: ['switch_led'],
12
+ BRIGHTNESS: ['bright_value', 'bright_value_v2'],
13
+ COLOR_TEMP: ['temp_value', 'temp_value_v2'],
14
+ COLOR: ['colour_data', 'colour_data_v2'],
15
+ WORK_MODE: ['work_mode'],
16
+ PIR: ['pir_state'],
17
+ PIR_ON: ['switch_pir'],
18
+ POWER_SWITCH: ['switch'],
19
+ };
20
+ class LightAccessory extends BaseAccessory_1.default {
21
+ requiredSchema() {
22
+ return [SCHEMA_CODE.ON];
23
+ }
24
+ configureServices() {
25
+ const service = this.accessory.getService(this.Service.Lightbulb)
26
+ || this.accessory.addService(this.Service.Lightbulb);
27
+ (0, Light_1.configureLight)(this, service, this.getSchema(...SCHEMA_CODE.ON), this.getSchema(...SCHEMA_CODE.BRIGHTNESS), this.getSchema(...SCHEMA_CODE.COLOR_TEMP), this.getSchema(...SCHEMA_CODE.COLOR), this.getSchema(...SCHEMA_CODE.WORK_MODE));
28
+ // PIR
29
+ (0, On_1.configureOn)(this, undefined, this.getSchema(...SCHEMA_CODE.PIR_ON));
30
+ (0, MotionDetected_1.configureMotionDetected)(this, undefined, this.getSchema(...SCHEMA_CODE.PIR));
31
+ // RGB Power Switch
32
+ (0, On_1.configureOn)(this, undefined, this.getSchema(...SCHEMA_CODE.POWER_SWITCH));
33
+ }
34
+ }
35
+ exports.default = LightAccessory;
36
+ //# sourceMappingURL=LightAccessory.js.map
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const util_1 = require("../util/util");
7
+ const BaseAccessory_1 = __importDefault(require("./BaseAccessory"));
8
+ const SCHEMA_CODE = {
9
+ BRIGHT_LEVEL: ['bright_value'],
10
+ };
11
+ class LightSensorAccessory extends BaseAccessory_1.default {
12
+ requiredSchema() {
13
+ return [SCHEMA_CODE.BRIGHT_LEVEL];
14
+ }
15
+ configureServices() {
16
+ const schema = this.getSchema(...SCHEMA_CODE.BRIGHT_LEVEL);
17
+ if (!schema) {
18
+ return;
19
+ }
20
+ const service = this.accessory.getService(this.Service.LightSensor)
21
+ || this.accessory.addService(this.Service.LightSensor);
22
+ const property = schema.property;
23
+ const multiple = Math.pow(10, property ? property.scale : 0);
24
+ service.getCharacteristic(this.Characteristic.CurrentAmbientLightLevel)
25
+ .onGet(() => {
26
+ const status = this.getStatus(schema.code);
27
+ return (0, util_1.limit)(status.value / multiple, 0.0001, 100000);
28
+ });
29
+ }
30
+ }
31
+ exports.default = LightSensorAccessory;
32
+ //# sourceMappingURL=LightSensorAccessory.js.map
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const BaseAccessory_1 = __importDefault(require("./BaseAccessory"));
7
+ const CurrentWeather_1 = require("./characteristic/CurrentWeather");
8
+ const CurrentWeatherByOpenMeteo_1 = require("./characteristic/CurrentWeatherByOpenMeteo");
9
+ class LocationWeatherAccessory extends BaseAccessory_1.default {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.weatherConditionTuya = {
13
+ coordinate: {
14
+ lon: '0',
15
+ lat: '0',
16
+ },
17
+ air_quality: {
18
+ o3: '0',
19
+ pm10: '0',
20
+ co: '0',
21
+ no2: '0',
22
+ pm25: '0',
23
+ so2: '0',
24
+ aqi: '0',
25
+ },
26
+ current_weather: {
27
+ temp: '0',
28
+ real_feel: '0',
29
+ uvi: '0',
30
+ pressure: '0',
31
+ condition: '0',
32
+ condition_num: '0',
33
+ humidity: '0',
34
+ wind_speed: '0',
35
+ },
36
+ };
37
+ this.weatherConditionOpenMeteo = {
38
+ latitude: 0,
39
+ longitude: 0,
40
+ generationtime_ms: 0,
41
+ utc_offset_seconds: 0,
42
+ timezone: '',
43
+ timezone_abbreviation: '',
44
+ elevation: 0,
45
+ current_units: {
46
+ time: '',
47
+ interval: '',
48
+ temperature_2m: '',
49
+ relative_humidity_2m: '',
50
+ },
51
+ current: {
52
+ time: '',
53
+ interval: 0,
54
+ temperature_2m: 0,
55
+ relative_humidity_2m: 0,
56
+ },
57
+ };
58
+ }
59
+ requiredSchema() {
60
+ return [];
61
+ }
62
+ configureServices() {
63
+ if (this.platform.options.weatherAPI === 'Tuya') {
64
+ (0, CurrentWeather_1.configureCurrentWeather)(this, this.weatherConditionTuya);
65
+ }
66
+ else {
67
+ (0, CurrentWeatherByOpenMeteo_1.configureCurrentWeatherByOpenMeteo)(this, this.weatherConditionOpenMeteo);
68
+ }
69
+ }
70
+ }
71
+ exports.default = LocationWeatherAccessory;
72
+ //# sourceMappingURL=LocationWeatherAccessory.js.map
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const BaseAccessory_1 = __importDefault(require("./BaseAccessory"));
7
+ const SCHEMA_CODE = {
8
+ LOCK_CURRENT_STATE: ['open_close', 'closed_opened', 'lock_motor_state'],
9
+ LOCK_TARGET_STATE: ['lock_motor_state'],
10
+ };
11
+ class LockAccessory extends BaseAccessory_1.default {
12
+ requiredSchema() {
13
+ return [SCHEMA_CODE.LOCK_CURRENT_STATE];
14
+ }
15
+ configureServices() {
16
+ this.configureLockCurrentState();
17
+ this.configureLockTargetState();
18
+ }
19
+ mainService() {
20
+ return this.accessory.getService(this.Service.LockMechanism)
21
+ || this.accessory.addService(this.Service.LockMechanism);
22
+ }
23
+ configureLockCurrentState() {
24
+ const schema = this.getSchema(...SCHEMA_CODE.LOCK_CURRENT_STATE);
25
+ if (!schema) {
26
+ return;
27
+ }
28
+ const { UNSECURED, SECURED } = this.Characteristic.LockCurrentState;
29
+ this.mainService().getCharacteristic(this.Characteristic.LockCurrentState)
30
+ .onGet(() => {
31
+ const status = this.getStatus(schema.code);
32
+ return status.value ? UNSECURED : SECURED;
33
+ });
34
+ }
35
+ configureLockTargetState() {
36
+ const schema = this.getSchema(...SCHEMA_CODE.LOCK_TARGET_STATE);
37
+ if (!schema) {
38
+ return;
39
+ }
40
+ const { UNSECURED, SECURED } = this.Characteristic.LockTargetState;
41
+ this.mainService().getCharacteristic(this.Characteristic.LockTargetState)
42
+ .onGet(() => {
43
+ const status = this.getStatus(schema.code);
44
+ return status.value ? UNSECURED : SECURED;
45
+ })
46
+ .onSet(async (value) => {
47
+ const res = await this.deviceManager.getLockTemporaryKey(this.device.id);
48
+ if (!res.success) {
49
+ return;
50
+ }
51
+ await this.deviceManager.sendLockCommands(this.device.id, res.result.ticket_id, (value === UNSECURED));
52
+ });
53
+ }
54
+ }
55
+ exports.default = LockAccessory;
56
+ //# sourceMappingURL=LockAccessory.js.map