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,307 @@
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 CurrentRelativeHumidity_1 = require("./characteristic/CurrentRelativeHumidity");
9
+ const CurrentTemperature_1 = require("./characteristic/CurrentTemperature");
10
+ const LockPhysicalControls_1 = require("./characteristic/LockPhysicalControls");
11
+ const RelativeHumidityDehumidifierThreshold_1 = require("./characteristic/RelativeHumidityDehumidifierThreshold");
12
+ const RotationSpeed_1 = require("./characteristic/RotationSpeed");
13
+ // import { configureSwingMode } from './characteristic/SwingMode';
14
+ const TemperatureDisplayUnits_1 = require("./characteristic/TemperatureDisplayUnits");
15
+ const SCHEMA_CODE = {
16
+ // AirConditioner
17
+ ACTIVE: ['switch'],
18
+ MODE: ['mode'],
19
+ WORK_STATE: ['work_status', 'mode'],
20
+ CURRENT_TEMP: ['temp_current'],
21
+ TARGET_TEMP: ['temp_set'],
22
+ SPEED_LEVEL: ['fan_speed_enum', 'windspeed'],
23
+ LOCK: ['lock', 'child_lock'],
24
+ TEMP_UNIT_CONVERT: ['temp_unit_convert', 'c_f'],
25
+ SWING: ['switch_horizontal', 'switch_vertical'],
26
+ // Dehumidifier
27
+ CURRENT_HUMIDITY: ['humidity_current'],
28
+ TARGET_HUMIDITY: ['humidity_set'],
29
+ };
30
+ const AC_MODES = ['auto', 'cold', 'hot'];
31
+ const DEHUMIDIFIER_MODE = 'wet';
32
+ const FAN_MODE = 'wind';
33
+ class AirConditionerAccessory extends BaseAccessory_1.default {
34
+ requiredSchema() {
35
+ return [SCHEMA_CODE.ACTIVE, SCHEMA_CODE.MODE, SCHEMA_CODE.WORK_STATE, SCHEMA_CODE.CURRENT_TEMP];
36
+ }
37
+ configureServices() {
38
+ this.configureAirConditioner();
39
+ this.configureDehumidifier();
40
+ this.configureFan();
41
+ // Add extra sensors for home automation use.
42
+ (0, CurrentTemperature_1.configureCurrentTemperature)(this, undefined, this.getSchema(...SCHEMA_CODE.CURRENT_TEMP));
43
+ (0, CurrentRelativeHumidity_1.configureCurrentRelativeHumidity)(this, undefined, this.getSchema(...SCHEMA_CODE.CURRENT_HUMIDITY));
44
+ }
45
+ configureAirConditioner() {
46
+ const activeSchema = this.getSchema(...SCHEMA_CODE.ACTIVE);
47
+ const modeSchema = this.getSchema(...SCHEMA_CODE.MODE);
48
+ const modeProperty = modeSchema.property;
49
+ const service = this.mainService();
50
+ // Required Characteristics
51
+ const { INACTIVE, ACTIVE } = this.Characteristic.Active;
52
+ service.getCharacteristic(this.Characteristic.Active)
53
+ .onGet(() => {
54
+ const activeStatus = this.getStatus(activeSchema.code);
55
+ const modeStatus = this.getStatus(modeSchema.code);
56
+ return (activeStatus.value === true && AC_MODES.includes(modeStatus.value)) ? ACTIVE : INACTIVE;
57
+ })
58
+ .onSet(async (value) => {
59
+ const commands = [{
60
+ code: activeSchema.code,
61
+ value: (value === ACTIVE) ? true : false,
62
+ }];
63
+ const modeStatus = this.getStatus(modeSchema.code);
64
+ if (!AC_MODES.includes(modeStatus.value)) {
65
+ for (const mode of AC_MODES) {
66
+ if (modeProperty.range.includes(mode)) {
67
+ commands.push({ code: modeStatus.code, value: mode });
68
+ break;
69
+ }
70
+ }
71
+ }
72
+ await this.sendCommands(commands, true);
73
+ });
74
+ this.configureCurrentState();
75
+ this.configureTargetState();
76
+ (0, CurrentTemperature_1.configureCurrentTemperature)(this, service, this.getSchema(...SCHEMA_CODE.CURRENT_TEMP));
77
+ // Optional Characteristics
78
+ (0, LockPhysicalControls_1.configureLockPhysicalControls)(this, service, this.getSchema(...SCHEMA_CODE.LOCK));
79
+ (0, RotationSpeed_1.configureRotationSpeedLevel)(this, service, this.getSchema(...SCHEMA_CODE.SPEED_LEVEL), ['auto']);
80
+ // configureSwingMode(this, service, this.getSchema(...SCHEMA_CODE.SWING));
81
+ this.configureCoolingThreshouldTemp();
82
+ this.configureHeatingThreshouldTemp();
83
+ (0, TemperatureDisplayUnits_1.configureTempDisplayUnits)(this, service, this.getSchema(...SCHEMA_CODE.TEMP_UNIT_CONVERT));
84
+ }
85
+ configureDehumidifier() {
86
+ const activeSchema = this.getSchema(...SCHEMA_CODE.ACTIVE);
87
+ const modeSchema = this.getSchema(...SCHEMA_CODE.MODE);
88
+ const property = modeSchema.property;
89
+ if (!property.range.includes(DEHUMIDIFIER_MODE)) {
90
+ return;
91
+ }
92
+ const service = this.dehumidifierService();
93
+ // Required Characteristics
94
+ const { INACTIVE, ACTIVE } = this.Characteristic.Active;
95
+ service.getCharacteristic(this.Characteristic.Active)
96
+ .onGet(() => {
97
+ const activeStatus = this.getStatus(activeSchema.code);
98
+ const modeStatus = this.getStatus(modeSchema.code);
99
+ return (activeStatus.value === true && modeStatus.value === DEHUMIDIFIER_MODE) ? ACTIVE : INACTIVE;
100
+ })
101
+ .onSet(async (value) => {
102
+ await this.sendCommands([{
103
+ code: activeSchema.code,
104
+ value: (value === ACTIVE) ? true : false,
105
+ }, {
106
+ code: modeSchema.code,
107
+ value: DEHUMIDIFIER_MODE,
108
+ }], true);
109
+ });
110
+ const { DEHUMIDIFYING } = this.Characteristic.CurrentHumidifierDehumidifierState;
111
+ service.setCharacteristic(this.Characteristic.CurrentHumidifierDehumidifierState, DEHUMIDIFYING);
112
+ const { DEHUMIDIFIER } = this.Characteristic.TargetHumidifierDehumidifierState;
113
+ service.getCharacteristic(this.Characteristic.TargetHumidifierDehumidifierState)
114
+ .updateValue(DEHUMIDIFIER)
115
+ .setProps({ validValues: [DEHUMIDIFIER] });
116
+ if (this.getSchema(...SCHEMA_CODE.CURRENT_HUMIDITY)) {
117
+ (0, CurrentRelativeHumidity_1.configureCurrentRelativeHumidity)(this, service, this.getSchema(...SCHEMA_CODE.CURRENT_HUMIDITY));
118
+ }
119
+ else {
120
+ service.setCharacteristic(this.Characteristic.CurrentRelativeHumidity, 0);
121
+ }
122
+ // Optional Characteristics
123
+ (0, LockPhysicalControls_1.configureLockPhysicalControls)(this, service, this.getSchema(...SCHEMA_CODE.LOCK));
124
+ (0, RotationSpeed_1.configureRotationSpeedLevel)(this, service, this.getSchema(...SCHEMA_CODE.SPEED_LEVEL), ['auto']);
125
+ (0, RelativeHumidityDehumidifierThreshold_1.configureRelativeHumidityDehumidifierThreshold)(this, service, this.getSchema(...SCHEMA_CODE.TARGET_HUMIDITY));
126
+ // configureSwingMode(this, service, this.getSchema(...SCHEMA_CODE.SWING));
127
+ }
128
+ configureFan() {
129
+ const activeSchema = this.getSchema(...SCHEMA_CODE.ACTIVE);
130
+ const modeSchema = this.getSchema(...SCHEMA_CODE.MODE);
131
+ const property = modeSchema.property;
132
+ if (!property.range.includes(FAN_MODE)) {
133
+ return;
134
+ }
135
+ const service = this.fanService();
136
+ // Required Characteristics
137
+ const { INACTIVE, ACTIVE } = this.Characteristic.Active;
138
+ service.getCharacteristic(this.Characteristic.Active)
139
+ .onGet(() => {
140
+ const activeStatus = this.getStatus(activeSchema.code);
141
+ const modeStatus = this.getStatus(modeSchema.code);
142
+ return (activeStatus.value === true && modeStatus.value === FAN_MODE) ? ACTIVE : INACTIVE;
143
+ })
144
+ .onSet(async (value) => {
145
+ await this.sendCommands([{
146
+ code: activeSchema.code,
147
+ value: (value === ACTIVE) ? true : false,
148
+ }, {
149
+ code: modeSchema.code,
150
+ value: FAN_MODE,
151
+ }], true);
152
+ });
153
+ // Optional Characteristics
154
+ (0, LockPhysicalControls_1.configureLockPhysicalControls)(this, service, this.getSchema(...SCHEMA_CODE.LOCK));
155
+ (0, RotationSpeed_1.configureRotationSpeedLevel)(this, service, this.getSchema(...SCHEMA_CODE.SPEED_LEVEL), ['auto']);
156
+ // configureSwingMode(this, service, this.getSchema(...SCHEMA_CODE.SWING));
157
+ }
158
+ mainService() {
159
+ return this.accessory.getService(this.Service.HeaterCooler)
160
+ || this.accessory.addService(this.Service.HeaterCooler);
161
+ }
162
+ dehumidifierService() {
163
+ return this.accessory.getService(this.Service.HumidifierDehumidifier)
164
+ || this.accessory.addService(this.Service.HumidifierDehumidifier, this.accessory.displayName + ' Dehumidifier');
165
+ }
166
+ fanService() {
167
+ return this.accessory.getService(this.Service.Fanv2)
168
+ || this.accessory.addService(this.Service.Fanv2, this.accessory.displayName + ' Fan');
169
+ }
170
+ configureCurrentState() {
171
+ const schema = this.getSchema(...SCHEMA_CODE.WORK_STATE);
172
+ if (!schema) {
173
+ return;
174
+ }
175
+ const { INACTIVE, HEATING, COOLING } = this.Characteristic.CurrentHeaterCoolerState;
176
+ this.mainService().getCharacteristic(this.Characteristic.CurrentHeaterCoolerState)
177
+ .onGet(() => {
178
+ const status = this.getStatus(schema.code);
179
+ if (status.value === 'heating' || status.value === 'hot') {
180
+ return HEATING;
181
+ }
182
+ else if (status.value === 'cooling' || status.value === 'cold') {
183
+ return COOLING;
184
+ }
185
+ else {
186
+ return INACTIVE;
187
+ }
188
+ });
189
+ }
190
+ configureTargetState() {
191
+ const schema = this.getSchema(...SCHEMA_CODE.MODE);
192
+ if (!schema) {
193
+ return;
194
+ }
195
+ const { AUTO, HEAT, COOL } = this.Characteristic.TargetHeaterCoolerState;
196
+ const validValues = [];
197
+ const property = schema.property;
198
+ if (property.range.includes('auto')) {
199
+ validValues.push(AUTO);
200
+ }
201
+ if (property.range.includes('hot')) {
202
+ validValues.push(HEAT);
203
+ }
204
+ if (property.range.includes('cold')) {
205
+ validValues.push(COOL);
206
+ }
207
+ if (validValues.length === 0) {
208
+ this.log.warn('Invalid mode range for TargetHeaterCoolerState:', property.range);
209
+ return;
210
+ }
211
+ this.mainService().getCharacteristic(this.Characteristic.TargetHeaterCoolerState)
212
+ .onGet(() => {
213
+ const status = this.getStatus(schema.code);
214
+ if (status.value === 'hot') {
215
+ return HEAT;
216
+ }
217
+ else if (status.value === 'cold') {
218
+ return COOL;
219
+ }
220
+ return validValues.includes(AUTO) ? AUTO : validValues[0];
221
+ })
222
+ .onSet(async (value) => {
223
+ let mode;
224
+ if (value === HEAT) {
225
+ mode = 'hot';
226
+ }
227
+ else if (value === COOL) {
228
+ mode = 'cold';
229
+ }
230
+ else {
231
+ mode = 'auto';
232
+ }
233
+ await this.sendCommands([{ code: schema.code, value: mode }], true);
234
+ })
235
+ .setProps({ validValues });
236
+ }
237
+ configureCoolingThreshouldTemp() {
238
+ const schema = this.getSchema(...SCHEMA_CODE.TARGET_TEMP);
239
+ if (!schema) {
240
+ return;
241
+ }
242
+ const property = schema.property;
243
+ const multiple = Math.pow(10, property.scale);
244
+ const props = {
245
+ minValue: property.min / multiple,
246
+ maxValue: property.max / multiple,
247
+ minStep: Math.max(0.1, property.step / multiple),
248
+ };
249
+ this.log.debug('Set props for CoolingThresholdTemperature:', props);
250
+ this.mainService().getCharacteristic(this.Characteristic.CoolingThresholdTemperature)
251
+ .onGet(() => {
252
+ const modeSchema = this.getSchema(...SCHEMA_CODE.MODE);
253
+ if (modeSchema && this.getStatus(modeSchema.code).value === 'auto') {
254
+ return props.minValue;
255
+ }
256
+ const status = this.getStatus(schema.code);
257
+ const temp = status.value / multiple;
258
+ return (0, util_1.limit)(temp, props.minValue, props.maxValue);
259
+ })
260
+ .onSet(async (value) => {
261
+ const modeSchema = this.getSchema(...SCHEMA_CODE.MODE);
262
+ if (modeSchema && this.getStatus(modeSchema.code).value === 'auto') {
263
+ this.mainService().getCharacteristic(this.Characteristic.CoolingThresholdTemperature)
264
+ .updateValue(props.minValue);
265
+ return;
266
+ }
267
+ await this.sendCommands([{ code: schema.code, value: value * multiple }], true);
268
+ })
269
+ .setProps(props);
270
+ }
271
+ configureHeatingThreshouldTemp() {
272
+ const schema = this.getSchema(...SCHEMA_CODE.TARGET_TEMP);
273
+ if (!schema) {
274
+ return;
275
+ }
276
+ const property = schema.property;
277
+ const multiple = Math.pow(10, property.scale);
278
+ const props = {
279
+ minValue: property.min / multiple,
280
+ maxValue: property.max / multiple,
281
+ minStep: Math.max(0.1, property.step / multiple),
282
+ };
283
+ this.log.debug('Set props for HeatingThresholdTemperature:', props);
284
+ this.mainService().getCharacteristic(this.Characteristic.HeatingThresholdTemperature)
285
+ .onGet(() => {
286
+ const modeSchema = this.getSchema(...SCHEMA_CODE.MODE);
287
+ if (modeSchema && this.getStatus(modeSchema.code).value === 'auto') {
288
+ return props.maxValue;
289
+ }
290
+ const status = this.getStatus(schema.code);
291
+ const temp = status.value / multiple;
292
+ return (0, util_1.limit)(temp, props.minValue, props.maxValue);
293
+ })
294
+ .onSet(async (value) => {
295
+ const modeSchema = this.getSchema(...SCHEMA_CODE.MODE);
296
+ if (modeSchema && this.getStatus(modeSchema.code).value === 'auto') {
297
+ this.mainService().getCharacteristic(this.Characteristic.HeatingThresholdTemperature)
298
+ .updateValue(props.maxValue);
299
+ return;
300
+ }
301
+ await this.sendCommands([{ code: schema.code, value: value * multiple }], true);
302
+ })
303
+ .setProps(props);
304
+ }
305
+ }
306
+ exports.default = AirConditionerAccessory;
307
+ //# sourceMappingURL=AirConditionerAccessory.js.map
@@ -0,0 +1,90 @@
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 TuyaDevice_1 = require("../../cloud/device/TuyaDevice");
7
+ const BaseAccessory_1 = __importDefault(require("./BaseAccessory"));
8
+ const Active_1 = require("./characteristic/Active");
9
+ const AirQuality_1 = require("./characteristic/AirQuality");
10
+ const LockPhysicalControls_1 = require("./characteristic/LockPhysicalControls");
11
+ const RotationSpeed_1 = require("./characteristic/RotationSpeed");
12
+ const SCHEMA_CODE = {
13
+ ACTIVE: ['switch'],
14
+ MODE: ['mode'],
15
+ LOCK: ['lock'],
16
+ SPEED: ['speed'],
17
+ SPEED_LEVEL: ['fan_speed_enum', 'speed'],
18
+ AIR_QUALITY: ['air_quality', 'pm25'],
19
+ PM2_5: ['pm25'],
20
+ VOC: ['tvoc'],
21
+ };
22
+ class AirPurifierAccessory extends BaseAccessory_1.default {
23
+ requiredSchema() {
24
+ return [SCHEMA_CODE.ACTIVE];
25
+ }
26
+ configureServices() {
27
+ (0, Active_1.configureActive)(this, this.mainService(), this.getSchema(...SCHEMA_CODE.ACTIVE));
28
+ this.configureCurrentState();
29
+ this.configureTargetState();
30
+ (0, LockPhysicalControls_1.configureLockPhysicalControls)(this, this.mainService(), this.getSchema(...SCHEMA_CODE.LOCK));
31
+ if (this.getFanSpeedSchema()) {
32
+ (0, RotationSpeed_1.configureRotationSpeed)(this, this.mainService(), this.getFanSpeedSchema());
33
+ }
34
+ else if (this.getFanSpeedLevelSchema()) {
35
+ (0, RotationSpeed_1.configureRotationSpeedLevel)(this, this.mainService(), this.getFanSpeedLevelSchema());
36
+ }
37
+ // Other
38
+ (0, AirQuality_1.configureAirQuality)(this, undefined, this.getSchema(...SCHEMA_CODE.AIR_QUALITY), this.getSchema(...SCHEMA_CODE.PM2_5), undefined, this.getSchema(...SCHEMA_CODE.VOC));
39
+ }
40
+ mainService() {
41
+ return this.accessory.getService(this.Service.AirPurifier)
42
+ || this.accessory.addService(this.Service.AirPurifier);
43
+ }
44
+ getFanSpeedSchema() {
45
+ const schema = this.getSchema(...SCHEMA_CODE.SPEED);
46
+ if (schema && schema.type === TuyaDevice_1.TuyaDeviceSchemaType.Integer) {
47
+ return schema;
48
+ }
49
+ return undefined;
50
+ }
51
+ getFanSpeedLevelSchema() {
52
+ const schema = this.getSchema(...SCHEMA_CODE.SPEED_LEVEL);
53
+ if (schema && schema.type === TuyaDevice_1.TuyaDeviceSchemaType.Enum) {
54
+ return schema;
55
+ }
56
+ return undefined;
57
+ }
58
+ configureCurrentState() {
59
+ const schema = this.getSchema(...SCHEMA_CODE.ACTIVE);
60
+ if (!schema) {
61
+ return;
62
+ }
63
+ const { INACTIVE, PURIFYING_AIR } = this.Characteristic.CurrentAirPurifierState;
64
+ this.mainService().getCharacteristic(this.Characteristic.CurrentAirPurifierState)
65
+ .onGet(() => {
66
+ const status = this.getStatus(schema.code);
67
+ return status.value ? PURIFYING_AIR : INACTIVE;
68
+ });
69
+ }
70
+ configureTargetState() {
71
+ const schema = this.getSchema(...SCHEMA_CODE.MODE);
72
+ if (!schema) {
73
+ return;
74
+ }
75
+ const { MANUAL, AUTO } = this.Characteristic.TargetAirPurifierState;
76
+ this.mainService().getCharacteristic(this.Characteristic.TargetAirPurifierState)
77
+ .onGet(() => {
78
+ const status = this.getStatus(schema.code);
79
+ return (status.value === 'auto') ? AUTO : MANUAL;
80
+ })
81
+ .onSet(async (value) => {
82
+ await this.sendCommands([{
83
+ code: schema.code,
84
+ value: (value === AUTO) ? 'auto' : 'manual',
85
+ }], true);
86
+ });
87
+ }
88
+ }
89
+ exports.default = AirPurifierAccessory;
90
+ //# sourceMappingURL=AirPurifierAccessory.js.map
@@ -0,0 +1,30 @@
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 AirQuality_1 = require("./characteristic/AirQuality");
8
+ const CurrentRelativeHumidity_1 = require("./characteristic/CurrentRelativeHumidity");
9
+ const CurrentTemperature_1 = require("./characteristic/CurrentTemperature");
10
+ const SCHEMA_CODE = {
11
+ AIR_QUALITY: ['pm25_value'],
12
+ PM2_5: ['pm25_value'],
13
+ PM10: ['pm10_value', 'pm10'],
14
+ VOC: ['voc_value'],
15
+ CURRENT_TEMP: ['va_temperature', 'temp_indoor', 'temp_current'],
16
+ CURRENT_HUMIDITY: ['va_humidity', 'humidity_value'],
17
+ };
18
+ class AirQualitySensorAccessory extends BaseAccessory_1.default {
19
+ requiredSchema() {
20
+ return [SCHEMA_CODE.AIR_QUALITY];
21
+ }
22
+ configureServices() {
23
+ (0, AirQuality_1.configureAirQuality)(this, undefined, this.getSchema(...SCHEMA_CODE.AIR_QUALITY), this.getSchema(...SCHEMA_CODE.PM2_5), this.getSchema(...SCHEMA_CODE.PM10), this.getSchema(...SCHEMA_CODE.VOC));
24
+ // Other
25
+ (0, CurrentTemperature_1.configureCurrentTemperature)(this, undefined, this.getSchema(...SCHEMA_CODE.CURRENT_TEMP));
26
+ (0, CurrentRelativeHumidity_1.configureCurrentRelativeHumidity)(this, undefined, this.getSchema(...SCHEMA_CODE.CURRENT_HUMIDITY));
27
+ }
28
+ }
29
+ exports.default = AirQualitySensorAccessory;
30
+ //# sourceMappingURL=AirQualitySensorAccessory.js.map