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
@@ -0,0 +1,217 @@
1
+ 'use strict';
2
+
3
+ let Service;
4
+ let Characteristic;
5
+ let communicationError;
6
+
7
+ function HomeAssistantSwitch(log, data, client, type, firmware) {
8
+ // device info
9
+ this.domain = type;
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_serial) {
25
+ this.serial = String(data.attributes.homebridge_serial);
26
+ } else {
27
+ this.serial = data.entity_id;
28
+ }
29
+ this.client = client;
30
+ this.log = log;
31
+ }
32
+
33
+ HomeAssistantSwitch.prototype = {
34
+ onEvent(oldState, newState) {
35
+ if (newState.state) {
36
+ //this.service.getCharacteristic(Characteristic.On).setValue(newState.state === 'on', null, 'internal');
37
+ this.service.updateCharacteristic(Characteristic.On, newState.state === 'on');
38
+ if (this.domain === 'scene' || this.domain === 'key' || (this.domain === 'script' && !(this.data.attributes.can_cancel))) {
39
+ setTimeout(() => {
40
+ this.service.updateCharacteristic(Characteristic.On, false);
41
+ }, 500);
42
+ }
43
+ }
44
+ },
45
+ getPowerState(callback) {
46
+ this.client.fetchState(this.entity_id, (data) => {
47
+ if (data) {
48
+ const powerState = data.state === 'on';
49
+ callback(null, powerState);
50
+ if (this.domain === 'scene' || this.domain === 'key' || (this.domain === 'script' && !(this.data.attributes.can_cancel))) {
51
+ setTimeout(() => {
52
+ this.service.updateCharacteristic(Characteristic.On, false);
53
+ }, 500);
54
+ }
55
+ } else {
56
+ callback(communicationError);
57
+ }
58
+ });
59
+ },
60
+ setPowerState(powerOn, callback, context) {
61
+ if (context === 'internal') {
62
+ callback();
63
+ return;
64
+ }
65
+
66
+ const that = this;
67
+ const serviceData = {};
68
+ serviceData.entity_id = this.entity_id;
69
+ var callDomain = this.domain === 'group' ? 'homeassistant' : this.domain;
70
+
71
+ if (powerOn) {
72
+ this.log(`Setting power state on the '${this.name}' to on`);
73
+
74
+ this.client.callService(callDomain, 'turn_on', serviceData, (data) => {
75
+ if (this.domain === 'scene' || this.domain === 'key' || (this.domain === 'script' && !(this.data.attributes.can_cancel))) {
76
+ setTimeout(() => {
77
+ this.service.getCharacteristic(Characteristic.On)
78
+ .setValue(false, null, 'internal');
79
+ }, 500);
80
+ }
81
+ if (data) {
82
+ that.log(`Successfully set power state on the '${that.name}' to on`);
83
+ callback();
84
+ } else {
85
+ callback(communicationError);
86
+ }
87
+ });
88
+ } else {
89
+ this.log(`Setting power state on the '${this.name}' to off`);
90
+
91
+ this.client.callService(callDomain, 'turn_off', serviceData, (data) => {
92
+ if (data) {
93
+ that.log(`Successfully set power state on the '${that.name}' to off`);
94
+ callback();
95
+ } else {
96
+ callback(communicationError);
97
+ }
98
+ });
99
+ }
100
+ },
101
+ getServices() {
102
+ let model;
103
+
104
+ switch (this.domain) {
105
+ case 'scene':
106
+ if (this.data.attributes && this.data.attributes.homebridge_model) {
107
+ model = String(this.data.attributes.homebridge_model);
108
+ } else {
109
+ model = 'Scene';
110
+ }
111
+ break;
112
+ case 'key':
113
+ if (this.data.attributes && this.data.attributes.homebridge_model) {
114
+ model = String(this.data.attributes.homebridge_model);
115
+ } else {
116
+ model = 'Key';
117
+ }
118
+ break;
119
+ case 'input_boolean':
120
+ if (this.data.attributes && this.data.attributes.homebridge_model) {
121
+ model = String(this.data.attributes.homebridge_model);
122
+ } else {
123
+ model = 'Input Boolean';
124
+ }
125
+ break;
126
+ case 'group':
127
+ if (this.data.attributes && this.data.attributes.homebridge_model) {
128
+ model = String(this.data.attributes.homebridge_model);
129
+ } else {
130
+ model = 'Group';
131
+ }
132
+ break;
133
+ case 'switch':
134
+ if (this.data.attributes && this.data.attributes.homebridge_model) {
135
+ model = String(this.data.attributes.homebridge_model);
136
+ } else {
137
+ model = 'Switch';
138
+ }
139
+ break;
140
+ case 'remote':
141
+ if (this.data.attributes && this.data.attributes.homebridge_model) {
142
+ model = String(this.data.attributes.homebridge_model);
143
+ } else {
144
+ model = 'Remote';
145
+ }
146
+ break;
147
+ case 'automation':
148
+ if (this.data.attributes && this.data.attributes.homebridge_model) {
149
+ model = String(this.data.attributes.homebridge_model);
150
+ } else {
151
+ model = 'Automation';
152
+ }
153
+ break;
154
+ case 'vacuum':
155
+ if (this.data.attributes && this.data.attributes.homebridge_model) {
156
+ model = String(this.data.attributes.homebridge_model);
157
+ } else {
158
+ model = 'Vacuum';
159
+ }
160
+ break;
161
+ case 'script':
162
+ if (this.data.attributes && this.data.attributes.homebridge_model) {
163
+ model = String(this.data.attributes.homebridge_model);
164
+ } else {
165
+ model = 'Script';
166
+ }
167
+ break;
168
+ default:
169
+ model = 'Switch';
170
+ }
171
+
172
+ this.service = new Service.Switch();
173
+ if (this.data && this.data.attributes && this.data.attributes.homebridge_switch_type === 'outlet') {
174
+ this.service = new Service.Outlet();
175
+ if (this.data.attributes && this.data.attributes.homebridge_model) {
176
+ model = String(this.data.attributes.homebridge_model);
177
+ } else {
178
+ model = 'Outlet';
179
+ }
180
+ this.service
181
+ .getCharacteristic(Characteristic.OutletInUse)
182
+ .on('get', this.getPowerState.bind(this));
183
+ }
184
+ const informationService = new Service.AccessoryInformation();
185
+
186
+ informationService
187
+ .setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
188
+ .setCharacteristic(Characteristic.Model, model)
189
+ .setCharacteristic(Characteristic.SerialNumber, this.serial)
190
+ .setCharacteristic(Characteristic.FirmwareRevision, this.firmware);
191
+
192
+ if (this.domain === 'remote' || this.domain === 'switch' || this.domain === 'input_boolean' || this.domain === 'group' || this.domain === 'automation' || this.domain === 'vacuum' || (this.domain === 'script' && this.data.attributes.can_cancel)) {
193
+ this.service
194
+ .getCharacteristic(Characteristic.On)
195
+ .on('get', this.getPowerState.bind(this))
196
+ .on('set', this.setPowerState.bind(this));
197
+ } else {
198
+ this.service
199
+ .getCharacteristic(Characteristic.On)
200
+ .on('set', this.setPowerState.bind(this));
201
+ }
202
+
203
+ return [informationService, this.service];
204
+ },
205
+
206
+ };
207
+
208
+ function HomeAssistantSwitchPlatform(oService, oCharacteristic, oCommunicationError) {
209
+ Service = oService;
210
+ Characteristic = oCharacteristic;
211
+ communicationError = oCommunicationError;
212
+
213
+ return HomeAssistantSwitch;
214
+ }
215
+
216
+ module.exports = HomeAssistantSwitchPlatform;
217
+ module.exports.HomeAssistantSwitch = HomeAssistantSwitch;
@@ -0,0 +1 @@
1
+ #app{font-family:Avenir,Helvetica,Arial,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-align:center;color:#2c3e50}nav{padding:30px}nav a{font-weight:700;color:#2c3e50}nav a.router-link-exact-active{color:#42b983}