homebridge-savantlightingcn 1.0.2

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 (60) hide show
  1. package/README.md +45 -0
  2. package/accessories/alarm_control_panel.js +187 -0
  3. package/accessories/binary_sensor.js +243 -0
  4. package/accessories/climate.js +526 -0
  5. package/accessories/cover.js +214 -0
  6. package/accessories/device_tracker.js +152 -0
  7. package/accessories/fan.js +254 -0
  8. package/accessories/floor_heating.js +266 -0
  9. package/accessories/light.js +519 -0
  10. package/accessories/lock.js +177 -0
  11. package/accessories/media_player.js +276 -0
  12. package/accessories/sensor.js +225 -0
  13. package/accessories/switch.js +217 -0
  14. package/dist/css/app.ddbde395.css +1 -0
  15. package/dist/css/chunk-vendors.f2db5e15.css +1 -0
  16. package/dist/css/test.0ebe5642.css +0 -0
  17. package/dist/favicon.ico +0 -0
  18. package/dist/index.html +1 -0
  19. package/dist/js/about.7c566887.js +2 -0
  20. package/dist/js/about.7c566887.js.map +1 -0
  21. package/dist/js/about.ecf592a0.js +2 -0
  22. package/dist/js/about.ecf592a0.js.map +1 -0
  23. package/dist/js/app.01e8fa44.js +2 -0
  24. package/dist/js/app.01e8fa44.js.map +1 -0
  25. package/dist/js/app.15ed2e3b.js +2 -0
  26. package/dist/js/app.15ed2e3b.js.map +1 -0
  27. package/dist/js/app.25976869.js +2 -0
  28. package/dist/js/app.25976869.js.map +1 -0
  29. package/dist/js/app.3112044b.js +2 -0
  30. package/dist/js/app.3112044b.js.map +1 -0
  31. package/dist/js/app.3a289bce.js +2 -0
  32. package/dist/js/app.3a289bce.js.map +1 -0
  33. package/dist/js/app.734f9d85.js +2 -0
  34. package/dist/js/app.734f9d85.js.map +1 -0
  35. package/dist/js/app.83545550.js +2 -0
  36. package/dist/js/app.83545550.js.map +1 -0
  37. package/dist/js/app.926ce9ff.js +2 -0
  38. package/dist/js/app.926ce9ff.js.map +1 -0
  39. package/dist/js/app.a6ba37fb.js +2 -0
  40. package/dist/js/app.a6ba37fb.js.map +1 -0
  41. package/dist/js/app.aa309e99.js +2 -0
  42. package/dist/js/app.aa309e99.js.map +1 -0
  43. package/dist/js/app.b2b4f482.js +2 -0
  44. package/dist/js/app.b2b4f482.js.map +1 -0
  45. package/dist/js/app.f9643858.js +2 -0
  46. package/dist/js/app.f9643858.js.map +1 -0
  47. package/dist/js/chunk-vendors.372a828c.js +52 -0
  48. package/dist/js/chunk-vendors.372a828c.js.map +1 -0
  49. package/dist/js/chunk-vendors.4b731e62.js +52 -0
  50. package/dist/js/chunk-vendors.4b731e62.js.map +1 -0
  51. package/dist/js/chunk-vendors.941b76e9.js +46 -0
  52. package/dist/js/chunk-vendors.941b76e9.js.map +1 -0
  53. package/dist/js/test.041333f7.js +2 -0
  54. package/dist/js/test.041333f7.js.map +1 -0
  55. package/dist/js/test.70bf0852.js +8 -0
  56. package/dist/js/test.70bf0852.js.map +1 -0
  57. package/dist/js/test.840bc653.js +2 -0
  58. package/dist/js/test.840bc653.js.map +1 -0
  59. package/index.js +1635 -0
  60. package/package.json +44 -0
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # 介绍 #
2
+ homebridge 插件
3
+
4
+ # 版本 #
5
+ v1.0.0
6
+ 支持灯控制(开闭、调光、色温、RGB),状态反馈
7
+
8
+ v1.0.1
9
+ 添加支持温控面板,同步状态,网关连上时同步设备
10
+
11
+ v1.0.2
12
+ 温控面板直接同时添加空调、地暖、新风
13
+
14
+ v1.0.3
15
+ 优化初始化状态同步,空调状态分开查询
16
+
17
+ v1.0.4
18
+ 修改包说明
19
+
20
+ v1.0.5
21
+ 添加传感器
22
+
23
+ v1.0.6
24
+ 添加窗帘,优化面板按键选择
25
+
26
+ v1.0.7
27
+ 优化窗帘初始化查询和控制回复判断
28
+
29
+ v1.0.8
30
+ 窗帘控制的所有数据都解析
31
+
32
+ v1.0.9
33
+ 在空调中添加除湿模块
34
+
35
+ v1.0.10
36
+ 通过最大端口判断查询起始端口和查询端口数量
37
+
38
+ v1.0.14
39
+ 优化修改查询机制
40
+
41
+ v1.0.17
42
+ 修改DALI B on\off控制
43
+
44
+ v1.1.0
45
+ 正式发布版本
@@ -0,0 +1,187 @@
1
+ 'use strict';
2
+
3
+ let Service;
4
+ let Characteristic;
5
+ let communicationError;
6
+
7
+ function HomeAssistantAlarmControlPanel(log, data, client, firmware) {
8
+ // device info
9
+ this.domain = 'alarm_control_panel';
10
+ this.data = data;
11
+ this.entity_id = data.entity_id;
12
+ this.uuid_base = data.entity_id;
13
+ this.firmware = firmware;
14
+ if (data.attributes && data.attributes.friendly_name) {
15
+ this.name = data.attributes.friendly_name;
16
+ } else {
17
+ this.name = data.entity_id.split('.').pop().replace(/_/g, ' ');
18
+ }
19
+ if (data.attributes && data.attributes.homebridge_manufacturer) {
20
+ this.manufacturer = String(data.attributes.homebridge_manufacturer);
21
+ } else {
22
+ this.manufacturer = 'Home Assistant';
23
+ }
24
+ if (data.attributes && data.attributes.homebridge_model) {
25
+ this.model = String(data.attributes.homebridge_model);
26
+ } else {
27
+ this.model = 'Alarm Control Panel';
28
+ }
29
+ if (data.attributes && data.attributes.homebridge_serial) {
30
+ this.serial = String(data.attributes.homebridge_serial);
31
+ } else {
32
+ this.serial = data.entity_id;
33
+ }
34
+ this.client = client;
35
+ this.log = log;
36
+ this.alarmCode = data.attributes.homebridge_alarm_code;
37
+ }
38
+
39
+ HomeAssistantAlarmControlPanel.prototype = {
40
+ onEvent(oldState, newState) {
41
+ if (newState.state) {
42
+ let alarmState;
43
+ if (newState.state === 'armed_home') {
44
+ alarmState = 0;
45
+ } else if (newState.state === 'armed_away') {
46
+ alarmState = 1;
47
+ } else if (newState.state === 'armed_night') {
48
+ alarmState = 2;
49
+ } else if (newState.state === 'disarmed') {
50
+ alarmState = 3;
51
+ } else if (newState.state === 'triggered') {
52
+ alarmState = 4;
53
+ } else {
54
+ alarmState = 3;
55
+ }
56
+ this.alarmService.getCharacteristic(Characteristic.SecuritySystemCurrentState)
57
+ .setValue(alarmState, null, 'internal');
58
+ this.alarmService.getCharacteristic(Characteristic.SecuritySystemTargetState)
59
+ .setValue(alarmState, null, 'internal');
60
+ }
61
+ },
62
+ getAlarmState(callback) {
63
+ this.client.fetchState(this.entity_id, (data) => {
64
+ if (data) {
65
+ if (data.state === 'armed_home') {
66
+ callback(null, 0);
67
+ } else if (data.state === 'armed_away') {
68
+ callback(null, 1);
69
+ } else if (data.state === 'armed_night') {
70
+ callback(null, 2);
71
+ } else if (data.state === 'disarmed') {
72
+ callback(null, 3);
73
+ } else if (data.state === 'triggered') {
74
+ callback(null, 4);
75
+ } else {
76
+ callback(null, 3);
77
+ }
78
+ } else {
79
+ callback(communicationError);
80
+ }
81
+ });
82
+ },
83
+
84
+ setAlarmState(targetState, callback, context) {
85
+ if (context === 'internal') {
86
+ callback();
87
+ return;
88
+ }
89
+
90
+ const that = this;
91
+ const serviceData = {};
92
+ serviceData.entity_id = this.entity_id;
93
+ if (this.alarmCode) {
94
+ serviceData.code = this.alarmCode;
95
+ }
96
+
97
+ if (targetState === Characteristic.SecuritySystemCurrentState.STAY_ARM) {
98
+ this.log(`Setting alarm state on the '${this.name}' to armed stay`);
99
+
100
+ this.client.callService(this.domain, 'alarm_arm_home', serviceData, (data) => {
101
+ if (data) {
102
+ that.log(`Successfully set alarm state on the '${that.name}' to armed stay`);
103
+ callback();
104
+ } else {
105
+ callback(communicationError);
106
+ }
107
+ });
108
+ } else if (targetState === Characteristic.SecuritySystemCurrentState.AWAY_ARM) {
109
+ this.log(`Setting alarm state on the '${this.name}' to armed away`);
110
+
111
+ this.client.callService(this.domain, 'alarm_arm_away', serviceData, (data) => {
112
+ if (data) {
113
+ that.log(`Successfully set alarm state on the '${that.name}' to armed away`);
114
+ callback();
115
+ } else {
116
+ callback(communicationError);
117
+ }
118
+ });
119
+ } else if (targetState === Characteristic.SecuritySystemCurrentState.NIGHT_ARM) {
120
+ this.log(`Setting alarm state on the '${this.name}' to armed night`);
121
+
122
+ this.client.callService(this.domain, 'alarm_arm_night', serviceData, (data) => {
123
+ if (data) {
124
+ that.log(`Successfully set alarm state on the '${that.name}' to armed night`);
125
+ callback();
126
+ } else {
127
+ callback(communicationError);
128
+ }
129
+ });
130
+ } else if (targetState === Characteristic.SecuritySystemCurrentState.DISARMED) {
131
+ this.log(`Setting alarm state on the '${this.name}' to disarmed`);
132
+
133
+ this.client.callService(this.domain, 'alarm_disarm', serviceData, (data) => {
134
+ if (data) {
135
+ that.log(`Successfully set alarm state on the '${that.name}' to disarmed`);
136
+ callback();
137
+ } else {
138
+ callback(communicationError);
139
+ }
140
+ });
141
+ } else {
142
+ this.log(`Setting alarm state on the '${this.name}' to disarmed`);
143
+
144
+ this.client.callService(this.domain, 'alarm_disarm', serviceData, (data) => {
145
+ if (data) {
146
+ that.log(`Successfully set alarm state on the '${that.name}' to disarmed`);
147
+ callback();
148
+ } else {
149
+ callback(communicationError);
150
+ }
151
+ });
152
+ }
153
+ },
154
+ getServices() {
155
+ this.alarmService = new Service.SecuritySystem();
156
+ const informationService = new Service.AccessoryInformation();
157
+
158
+ informationService
159
+ .setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
160
+ .setCharacteristic(Characteristic.Model, this.model)
161
+ .setCharacteristic(Characteristic.SerialNumber, this.serial)
162
+ .setCharacteristic(Characteristic.FirmwareRevision, this.firmware);
163
+
164
+ this.alarmService
165
+ .getCharacteristic(Characteristic.SecuritySystemCurrentState)
166
+ .on('get', this.getAlarmState.bind(this));
167
+
168
+ this.alarmService
169
+ .getCharacteristic(Characteristic.SecuritySystemTargetState)
170
+ .on('get', this.getAlarmState.bind(this))
171
+ .on('set', this.setAlarmState.bind(this));
172
+
173
+ return [informationService, this.alarmService];
174
+ },
175
+
176
+ };
177
+
178
+ function HomeAssistantAlarmControlPanelPlatform(oService, oCharacteristic, oCommunicationError) {
179
+ Service = oService;
180
+ Characteristic = oCharacteristic;
181
+ communicationError = oCommunicationError;
182
+
183
+ return HomeAssistantAlarmControlPanel;
184
+ }
185
+
186
+ module.exports = HomeAssistantAlarmControlPanelPlatform;
187
+ module.exports.HomeAssistantAlarmControlPanel = HomeAssistantAlarmControlPanel;
@@ -0,0 +1,243 @@
1
+ 'use strict';
2
+
3
+ let Service;
4
+ let Characteristic;
5
+ let communicationError;
6
+
7
+ function toTitleCase(str) {
8
+ return str.replace(/\w\S*/g, txt => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase());
9
+ }
10
+
11
+ class HomeAssistantBinarySensor {
12
+ constructor(log, data, client, service, characteristic, onValue, offValue, firmware) {
13
+ // device info
14
+ this.data = data;
15
+ this.entity_id = data.entity_id;
16
+ this.uuid_base = data.entity_id;
17
+ this.firmware = firmware;
18
+ if (data.attributes && data.attributes.friendly_name) {
19
+ this.name = data.attributes.friendly_name;
20
+ } else {
21
+ this.name = data.entity_id.split('.').pop().replace(/_/g, ' ');
22
+ }
23
+ if (data.attributes && data.attributes.homebridge_manufacturer) {
24
+ this.manufacturer = String(data.attributes.homebridge_manufacturer);
25
+ } else {
26
+ this.manufacturer = 'Home Assistant';
27
+ }
28
+ if (data.attributes && data.attributes.homebridge_model) {
29
+ this.model = String(data.attributes.homebridge_model);
30
+ } else {
31
+ this.model = `${toTitleCase(data.attributes.device_class)} Binary Sensor`;
32
+ }
33
+ if (data.attributes && data.attributes.homebridge_serial) {
34
+ this.serial = String(data.attributes.homebridge_serial);
35
+ } else {
36
+ this.serial = data.entity_id;
37
+ }
38
+ this.entity_type = data.entity_id.split('.')[0];
39
+ this.client = client;
40
+ this.log = log;
41
+ this.service = service;
42
+ this.characteristic = characteristic;
43
+ this.onValue = onValue;
44
+ this.offValue = offValue;
45
+ this.batterySource = data.attributes.homebridge_battery_source;
46
+ this.chargingSource = data.attributes.homebridge_charging_source;
47
+ }
48
+
49
+ onEvent(oldState, newState) {
50
+ if (newState.state) {
51
+ this.sensorService.getCharacteristic(this.characteristic)
52
+ .setValue(newState.state === 'on' ? this.onValue : this.offValue, null, 'internal');
53
+ }
54
+ }
55
+ identify(callback) {
56
+ this.log(`identifying: ${this.name}`);
57
+ callback();
58
+ }
59
+ getState(callback) {
60
+ this.log(`fetching state for: ${this.name}`);
61
+ this.client.fetchState(this.entity_id, (data) => {
62
+ if (data) {
63
+ callback(null, data.state === 'on' ? this.onValue : this.offValue);
64
+ } else {
65
+ callback(communicationError);
66
+ }
67
+ });
68
+ }
69
+ getBatteryLevel(callback) {
70
+ this.client.fetchState(this.batterySource, (data) => {
71
+ if (data) {
72
+ callback(null, parseFloat(data.state));
73
+ } else {
74
+ callback(communicationError);
75
+ }
76
+ });
77
+ }
78
+ getChargingState(callback) {
79
+ if (this.batterySource && this.chargingSource) {
80
+ this.client.fetchState(this.chargingSource, (data) => {
81
+ if (data) {
82
+ callback(null, data.state.toLowerCase() === 'charging' ? 1 : 0);
83
+ } else {
84
+ callback(communicationError);
85
+ }
86
+ });
87
+ } else {
88
+ callback(null, 2);
89
+ }
90
+ }
91
+ getLowBatteryStatus(callback) {
92
+ this.client.fetchState(this.batterySource, (data) => {
93
+ if (data) {
94
+ callback(null, parseFloat(data.state) > 20 ? 0 : 1);
95
+ } else {
96
+ callback(communicationError);
97
+ }
98
+ });
99
+ }
100
+ getServices() {
101
+ this.sensorService = new this.service(); // eslint-disable-line new-cap
102
+ this.sensorService
103
+ .getCharacteristic(this.characteristic)
104
+ .on('get', this.getState.bind(this));
105
+
106
+ const informationService = new Service.AccessoryInformation();
107
+
108
+ informationService
109
+ .setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
110
+ .setCharacteristic(Characteristic.Model, this.model)
111
+ .setCharacteristic(Characteristic.SerialNumber, this.serial)
112
+ .setCharacteristic(Characteristic.FirmwareRevision, this.firmware);
113
+
114
+ if (this.batterySource) {
115
+ this.batteryService = new Service.BatteryService();
116
+ this.batteryService
117
+ .getCharacteristic(Characteristic.BatteryLevel)
118
+ .setProps({ maxValue: 100, minValue: 0, minStep: 1 })
119
+ .on('get', this.getBatteryLevel.bind(this));
120
+ this.batteryService
121
+ .getCharacteristic(Characteristic.ChargingState)
122
+ .setProps({ maxValue: 2 })
123
+ .on('get', this.getChargingState.bind(this));
124
+ this.batteryService
125
+ .getCharacteristic(Characteristic.StatusLowBattery)
126
+ .on('get', this.getLowBatteryStatus.bind(this));
127
+ return [informationService, this.batteryService, this.sensorService];
128
+ }
129
+ return [informationService, this.sensorService];
130
+ }
131
+ }
132
+
133
+ function HomeAssistantBinarySensorFactory(log, data, client, firmware) {
134
+ if (!(data.attributes && data.attributes.device_class)) {
135
+ return null;
136
+ }
137
+ switch (data.attributes.device_class) {
138
+ case 'door':
139
+ case 'garage_door':
140
+ case 'opening':
141
+ case 'window':
142
+ return new HomeAssistantBinarySensor(
143
+ log, data, client,
144
+ Service.ContactSensor,
145
+ Characteristic.ContactSensorState,
146
+ Characteristic.ContactSensorState.CONTACT_NOT_DETECTED,
147
+ Characteristic.ContactSensorState.CONTACT_DETECTED,
148
+ firmware
149
+ );
150
+ case 'gas':
151
+ if (!(data.attributes.homebridge_gas_type)) {
152
+ return new HomeAssistantBinarySensor(
153
+ log, data, client,
154
+ Service.CarbonMonoxideSensor,
155
+ Characteristic.CarbonMonoxideDetected,
156
+ Characteristic.LeakDetected.CO_LEVELS_ABNORMAL,
157
+ Characteristic.LeakDetected.CO_LEVELS_NORMAL,
158
+ firmware
159
+ );
160
+ }
161
+ switch (data.attributes.homebridge_gas_type) {
162
+ case 'co2':
163
+ return new HomeAssistantBinarySensor(
164
+ log, data, client,
165
+ Service.CarbonDioxideSensor,
166
+ Characteristic.CarbonDioxideDetected,
167
+ Characteristic.LeakDetected.CO2_LEVELS_ABNORMAL,
168
+ Characteristic.LeakDetected.CO2_LEVELS_NORMAL,
169
+ firmware
170
+ );
171
+ case 'co':
172
+ return new HomeAssistantBinarySensor(
173
+ log, data, client,
174
+ Service.CarbonMonoxideSensor,
175
+ Characteristic.CarbonMonoxideDetected,
176
+ Characteristic.LeakDetected.CO_LEVELS_ABNORMAL,
177
+ Characteristic.LeakDetected.CO_LEVELS_NORMAL,
178
+ firmware
179
+ );
180
+ default:
181
+ return new HomeAssistantBinarySensor(
182
+ log, data, client,
183
+ Service.CarbonMonoxideSensor,
184
+ Characteristic.CarbonMonoxideDetected,
185
+ Characteristic.LeakDetected.CO_LEVELS_ABNORMAL,
186
+ Characteristic.LeakDetected.CO_LEVELS_NORMAL,
187
+ firmware
188
+ );
189
+ }
190
+ case 'moisture':
191
+ return new HomeAssistantBinarySensor(
192
+ log, data, client,
193
+ Service.LeakSensor,
194
+ Characteristic.LeakDetected,
195
+ Characteristic.LeakDetected.LEAK_DETECTED,
196
+ Characteristic.LeakDetected.LEAK_NOT_DETECTED,
197
+ firmware
198
+ );
199
+ case 'motion':
200
+ return new HomeAssistantBinarySensor(
201
+ log, data, client,
202
+ Service.MotionSensor,
203
+ Characteristic.MotionDetected,
204
+ true,
205
+ false,
206
+ firmware
207
+ );
208
+ case 'occupancy':
209
+ return new HomeAssistantBinarySensor(
210
+ log, data, client,
211
+ Service.OccupancySensor,
212
+ Characteristic.OccupancyDetected,
213
+ Characteristic.OccupancyDetected.OCCUPANCY_DETECTED,
214
+ Characteristic.OccupancyDetected.OCCUPANCY_NOT_DETECTED,
215
+ firmware
216
+ );
217
+ case 'smoke':
218
+ return new HomeAssistantBinarySensor(
219
+ log, data, client,
220
+ Service.SmokeSensor,
221
+ Characteristic.SmokeDetected,
222
+ Characteristic.SmokeDetected.SMOKE_DETECTED,
223
+ Characteristic.SmokeDetected.SMOKE_NOT_DETECTED,
224
+ firmware
225
+ );
226
+ default:
227
+ log.error(`'${data.entity_id}' has a device_class of '${data.attributes.device_class}' which is not supported by ` +
228
+ 'homebridge-homeassistant. Supported classes are \'gas\', \'moisture\', \'motion\', \'occupancy\', \'opening\' and \'smoke\'. ' +
229
+ 'See the README.md for more information.');
230
+ return null;
231
+ }
232
+ }
233
+
234
+ function HomeAssistantBinarySensorPlatform(oService, oCharacteristic, oCommunicationError) {
235
+ Service = oService;
236
+ Characteristic = oCharacteristic;
237
+ communicationError = oCommunicationError;
238
+
239
+ return HomeAssistantBinarySensorFactory;
240
+ }
241
+
242
+ module.exports = HomeAssistantBinarySensorPlatform;
243
+ module.exports.HomeAssistantBinarySensorFactory = HomeAssistantBinarySensorFactory;