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,266 @@
1
+ var Service;
2
+ var Characteristic;
3
+ var communicationError;
4
+
5
+
6
+ function fahrenheitToCelsius(temperature) {
7
+ return (temperature - 32) / 1.8;
8
+ }
9
+
10
+ function celsiusToFahrenheit(temperature) {
11
+ return Math.round((temperature * 1.8) + 32);
12
+ }
13
+
14
+ function getTempUnits(data) {
15
+ // determine HomeAssistant temp. units (celsius vs. fahrenheit)
16
+ // defaults to celsius
17
+ return (data.attributes && data.attributes.unit_of_measurement && data.attributes.unit_of_measurement === '°F') ? 'FAHRENHEIT' : 'CELSIUS';
18
+ }
19
+
20
+ function HomeAssistantClimate(log, data, client, firmware) {
21
+ // device info
22
+
23
+ this.domain = 'floorHeating';
24
+ this.data = data;
25
+ this.entity_id = data.entity_id;
26
+ this.uuid_base = data.entity_id;
27
+ this.firmware = firmware;
28
+ if (data.attributes && data.attributes.friendly_name) {
29
+ this.name = data.attributes.friendly_name;
30
+ } else {
31
+ this.name = data.entity_id.split('.').pop().replace(/_/g, ' ');
32
+ }
33
+ if (data.attributes && data.attributes.homebridge_manufacturer) {
34
+ this.manufacturer = String(data.attributes.homebridge_manufacturer);
35
+ } else {
36
+ this.manufacturer = 'Home Assistant';
37
+ }
38
+ if (data.attributes && data.attributes.homebridge_model) {
39
+ this.model = String(data.attributes.homebridge_model);
40
+ } else {
41
+ this.model = 'floorHeating';
42
+ }
43
+ if (data.attributes && data.attributes.homebridge_serial) {
44
+ this.serial = String(data.attributes.homebridge_serial);
45
+ } else {
46
+ this.serial = data.entity_id;
47
+ }
48
+ this.client = client;
49
+ this.log = log;
50
+ }
51
+ HomeAssistantClimate.prototype = {
52
+ onEvent: function (oldState, newState) {
53
+ if (newState.state) {
54
+ const list = {
55
+ idle: 0, heat: 1, cool: 2, auto: 3, off: 0
56
+ };
57
+ this.ThermostatService.getCharacteristic(Characteristic.CurrentTemperature)
58
+ .setValue(newState.attributes.current_temperature || newState.attributes.temperature, null, 'internal');
59
+ this.ThermostatService.getCharacteristic(Characteristic.TargetTemperature)
60
+ .setValue(newState.attributes.temperature, null, 'internal');
61
+ if (newState.state == "on") {
62
+ this.ThermostatService.getCharacteristic(Characteristic.TargetHeatingCoolingState)
63
+ .setValue(1, null, 'internal');
64
+ } else {
65
+ this.ThermostatService.getCharacteristic(Characteristic.TargetHeatingCoolingState)
66
+ .setValue(0, null, 'internal');
67
+ }
68
+ }
69
+ },
70
+ getCurrentTemp: function (callback) {
71
+ this.log("getCurrentTemp")
72
+ this.client.fetchState(this.entity_id, function (data) {
73
+ if (data) {
74
+ if (getTempUnits(data) === 'FAHRENHEIT') {
75
+ callback(null, fahrenheitToCelsius(data.attributes.current_temperature));
76
+ } else {
77
+ callback(null, data.attributes.current_temperature);
78
+ }
79
+ } else {
80
+ callback(communicationError);
81
+ }
82
+ });
83
+ },
84
+ getTargetTemp: function (callback) {
85
+ this.log("getCurrentTemp")
86
+ this.client.fetchState(this.entity_id, function (data) {
87
+ if (data) {
88
+ if (getTempUnits(data) === 'FAHRENHEIT') {
89
+ callback(null, fahrenheitToCelsius(data.attributes.temperature));
90
+ } else {
91
+ callback(null, data.attributes.temperature);
92
+ }
93
+ } else {
94
+ callback(communicationError);
95
+ }
96
+ });
97
+ },
98
+ setTargetTemp: function (value, callback, context) {
99
+ if (context === 'internal') {
100
+ callback();
101
+ return;
102
+ }
103
+
104
+ var that = this;
105
+ var serviceData = {};
106
+ serviceData.entity_id = this.entity_id;
107
+ serviceData.temperature = value;
108
+
109
+ if (getTempUnits(this.data) === 'FAHRENHEIT') {
110
+ serviceData.temperature = celsiusToFahrenheit(serviceData.temperature);
111
+ }
112
+
113
+ this.log(`Setting temperature on the '${this.name}' to ${serviceData.temperature}`);
114
+
115
+ this.client.callService(this.domain, 'set_temperature', serviceData, function (data) {
116
+ if (data) {
117
+ that.log(`Successfully set temperature of '${that.name}'`);
118
+ callback();
119
+ } else {
120
+ callback(communicationError);
121
+ }
122
+ });
123
+ },
124
+ getTargetHeatingCoolingState: function (callback) {
125
+ this.log('fetching Current Heating Cooling state for: ' + this.name);
126
+
127
+ this.client.fetchState(this.entity_id, function (data) {
128
+ if (data && data.attributes && data.attributes.operation_mode) {
129
+ var state;
130
+ switch (data.attributes.operation_mode) {
131
+ case 'auto':
132
+ state = Characteristic.TargetHeatingCoolingState.AUTO;
133
+ break;
134
+ case 'cool':
135
+ state = Characteristic.TargetHeatingCoolingState.COOL;
136
+ break;
137
+ case 'heat':
138
+ state = Characteristic.TargetHeatingCoolingState.HEAT;
139
+ break;
140
+ case 'off':
141
+ default:
142
+ state = Characteristic.TargetHeatingCoolingState.OFF;
143
+ break;
144
+ }
145
+ callback(null, state);
146
+ } else {
147
+ callback(communicationError);
148
+ }
149
+ });
150
+ },
151
+
152
+ setTargetHeatingCoolingState: function (value, callback, context) {
153
+ if (context === 'internal') {
154
+ callback();
155
+ return;
156
+ }
157
+ var serviceData = {};
158
+ serviceData.entity_id = this.entity_id;
159
+
160
+ var mode = '';
161
+ switch (value) {
162
+ case Characteristic.TargetHeatingCoolingState.AUTO:
163
+ mode = 'auto';
164
+ break;
165
+ case Characteristic.TargetHeatingCoolingState.COOL:
166
+ mode = 'cool';
167
+ break;
168
+ case Characteristic.TargetHeatingCoolingState.HEAT:
169
+ mode = 'heat';
170
+ break;
171
+ case Characteristic.TargetHeatingCoolingState.OFF:
172
+ default:
173
+ mode = 'off';
174
+ break;
175
+ }
176
+
177
+ serviceData.operation_mode = mode;
178
+ this.log(`Setting Current Heating Cooling state on the '${this.name}' to ${mode}`);
179
+
180
+ var that = this;
181
+
182
+ this.client.callService(this.domain, 'set_operation_mode', serviceData, function (data) {
183
+ if (data) {
184
+ that.log(`Successfully set current heating cooling state of '${that.name}'`);
185
+ callback();
186
+ } else {
187
+ callback(communicationError);
188
+ }
189
+ });
190
+ },
191
+
192
+ getServices: function () {
193
+ this.ThermostatService = new Service.Thermostat();
194
+ var informationService = new Service.AccessoryInformation();
195
+
196
+ informationService
197
+ .setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
198
+ .setCharacteristic(Characteristic.Model, this.model)
199
+ .setCharacteristic(Characteristic.SerialNumber, this.serial)
200
+ .setCharacteristic(Characteristic.FirmwareRevision, this.firmware);
201
+
202
+ // get our unit var -- default to celsius
203
+ var units = (getTempUnits(this.data) === 'FAHRENHEIT') ? Characteristic.TemperatureDisplayUnits.FAHRENHEIT : Characteristic.TemperatureDisplayUnits.CELSIUS;
204
+
205
+ this.ThermostatService
206
+ .getCharacteristic(Characteristic.CurrentTemperature)
207
+ .on('get', this.getCurrentTemp.bind(this));
208
+
209
+ // default min/max/step for temperature
210
+ var minTemp = 16;
211
+ var maxTemp = 35;
212
+ var tempStep = 1;
213
+
214
+ if (units === Characteristic.TemperatureDisplayUnits.FAHRENHEIT) {
215
+ if (this.data && this.data.attributes) {
216
+ if (this.data.attributes.min_temp) {
217
+ minTemp = fahrenheitToCelsius(this.data.attributes.min_temp);
218
+ }
219
+ if (this.data.attributes.max_temp) {
220
+ maxTemp = fahrenheitToCelsius(this.data.attributes.max_temp);
221
+ }
222
+ if (this.data.attributes.target_temp_step) {
223
+ tempStep = this.data.attributes.target_temp_step;
224
+ }
225
+ }
226
+ } else if (this.data && this.data.attributes) {
227
+ if (this.data.attributes.min_temp) {
228
+ minTemp = this.data.attributes.min_temp;
229
+ }
230
+ if (this.data.attributes.max_temp) {
231
+ maxTemp = this.data.attributes.max_temp;
232
+ }
233
+ if (this.data.attributes.target_temp_step) {
234
+ tempStep = this.data.attributes.target_temp_step;
235
+ }
236
+ }
237
+
238
+ this.ThermostatService
239
+ .getCharacteristic(Characteristic.TargetTemperature)
240
+ .setProps({ minValue: minTemp, maxValue: maxTemp, minStep: tempStep })
241
+ .on('get', this.getTargetTemp.bind(this))
242
+ .on('set', this.setTargetTemp.bind(this));
243
+
244
+ this.ThermostatService
245
+ .getCharacteristic(Characteristic.TargetHeatingCoolingState)
246
+ .on('get', this.getTargetHeatingCoolingState.bind(this))
247
+ .on('set', this.setTargetHeatingCoolingState.bind(this));
248
+
249
+ this.ThermostatService.setCharacteristic(Characteristic.TemperatureDisplayUnits, units);
250
+
251
+ return [informationService, this.ThermostatService];
252
+ }
253
+
254
+
255
+ };
256
+
257
+ function HomeAssistantClimatePlatform(oService, oCharacteristic, oCommunicationError) {
258
+ Service = oService;
259
+ Characteristic = oCharacteristic;
260
+ communicationError = oCommunicationError;
261
+
262
+ return HomeAssistantClimate;
263
+ }
264
+
265
+ module.exports = HomeAssistantClimatePlatform;
266
+ module.exports.HomeAssistantClimate = HomeAssistantClimate;