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,121 @@
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 TuyaStreamDelegate_1 = require("../util/TuyaStreamDelegate");
7
+ const BaseAccessory_1 = __importDefault(require("./BaseAccessory"));
8
+ const Light_1 = require("./characteristic/Light");
9
+ const On_1 = require("./characteristic/On");
10
+ const ProgrammableSwitchEvent_1 = require("./characteristic/ProgrammableSwitchEvent");
11
+ const SCHEMA_CODE = {
12
+ MOTION_ON: ['motion_switch'],
13
+ MOTION_DETECT: ['movement_detect_pic'],
14
+ // Indicates that this is possibly a doorbell
15
+ DOORBELL: ['doorbell_ring_exist'],
16
+ // Notifies when a doorbell ring occurs.
17
+ DOORBELL_RING: ['doorbell_pic'],
18
+ // Notifies when a doorbell ring occurs.
19
+ ALARM_MESSAGE: ['alarm_message'],
20
+ LIGHT_ON: ['floodlight_switch'],
21
+ LIGHT_BRIGHT: ['floodlight_lightness'],
22
+ };
23
+ class CameraAccessory extends BaseAccessory_1.default {
24
+ requiredSchema() {
25
+ return [];
26
+ }
27
+ configureServices() {
28
+ this.configureDoorbell();
29
+ this.configureCamera();
30
+ this.configureMotion();
31
+ this.configureFloodLight();
32
+ }
33
+ configureMotion() {
34
+ const onSchema = this.getSchema(...SCHEMA_CODE.MOTION_ON);
35
+ if (onSchema) {
36
+ const onService = this.accessory.getService(onSchema.code)
37
+ || this.accessory.addService(this.Service.Switch, onSchema.code, onSchema.code);
38
+ (0, On_1.configureOn)(this, onService, onSchema);
39
+ }
40
+ this.getMotionService().setCharacteristic(this.Characteristic.MotionDetected, false);
41
+ }
42
+ configureDoorbell() {
43
+ // Check to see if it is indeed a doorbell.
44
+ if (!this.getSchema(...SCHEMA_CODE.DOORBELL)) {
45
+ return;
46
+ }
47
+ const schema = this.getSchema(...SCHEMA_CODE.DOORBELL_RING, ...SCHEMA_CODE.ALARM_MESSAGE);
48
+ if (!schema) {
49
+ return;
50
+ }
51
+ (0, ProgrammableSwitchEvent_1.configureProgrammableSwitchEvent)(this, this.getDoorbellService(), schema);
52
+ }
53
+ configureCamera() {
54
+ if (this.stream !== undefined) {
55
+ return;
56
+ }
57
+ if (this.device.isVirtualDevice()) {
58
+ return;
59
+ }
60
+ this.stream = new TuyaStreamDelegate_1.TuyaStreamingDelegate(this);
61
+ this.accessory.configureController(this.stream.controller);
62
+ }
63
+ configureFloodLight() {
64
+ if (!this.getSchema(...SCHEMA_CODE.LIGHT_ON)) {
65
+ return;
66
+ }
67
+ (0, Light_1.configureLight)(this, this.getLightService(), this.getSchema(...SCHEMA_CODE.LIGHT_ON), this.getSchema(...SCHEMA_CODE.LIGHT_BRIGHT), undefined, undefined, undefined);
68
+ }
69
+ getLightService() {
70
+ return this.accessory.getService(this.Service.Lightbulb)
71
+ || this.accessory.addService(this.Service.Lightbulb, this.accessory.displayName + ' Floodlight');
72
+ }
73
+ getDoorbellService() {
74
+ return this.accessory.getService(this.Service.Doorbell)
75
+ || this.accessory.addService(this.Service.Doorbell);
76
+ }
77
+ getMotionService() {
78
+ return this.accessory.getService(this.Service.MotionSensor)
79
+ || this.accessory.addService(this.Service.MotionSensor, this.accessory.displayName + ' Motion Detect');
80
+ }
81
+ async onDeviceStatusUpdate(status) {
82
+ super.onDeviceStatusUpdate(status);
83
+ const doorbellRingSchema = this.getSchema(...SCHEMA_CODE.DOORBELL_RING);
84
+ const alarmMessageSchema = this.getSchema(...SCHEMA_CODE.ALARM_MESSAGE);
85
+ if (this.getSchema(...SCHEMA_CODE.DOORBELL) && (doorbellRingSchema || alarmMessageSchema)) {
86
+ const doorbellRingStatus = doorbellRingSchema && status.find(_status => _status.code === doorbellRingSchema.code);
87
+ const alarmMessageStatus = alarmMessageSchema && status.find(_status => _status.code === alarmMessageSchema.code);
88
+ if (doorbellRingStatus && doorbellRingStatus.value.length > 1) { // Compared with '1' in order to filter value '$'
89
+ (0, ProgrammableSwitchEvent_1.onProgrammableSwitchEvent)(this, this.getDoorbellService(), doorbellRingStatus);
90
+ }
91
+ else if (alarmMessageStatus && alarmMessageStatus.value.length > 1) {
92
+ (0, ProgrammableSwitchEvent_1.onProgrammableSwitchEvent)(this, this.getDoorbellService(), alarmMessageStatus);
93
+ }
94
+ }
95
+ const motionSchema = this.getSchema(...SCHEMA_CODE.MOTION_DETECT);
96
+ if (motionSchema) {
97
+ const motionStatus = status.find(_status => _status.code === motionSchema.code);
98
+ if (motionStatus) {
99
+ this.onMotionDetected(motionStatus);
100
+ }
101
+ }
102
+ }
103
+ onMotionDetected(status) {
104
+ if (!this.initialized) {
105
+ return;
106
+ }
107
+ const data = Buffer.from(status.value, 'base64').toString('binary');
108
+ if (data.length === 0) {
109
+ return;
110
+ }
111
+ this.log.info('Motion event:', data);
112
+ const characteristic = this.getMotionService().getCharacteristic(this.Characteristic.MotionDetected);
113
+ characteristic.updateValue(true);
114
+ if (this.timer) {
115
+ clearTimeout(this.timer);
116
+ }
117
+ this.timer = setTimeout(() => characteristic.updateValue(false), 30 * 1000);
118
+ }
119
+ }
120
+ exports.default = CameraAccessory;
121
+ //# sourceMappingURL=CameraAccessory.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 util_1 = require("../util/util");
7
+ const BaseAccessory_1 = __importDefault(require("./BaseAccessory"));
8
+ const SCHEMA_CODE = {
9
+ CO2_STATUS: ['co2_state'],
10
+ CO2_LEVEL: ['co2_value'],
11
+ };
12
+ class CarbonDioxideSensorAccessory extends BaseAccessory_1.default {
13
+ requiredSchema() {
14
+ return [SCHEMA_CODE.CO2_STATUS];
15
+ }
16
+ configureServices() {
17
+ this.configureCarbonDioxideDetected();
18
+ this.configureCarbonDioxideLevel();
19
+ }
20
+ mainService() {
21
+ return this.accessory.getService(this.Service.CarbonDioxideSensor)
22
+ || this.accessory.addService(this.Service.CarbonDioxideSensor);
23
+ }
24
+ configureCarbonDioxideDetected() {
25
+ const schema = this.getSchema(...SCHEMA_CODE.CO2_STATUS);
26
+ if (!schema) {
27
+ return;
28
+ }
29
+ const { CO2_LEVELS_ABNORMAL, CO2_LEVELS_NORMAL } = this.Characteristic.CarbonDioxideDetected;
30
+ this.mainService().getCharacteristic(this.Characteristic.CarbonDioxideDetected)
31
+ .onGet(() => {
32
+ const status = this.getStatus(schema.code);
33
+ return (status.value === 'alarm') ? CO2_LEVELS_ABNORMAL : CO2_LEVELS_NORMAL;
34
+ });
35
+ }
36
+ configureCarbonDioxideLevel() {
37
+ const schema = this.getSchema(...SCHEMA_CODE.CO2_LEVEL);
38
+ if (!schema) {
39
+ return;
40
+ }
41
+ const property = schema.property;
42
+ const multiple = Math.pow(10, property ? property.scale : 0);
43
+ this.mainService().getCharacteristic(this.Characteristic.CarbonDioxideLevel)
44
+ .onGet(() => {
45
+ const status = this.getStatus(schema.code);
46
+ const value = (0, util_1.limit)(status.value / multiple, 0, 100000);
47
+ return value;
48
+ });
49
+ }
50
+ }
51
+ exports.default = CarbonDioxideSensorAccessory;
52
+ //# sourceMappingURL=CarbonDioxideSensorAccessory.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 util_1 = require("../util/util");
7
+ const BaseAccessory_1 = __importDefault(require("./BaseAccessory"));
8
+ const SCHEMA_CODE = {
9
+ CO_STATUS: ['co_status', 'co_state'],
10
+ CO_LEVEL: ['co_value'],
11
+ };
12
+ class CarbonMonoxideSensorAccessory extends BaseAccessory_1.default {
13
+ requiredSchema() {
14
+ return [SCHEMA_CODE.CO_STATUS];
15
+ }
16
+ configureServices() {
17
+ this.configureCarbonMonoxideDetected();
18
+ this.configureCarbonMonoxideLevel();
19
+ }
20
+ mainService() {
21
+ return this.accessory.getService(this.Service.CarbonMonoxideSensor)
22
+ || this.accessory.addService(this.Service.CarbonMonoxideSensor);
23
+ }
24
+ configureCarbonMonoxideDetected() {
25
+ const schema = this.getSchema(...SCHEMA_CODE.CO_STATUS);
26
+ if (!schema) {
27
+ return;
28
+ }
29
+ const { CO_LEVELS_ABNORMAL, CO_LEVELS_NORMAL } = this.Characteristic.CarbonMonoxideDetected;
30
+ this.mainService().getCharacteristic(this.Characteristic.CarbonMonoxideDetected)
31
+ .onGet(() => {
32
+ const status = this.getStatus(schema.code);
33
+ return (status.value === 'alarm' || status.value === '1') ? CO_LEVELS_ABNORMAL : CO_LEVELS_NORMAL;
34
+ });
35
+ }
36
+ configureCarbonMonoxideLevel() {
37
+ const schema = this.getSchema(...SCHEMA_CODE.CO_LEVEL);
38
+ if (!schema) {
39
+ return;
40
+ }
41
+ const property = schema.property;
42
+ const multiple = Math.pow(10, property ? property.scale : 0);
43
+ this.mainService().getCharacteristic(this.Characteristic.CarbonMonoxideLevel)
44
+ .onGet(() => {
45
+ const status = this.getStatus(schema.code);
46
+ const value = (0, util_1.limit)(status.value / multiple, 0, 100);
47
+ return value;
48
+ });
49
+ }
50
+ }
51
+ exports.default = CarbonMonoxideSensorAccessory;
52
+ //# sourceMappingURL=CarbonMonoxideSensorAccessory.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 SCHEMA_CODE = {
8
+ CONTACT_STATE: ['doorcontact_state', 'switch'],
9
+ };
10
+ class ContaceSensor extends BaseAccessory_1.default {
11
+ requiredSchema() {
12
+ return [SCHEMA_CODE.CONTACT_STATE];
13
+ }
14
+ configureServices() {
15
+ const schema = this.getSchema(...SCHEMA_CODE.CONTACT_STATE);
16
+ if (!schema) {
17
+ return;
18
+ }
19
+ const service = this.accessory.getService(this.Service.ContactSensor)
20
+ || this.accessory.addService(this.Service.ContactSensor);
21
+ const { CONTACT_NOT_DETECTED, CONTACT_DETECTED } = this.Characteristic.ContactSensorState;
22
+ service.getCharacteristic(this.Characteristic.ContactSensorState)
23
+ .onGet(() => {
24
+ const status = this.getStatus(schema.code);
25
+ return status.value ? CONTACT_NOT_DETECTED : CONTACT_DETECTED;
26
+ });
27
+ }
28
+ }
29
+ exports.default = ContaceSensor;
30
+ //# sourceMappingURL=ContactSensorAccessory.js.map
@@ -0,0 +1,68 @@
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 Active_1 = require("./characteristic/Active");
8
+ const CurrentTemperature_1 = require("./characteristic/CurrentTemperature");
9
+ const CurrentRelativeHumidity_1 = require("./characteristic/CurrentRelativeHumidity");
10
+ const RotationSpeed_1 = require("./characteristic/RotationSpeed");
11
+ const SwingMode_1 = require("./characteristic/SwingMode");
12
+ const LockPhysicalControls_1 = require("./characteristic/LockPhysicalControls");
13
+ const RelativeHumidityDehumidifierThreshold_1 = require("./characteristic/RelativeHumidityDehumidifierThreshold");
14
+ const SCHEMA_CODE = {
15
+ ACTIVE: ['switch'],
16
+ CURRENT_HUMIDITY: ['humidity_indoor'],
17
+ TARGET_HUMIDITY: ['dehumidify_set_value'],
18
+ CURRENT_TEMP: ['temp_indoor'],
19
+ SPEED_LEVEL: ['fan_speed_enum'],
20
+ SWING: ['swing'],
21
+ LOCK: ['child_lock'],
22
+ };
23
+ class DehumidifierAccessory extends BaseAccessory_1.default {
24
+ requiredSchema() {
25
+ return [SCHEMA_CODE.ACTIVE, SCHEMA_CODE.CURRENT_HUMIDITY];
26
+ }
27
+ configureServices() {
28
+ // Required Characteristics
29
+ (0, Active_1.configureActive)(this, this.mainService(), this.getSchema(...SCHEMA_CODE.ACTIVE));
30
+ this.configureCurrentState();
31
+ this.configureTargetState();
32
+ (0, CurrentRelativeHumidity_1.configureCurrentRelativeHumidity)(this, this.mainService(), this.getSchema(...SCHEMA_CODE.CURRENT_HUMIDITY));
33
+ // Optional Characteristics
34
+ (0, LockPhysicalControls_1.configureLockPhysicalControls)(this, this.mainService(), this.getSchema(...SCHEMA_CODE.LOCK));
35
+ (0, RelativeHumidityDehumidifierThreshold_1.configureRelativeHumidityDehumidifierThreshold)(this, this.mainService(), this.getSchema(...SCHEMA_CODE.TARGET_HUMIDITY));
36
+ (0, RotationSpeed_1.configureRotationSpeedLevel)(this, this.mainService(), this.getSchema(...SCHEMA_CODE.SPEED_LEVEL));
37
+ (0, SwingMode_1.configureSwingMode)(this, this.mainService(), this.getSchema(...SCHEMA_CODE.SWING));
38
+ // Other
39
+ (0, CurrentTemperature_1.configureCurrentTemperature)(this, undefined, this.getSchema(...SCHEMA_CODE.CURRENT_TEMP));
40
+ }
41
+ mainService() {
42
+ return this.accessory.getService(this.Service.HumidifierDehumidifier)
43
+ || this.accessory.addService(this.Service.HumidifierDehumidifier);
44
+ }
45
+ configureCurrentState() {
46
+ const schema = this.getSchema(...SCHEMA_CODE.ACTIVE);
47
+ if (!schema) {
48
+ this.log.warn('CurrentHumidifierDehumidifierState not supported.');
49
+ return;
50
+ }
51
+ const { INACTIVE, DEHUMIDIFYING } = this.Characteristic.CurrentHumidifierDehumidifierState;
52
+ this.mainService().getCharacteristic(this.Characteristic.CurrentHumidifierDehumidifierState)
53
+ .onGet(() => {
54
+ const status = this.getStatus(schema.code);
55
+ return status?.value ? DEHUMIDIFYING : INACTIVE;
56
+ });
57
+ }
58
+ configureTargetState() {
59
+ const { DEHUMIDIFIER } = this.Characteristic.TargetHumidifierDehumidifierState;
60
+ const validValues = [DEHUMIDIFIER];
61
+ this.mainService().getCharacteristic(this.Characteristic.TargetHumidifierDehumidifierState)
62
+ .onGet(() => {
63
+ return DEHUMIDIFIER;
64
+ }).setProps({ validValues });
65
+ }
66
+ }
67
+ exports.default = DehumidifierAccessory;
68
+ //# sourceMappingURL=DehumidifierAccessory.js.map
@@ -0,0 +1,55 @@
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 Active_1 = require("./characteristic/Active");
8
+ const Light_1 = require("./characteristic/Light");
9
+ const On_1 = require("./characteristic/On");
10
+ const RotationSpeed_1 = require("./characteristic/RotationSpeed");
11
+ const SCHEMA_CODE = {
12
+ ON: ['switch'],
13
+ SPRAY_ON: ['switch_spray'],
14
+ SPRAY_MODE: ['mode'],
15
+ SPRAY_LEVEL: ['level'],
16
+ LIGHT_ON: ['switch_led'],
17
+ LIGHT_MODE: ['work_mode'],
18
+ LIGHT_BRIGHT: ['bright_value', 'bright_value_v2'],
19
+ LIGHT_COLOR: ['colour_data', 'colour_data_hsv'],
20
+ SOUND_ON: ['switch_sound'],
21
+ };
22
+ class DiffuserAccessory extends BaseAccessory_1.default {
23
+ requiredSchema() {
24
+ return [SCHEMA_CODE.SPRAY_ON];
25
+ }
26
+ configureServices() {
27
+ // Main Switch
28
+ (0, On_1.configureOn)(this, undefined, this.getSchema(...SCHEMA_CODE.ON));
29
+ this.configureDiffuser();
30
+ (0, Light_1.configureLight)(this, undefined, this.getSchema(...SCHEMA_CODE.LIGHT_ON), this.getSchema(...SCHEMA_CODE.LIGHT_BRIGHT), undefined, this.getSchema(...SCHEMA_CODE.LIGHT_COLOR), this.getSchema(...SCHEMA_CODE.LIGHT_MODE));
31
+ (0, On_1.configureOn)(this, undefined, this.getSchema(...SCHEMA_CODE.SOUND_ON)); // Sound Switch
32
+ }
33
+ mainService() {
34
+ return this.accessory.getService(this.Service.AirPurifier)
35
+ || this.accessory.addService(this.Service.AirPurifier);
36
+ }
37
+ configureDiffuser() {
38
+ const sprayOnSchema = this.getSchema(...SCHEMA_CODE.SPRAY_ON);
39
+ // Required Characteristics
40
+ (0, Active_1.configureActive)(this, this.mainService(), sprayOnSchema);
41
+ const { INACTIVE, PURIFYING_AIR } = this.Characteristic.CurrentAirPurifierState;
42
+ this.mainService().getCharacteristic(this.Characteristic.CurrentAirPurifierState)
43
+ .onGet(() => {
44
+ const status = this.getStatus(sprayOnSchema.code);
45
+ return status.value ? PURIFYING_AIR : INACTIVE;
46
+ });
47
+ // const { MANUAL } = this.Characteristic.TargetAirPurifierState;
48
+ // this.mainService().getCharacteristic(this.Characteristic.TargetAirPurifierState)
49
+ // .setProps({ validValues: [MANUAL] });
50
+ // Optional Characteristics
51
+ (0, RotationSpeed_1.configureRotationSpeedLevel)(this, this.mainService(), this.getSchema(...SCHEMA_CODE.SPRAY_LEVEL));
52
+ }
53
+ }
54
+ exports.default = DiffuserAccessory;
55
+ //# sourceMappingURL=DiffuserAccessory.js.map
@@ -0,0 +1,94 @@
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 Name_1 = require("./characteristic/Name");
9
+ const On_1 = require("./characteristic/On");
10
+ const SCHEMA_CODE = {
11
+ ON: ['switch', 'switch_led', 'switch_1', 'switch_led_1'],
12
+ BRIGHTNESS: ['bright_value', 'bright_value_1'],
13
+ };
14
+ class DimmerAccessory extends BaseAccessory_1.default {
15
+ requiredSchema() {
16
+ return [SCHEMA_CODE.ON, SCHEMA_CODE.BRIGHTNESS];
17
+ }
18
+ configureServices() {
19
+ const oldService = this.accessory.getService(this.Service.Lightbulb);
20
+ if (oldService && oldService?.subtype === undefined) {
21
+ this.platform.log.warn('Remove old service:', oldService.UUID);
22
+ this.accessory.removeService(oldService);
23
+ }
24
+ const schema = this.device.schema.filter((schema) => schema.code.startsWith('bright_value'));
25
+ for (const _schema of schema) {
26
+ const suffix = _schema.code.replace('bright_value', '');
27
+ const name = (schema.length === 1) ? this.device.name : _schema.code;
28
+ const service = this.accessory.getService(_schema.code)
29
+ || this.accessory.addService(this.Service.Lightbulb, name, _schema.code);
30
+ (0, Name_1.configureName)(this, service, name);
31
+ (0, On_1.configureOn)(this, service, this.getSchema('switch' + suffix, 'switch_led' + suffix));
32
+ this.configureBrightness(service, suffix);
33
+ }
34
+ }
35
+ configureBrightness(service, suffix) {
36
+ const schema = this.getSchema('bright_value' + suffix);
37
+ if (!schema) {
38
+ return;
39
+ }
40
+ const { min, max } = schema.property;
41
+ const range = max; // not max - min
42
+ const props = {
43
+ minValue: 0,
44
+ maxValue: 100,
45
+ minStep: 1,
46
+ };
47
+ const minStatus = this.getStatus('brightness_min' + suffix);
48
+ const maxStatus = this.getStatus('brightness_max' + suffix);
49
+ if (minStatus && maxStatus && maxStatus.value > minStatus.value) {
50
+ const minValue = Math.ceil((0, util_1.remap)(minStatus.value, 0, range, 0, 100));
51
+ const maxValue = Math.floor((0, util_1.remap)(maxStatus.value, 0, range, 0, 100));
52
+ props.minValue = Math.max(props.minValue, minValue);
53
+ props.maxValue = Math.min(props.maxValue, maxValue);
54
+ }
55
+ this.log.debug('Set props for Brightness:', props);
56
+ service.getCharacteristic(this.Characteristic.Brightness)
57
+ .onGet(() => {
58
+ const status = this.getStatus(schema.code);
59
+ let value = status.value;
60
+ value = (0, util_1.remap)(value, 0, range, 0, 100);
61
+ value = Math.round(value);
62
+ value = (0, util_1.limit)(value, props.minValue, props.maxValue);
63
+ return value;
64
+ })
65
+ .onSet(async (value) => {
66
+ this.log.debug(`Characteristic.Brightness set to: ${value}`);
67
+ let brightValue = value;
68
+ brightValue = (0, util_1.remap)(brightValue, 0, 100, 0, range);
69
+ brightValue = Math.round(brightValue);
70
+ brightValue = (0, util_1.limit)(brightValue, min, max);
71
+ await this.sendCommands([{ code: schema.code, value: brightValue }], true);
72
+ })
73
+ .setProps(props);
74
+ }
75
+ async onDeviceStatusUpdate(status) {
76
+ // brightness range updated
77
+ if (status.length !== this.device.status.length) {
78
+ for (const _status of status) {
79
+ if (!_status.code.startsWith('brightness_min')
80
+ && !_status.code.startsWith('brightness_max')) {
81
+ continue;
82
+ }
83
+ this.platform.log.warn('Brightness range updated, please restart homebridge to take effect.');
84
+ // TODO updating props
85
+ // this.platform.log.debug('Brightness range updated, resetting props...');
86
+ // this.configure();
87
+ break;
88
+ }
89
+ }
90
+ super.onDeviceStatusUpdate(status);
91
+ }
92
+ }
93
+ exports.default = DimmerAccessory;
94
+ //# sourceMappingURL=DimmerAccessory.js.map
@@ -0,0 +1,91 @@
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 ProgrammableSwitchEvent_1 = require("./characteristic/ProgrammableSwitchEvent");
8
+ const SCHEMA_CODE = {
9
+ // ALARM_MESSAGE: ['alarm_message'],
10
+ // ALARM_SWITCH: ['alarm_propel_switch'],
11
+ // VOLUME: ['doorbell_volume_value'],
12
+ DOORBELL_CALL: ['doorbell_call'],
13
+ };
14
+ class DoorbellAccessory extends BaseAccessory_1.default {
15
+ requiredSchema() {
16
+ return [SCHEMA_CODE.DOORBELL_CALL];
17
+ }
18
+ configureServices() {
19
+ this.log.warn('HomeKit Doorbell service does not work without camera anymore.');
20
+ this.log.warn('Downgrade to StatelessProgrammableSwitch. "Mute" and "Volume" not available.');
21
+ (0, ProgrammableSwitchEvent_1.configureProgrammableSwitchEvent)(this, this.getDoorbellService(), this.getSchema(...SCHEMA_CODE.DOORBELL_CALL));
22
+ // this.configureMute();
23
+ // this.configureVolume();
24
+ }
25
+ /*
26
+ configureMute() {
27
+ const schema = this.getSchema(...SCHEMA_CODE.ALARM_SWITCH);
28
+ if (!schema) {
29
+ return;
30
+ }
31
+
32
+ this.getDoorbellService().getCharacteristic(this.Characteristic.Mute)
33
+ .onGet(() => {
34
+ const status = this.getStatus(schema.code)!;
35
+ const value = !(status.value as boolean);
36
+ return value;
37
+ })
38
+ .onSet(async value => {
39
+ const mute = !(value as boolean);
40
+ await this.sendCommands([{ code: schema.code, value: mute }], true);
41
+ });
42
+ }
43
+
44
+ configureVolume() {
45
+ const schema = this.getSchema(...SCHEMA_CODE.VOLUME);
46
+ if (!schema) {
47
+ return;
48
+ }
49
+
50
+ const property = schema.property as TuyaDeviceSchemaIntegerProperty;
51
+ const multiple = Math.pow(10, property.scale);
52
+ const props = {
53
+ minValue: property.min / multiple,
54
+ maxValue: property.max / multiple,
55
+ minStep: Math.max(1, property.step / multiple),
56
+ };
57
+ this.getDoorbellService().getCharacteristic(this.Characteristic.Volume)
58
+ .onGet(() => {
59
+ const status = this.getStatus(schema.code)!;
60
+ const value = status.value as number / multiple;
61
+ return value;
62
+ })
63
+ .onSet(async value => {
64
+ const volume = (value as number) * multiple;
65
+ await this.sendCommands([{ code: schema.code, value: volume }], true);
66
+ })
67
+ .setProps(props);
68
+ }
69
+
70
+ getDoorbellService() {
71
+ return this.accessory.getService(this.Service.Doorbell)
72
+ || this.accessory.addService(this.Service.Doorbell);
73
+ }
74
+ */
75
+ getDoorbellService() {
76
+ return this.accessory.getService(this.Service.StatelessProgrammableSwitch)
77
+ || this.accessory.addService(this.Service.StatelessProgrammableSwitch);
78
+ }
79
+ async onDeviceStatusUpdate(status) {
80
+ super.onDeviceStatusUpdate(status);
81
+ const doorbellCallSchema = this.getSchema(...SCHEMA_CODE.DOORBELL_CALL);
82
+ if (doorbellCallSchema) {
83
+ const doorbellCallStatus = status.find(_status => _status.code === doorbellCallSchema.code);
84
+ if (doorbellCallStatus) {
85
+ (0, ProgrammableSwitchEvent_1.onProgrammableSwitchEvent)(this, this.getDoorbellService(), doorbellCallStatus);
86
+ }
87
+ }
88
+ }
89
+ }
90
+ exports.default = DoorbellAccessory;
91
+ //# sourceMappingURL=DoorbellAccessory.js.map