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,214 @@
1
+ 'use strict';
2
+
3
+ let Service;
4
+ let Characteristic;
5
+ let communicationError;
6
+
7
+ class HomeAssistantCover {
8
+ constructor(log, data, client, firmware) {
9
+ this.client = client;
10
+ this.log = log;
11
+ // device info
12
+ this.domain = 'cover';
13
+ this.data = data;
14
+ this.entity_id = data.entity_id;
15
+ this.uuid_base = data.entity_id;
16
+ this.firmware = firmware;
17
+ if (data.attributes && data.attributes.friendly_name) {
18
+ this.name = data.attributes.friendly_name;
19
+ } else {
20
+ this.name = data.entity_id.split('.').pop().replace(/_/g, ' ');
21
+ }
22
+ if (data.attributes && data.attributes.homebridge_manufacturer) {
23
+ this.manufacturer = String(data.attributes.homebridge_manufacturer);
24
+ } else {
25
+ this.manufacturer = 'Home Assistant';
26
+ }
27
+ if (data.attributes && data.attributes.homebridge_serial) {
28
+ this.serial = String(data.attributes.homebridge_serial);
29
+ } else {
30
+ this.serial = data.entity_id;
31
+ }
32
+ }
33
+
34
+ onEvent(oldState, newState) {
35
+ if (newState.state) {
36
+ const state = this.transformData(newState);
37
+
38
+ this.service.updateCharacteristic(this.stateCharacteristic, state);
39
+ //this.service.getCharacteristic(this.stateCharacteristic).setValue(state, null, 'internal');
40
+ this.service.updateCharacteristic(this.targetCharacteristic, state);
41
+ //this.service.getCharacteristic(this.targetCharacteristic).setValue(state, null, 'internal');
42
+ }
43
+ }
44
+
45
+ getState(callback) {
46
+ this.client.fetchState(this.entity_id, (data) => {
47
+ if (data) {
48
+ callback(null, this.transformData(data));
49
+ } else {
50
+ callback(communicationError);
51
+ }
52
+ });
53
+ }
54
+
55
+ getServices() {
56
+ const informationService = new Service.AccessoryInformation();
57
+ informationService
58
+ .setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
59
+ .setCharacteristic(Characteristic.Model, this.model)
60
+ .setCharacteristic(Characteristic.SerialNumber, this.serial)
61
+ .setCharacteristic(Characteristic.FirmwareRevision, this.firmware);
62
+
63
+ this.service
64
+ .getCharacteristic(this.stateCharacteristic)
65
+ .on('get', this.getState.bind(this));
66
+
67
+ this.service
68
+ .getCharacteristic(this.targetCharacteristic)
69
+ .on('get', this.getState.bind(this))
70
+ .on('set', this.setTargetState.bind(this));
71
+
72
+ return [informationService, this.service];
73
+ }
74
+
75
+ doChangeState(service, callback) {
76
+ const serviceData = {
77
+ entity_id: this.entity_id,
78
+ };
79
+
80
+ this.log(`Calling service ${service} on ${this.name}`);
81
+
82
+ this.client.callService(this.domain, service, serviceData, (data) => {
83
+ if (data) {
84
+ callback();
85
+ } else {
86
+ callback(communicationError);
87
+ }
88
+ });
89
+ }
90
+ }
91
+
92
+ class HomeAssistantGarageDoor extends HomeAssistantCover {
93
+ constructor(log, data, client, firmware) {
94
+ super(log, data, client, firmware);
95
+ if (data.attributes && data.attributes.homebridge_model) {
96
+ this.model = String(data.attributes.homebridge_model);
97
+ } else {
98
+ this.model = 'Garage Door';
99
+ }
100
+ this.service = new Service.GarageDoorOpener();
101
+ this.stateCharacteristic = Characteristic.CurrentDoorState;
102
+ this.targetCharacteristic = Characteristic.TargetDoorState;
103
+ }
104
+
105
+ transformData(data) {
106
+ return data.state === 'closed' ? this.stateCharacteristic.CLOSED : this.stateCharacteristic.OPEN;
107
+ }
108
+
109
+ setTargetState(targetState, callback, context) {
110
+ if (context === 'internal') {
111
+ callback();
112
+ return;
113
+ }
114
+
115
+ this.doChangeState(targetState === Characteristic.TargetDoorState.CLOSED ? 'close_cover' : 'open_cover', callback);
116
+ }
117
+ }
118
+
119
+ class HomeAssistantRollershutter extends HomeAssistantCover {
120
+ constructor(log, data, client, firmware) {
121
+ super(log, data, client, firmware);
122
+ if (data.attributes && data.attributes.homebridge_model) {
123
+ this.model = String(data.attributes.homebridge_model);
124
+ } else {
125
+ this.model = 'Rollershutter';
126
+ }
127
+ this.service = new Service.WindowCovering();
128
+ this.stateCharacteristic = Characteristic.CurrentPosition;
129
+ this.targetCharacteristic = Characteristic.TargetPosition;
130
+ }
131
+
132
+ transformData(data) {
133
+ //console.log("transformData")
134
+ return (data && data.attributes) ? data.attributes.current_position : null;
135
+ }
136
+
137
+ setTargetState(position, callback, context) {
138
+ //console.log("setTargetState")
139
+ if (context === 'internal') {
140
+ callback();
141
+ return;
142
+ }
143
+
144
+ const payload = {
145
+ entity_id: this.entity_id,
146
+ position,
147
+ };
148
+
149
+ this.log(`Setting the state of the ${this.name} to ${payload.position}`);
150
+
151
+ this.client.callService(this.domain, 'set_cover_position', payload, (data) => {
152
+ console.log("setTargetState callService")
153
+ if (data) {
154
+ callback();
155
+ } else {
156
+ callback(communicationError);
157
+ }
158
+ });
159
+ }
160
+ }
161
+
162
+ class HomeAssistantRollershutterBinary extends HomeAssistantRollershutter {
163
+ transformData(data) {
164
+ return (data && data.state) ? ((data.state === 'open') * 100) : null;
165
+ }
166
+
167
+ setTargetState(position, callback, context) {
168
+ if (context === 'internal') {
169
+ callback();
170
+ return;
171
+ }
172
+
173
+ if (!(position === 100 || position === 0)) {
174
+ this.log('Cannot set this cover to positions other than 0 or 100');
175
+ callback(communicationError); // TODO
176
+ } else {
177
+ this.doChangeState(position === 100 ? 'open_cover' : 'close_cover', callback);
178
+ }
179
+ }
180
+ }
181
+
182
+ function HomeAssistantCoverFactory(log, data, client, firmware) {
183
+ if (!data.attributes) {
184
+ return null;
185
+ }
186
+
187
+ if (data.attributes.homebridge_cover_type === 'garage_door') {
188
+ return new HomeAssistantGarageDoor(log, data, client, firmware);
189
+ } else if (data.attributes.homebridge_cover_type === 'rollershutter') {
190
+ if (data.attributes.current_position !== undefined) {
191
+ console.log("HomeAssistantRollershutter")
192
+ return new HomeAssistantRollershutter(log, data, client, firmware);
193
+ }
194
+ console.log("HomeAssistantRollershutterBinary")
195
+ return new HomeAssistantRollershutterBinary(log, data, client, firmware);
196
+ }
197
+ log.error(`'${data.entity_id}' is a cover but does not have a 'homebridge_cover_type' property set. ` +
198
+ 'You must set it to either \'rollershutter\' or \'garage_door\' in the customize section ' +
199
+ 'of your Home Assistant configuration. It will not be available to Homebridge until you do. ' +
200
+ 'See the README.md for more information. ' +
201
+ 'The attributes that were found are:', JSON.stringify(data.attributes));
202
+ }
203
+
204
+ function HomeAssistantCoverPlatform(oService, oCharacteristic, oCommunicationError) {
205
+ Service = oService;
206
+ Characteristic = oCharacteristic;
207
+ communicationError = oCommunicationError;
208
+
209
+ return HomeAssistantCoverFactory;
210
+ }
211
+
212
+ module.exports = HomeAssistantCoverPlatform;
213
+
214
+ module.exports.HomeAssistantCoverFactory = HomeAssistantCoverFactory;
@@ -0,0 +1,152 @@
1
+ 'use strict';
2
+
3
+ var Service;
4
+ var Characteristic;
5
+ var communicationError;
6
+
7
+ class HomeAssistantDeviceTracker {
8
+ constructor(log, data, client, service, characteristic, onValue, offValue, firmware) {
9
+ // device info
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 = 'Device Tracker';
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.entity_type = data.entity_id.split('.')[0];
35
+ this.client = client;
36
+ this.log = log;
37
+ this.service = service;
38
+ this.characteristic = characteristic;
39
+ this.onValue = onValue;
40
+ this.offValue = offValue;
41
+ this.batterySource = data.attributes.homebridge_battery_source;
42
+ this.chargingSource = data.attributes.homebridge_charging_source;
43
+ }
44
+
45
+ onEvent(oldState, newState) {
46
+ if (newState.state) {
47
+ this.sensorService.getCharacteristic(this.characteristic)
48
+ .setValue(newState.state === 'home' ? this.onValue : this.offValue, null, 'internal');
49
+ }
50
+ }
51
+ identify(callback) {
52
+ this.log('identifying: ' + this.name);
53
+ callback();
54
+ }
55
+ getState(callback) {
56
+ this.log('fetching state for: ' + this.name);
57
+ this.client.fetchState(this.entity_id, function (data) {
58
+ if (data) {
59
+ callback(null, data.state === 'home' ? this.onValue : this.offValue);
60
+ } else {
61
+ callback(communicationError);
62
+ }
63
+ }.bind(this));
64
+ }
65
+ getBatteryLevel(callback) {
66
+ this.client.fetchState(this.batterySource, (data) => {
67
+ if (data) {
68
+ callback(null, parseFloat(data.state));
69
+ } else {
70
+ callback(communicationError);
71
+ }
72
+ });
73
+ }
74
+ getChargingState(callback) {
75
+ if (this.batterySource && this.chargingSource) {
76
+ this.client.fetchState(this.chargingSource, (data) => {
77
+ if (data) {
78
+ callback(null, data.state.toLowerCase() === 'charging' ? 1 : 0);
79
+ } else {
80
+ callback(communicationError);
81
+ }
82
+ });
83
+ } else {
84
+ callback(null, 2);
85
+ }
86
+ }
87
+ getLowBatteryStatus(callback) {
88
+ this.client.fetchState(this.batterySource, (data) => {
89
+ if (data) {
90
+ callback(null, parseFloat(data.state) > 20 ? 0 : 1);
91
+ } else {
92
+ callback(communicationError);
93
+ }
94
+ });
95
+ }
96
+ getServices() {
97
+ this.sensorService = new this.service();
98
+ this.sensorService
99
+ .getCharacteristic(this.characteristic)
100
+ .on('get', this.getState.bind(this));
101
+
102
+ var informationService = new Service.AccessoryInformation();
103
+
104
+ informationService
105
+ .setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
106
+ .setCharacteristic(Characteristic.Model, this.model)
107
+ .setCharacteristic(Characteristic.SerialNumber, this.serial)
108
+ .setCharacteristic(Characteristic.FirmwareRevision, this.firmware);
109
+
110
+ if (this.batterySource) {
111
+ this.batteryService = new Service.BatteryService();
112
+ this.batteryService
113
+ .getCharacteristic(Characteristic.BatteryLevel)
114
+ .setProps({ maxValue: 100, minValue: 0, minStep: 1 })
115
+ .on('get', this.getBatteryLevel.bind(this));
116
+ this.batteryService
117
+ .getCharacteristic(Characteristic.ChargingState)
118
+ .setProps({ maxValue: 2 })
119
+ .on('get', this.getChargingState.bind(this));
120
+ this.batteryService
121
+ .getCharacteristic(Characteristic.StatusLowBattery)
122
+ .on('get', this.getLowBatteryStatus.bind(this));
123
+ return [informationService, this.batteryService, this.sensorService];
124
+ }
125
+ return [informationService, this.sensorService];
126
+ }
127
+ }
128
+
129
+ function HomeAssistantDeviceTrackerFactory(log, data, client, firmware) {
130
+ if (!(data.attributes)) {
131
+ return null;
132
+ }
133
+ return new HomeAssistantDeviceTracker(
134
+ log, data, client,
135
+ Service.OccupancySensor,
136
+ Characteristic.OccupancyDetected,
137
+ Characteristic.OccupancyDetected.OCCUPANCY_DETECTED,
138
+ Characteristic.OccupancyDetected.OCCUPANCY_NOT_DETECTED,
139
+ firmware
140
+ );
141
+ }
142
+
143
+ function HomeAssistantDeviceTrackerFactoryPlatform(oService, oCharacteristic, oCommunicationError) {
144
+ Service = oService;
145
+ Characteristic = oCharacteristic;
146
+ communicationError = oCommunicationError;
147
+
148
+ return HomeAssistantDeviceTrackerFactory;
149
+ }
150
+
151
+ module.exports = HomeAssistantDeviceTrackerFactoryPlatform;
152
+ module.exports.HomeAssistantDeviceTrackerFactory = HomeAssistantDeviceTrackerFactory;
@@ -0,0 +1,254 @@
1
+ 'use strict';
2
+
3
+ let Service;
4
+ let Characteristic;
5
+ let communicationError;
6
+
7
+ function HomeAssistantFan(log, data, client, firmware) {
8
+ // device info
9
+ this.domain = 'fan';
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 = 'Fan';
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
+ if (data.attributes.speed_list) {
35
+ var speedList = data.attributes.speed_list;
36
+ this.maxValue = speedList.length - 1;
37
+ } else {
38
+ this.maxValue = 100;
39
+ }
40
+ this.client = client;
41
+ this.log = log;
42
+ }
43
+
44
+ HomeAssistantFan.prototype = {
45
+ onEvent(oldState, newState) {
46
+ if (newState.state) {
47
+ this.fanService.getCharacteristic(Characteristic.On)
48
+ .setValue(newState.state === 'on', null, 'internal');
49
+
50
+ if (newState.state === 'on') {
51
+ let speed;
52
+ if (newState.attributes.speed_list) {
53
+ var speedList = newState.attributes.speed_list;
54
+ if (speedList.length > 2) {
55
+ speed = speedList.indexOf(newState.attributes.speed);
56
+ }
57
+ } else {
58
+ switch (newState.attributes.speed) {
59
+ case 'low':
60
+ speed = 25;
61
+ break;
62
+ case 'medium':
63
+ speed = 50;
64
+ break;
65
+ case 'high':
66
+ speed = 100;
67
+ break;
68
+ default:
69
+ speed = 0;
70
+ }
71
+ }
72
+ this.fanService.getCharacteristic(Characteristic.RotationSpeed)
73
+ .setValue(speed, null, 'internal');
74
+ }
75
+ }
76
+ },
77
+ getPowerState(callback) {
78
+ this.client.fetchState(this.entity_id, (data) => {
79
+ if (data) {
80
+ const powerState = data.state === 'on';
81
+ callback(null, powerState);
82
+ } else {
83
+ callback(communicationError);
84
+ }
85
+ });
86
+ },
87
+ setPowerState(powerOn, callback, context) {
88
+ if (context === 'internal') {
89
+ callback();
90
+ return;
91
+ }
92
+
93
+ const that = this;
94
+ const serviceData = {};
95
+ serviceData.entity_id = this.entity_id;
96
+
97
+ if (powerOn) {
98
+ this.log(`Setting power state on the '${this.name}' to on`);
99
+
100
+ this.client.callService(this.domain, 'turn_on', serviceData, (data) => {
101
+ if (data) {
102
+ that.log(`Successfully set power state on the '${that.name}' to on`);
103
+ callback();
104
+ } else {
105
+ callback(communicationError);
106
+ }
107
+ });
108
+ } else {
109
+ this.log(`Setting power state on the '${this.name}' to off`);
110
+
111
+ this.client.callService(this.domain, 'turn_off', serviceData, (data) => {
112
+ if (data) {
113
+ that.log(`Successfully set power state on the '${that.name}' to off`);
114
+ callback();
115
+ } else {
116
+ callback(communicationError);
117
+ }
118
+ });
119
+ }
120
+ },
121
+ getRotationSpeed(callback) {
122
+ this.client.fetchState(this.entity_id, (data) => {
123
+ if (data) {
124
+ if (data.state === 'off') {
125
+ callback(null, 0);
126
+ } else if (data.attributes.speed_list) {
127
+ var speedList = data.attributes.speed_list;
128
+ if (speedList.length > 2) {
129
+ var index = speedList.indexOf(data.attributes.speed);
130
+ callback(null, index);
131
+ }
132
+ } else {
133
+ switch (data.attributes.speed) {
134
+ case 'low':
135
+ callback(null, 25);
136
+ break;
137
+ case 'medium':
138
+ callback(null, 50);
139
+ break;
140
+ case 'mediumHigh':
141
+ callback(null, 75);
142
+ break;
143
+ case 'high':
144
+ callback(null, 100);
145
+ break;
146
+ default:
147
+ callback(null, 0);
148
+ }
149
+ }
150
+ } else {
151
+ callback(communicationError);
152
+ }
153
+ });
154
+ },
155
+ setRotationSpeed(speed, callback, context) {
156
+ if (context === 'internal') {
157
+ callback();
158
+ return;
159
+ }
160
+
161
+ const that = this;
162
+ const serviceData = {};
163
+ serviceData.entity_id = this.entity_id;
164
+
165
+ if (speed === 0) {
166
+ this.log(`Setting power state on the '${this.name}' to off`);
167
+
168
+ this.client.callService(this.domain, 'turn_off', serviceData, (data) => {
169
+ if (data) {
170
+ that.log(`Successfully set power state on the '${that.name}' to off`);
171
+ callback();
172
+ } else {
173
+ callback(communicationError);
174
+ }
175
+ });
176
+ } else {
177
+ this.client.fetchState(this.entity_id, (data) => {
178
+ if (data) {
179
+ if (data.attributes.speed_list) {
180
+ var speedList = data.attributes.speed_list;
181
+ for (var index = 0; index < speedList.length - 1; index += 1) {
182
+ if (speed === index) {
183
+ serviceData.speed = speedList[index];
184
+ break;
185
+ }
186
+ }
187
+ if (!serviceData.speed) {
188
+ serviceData.speed = speedList[speedList.length - 1];
189
+ }
190
+ } else if (speed <= 25) {
191
+ serviceData.speed = 'low';
192
+ } else if (speed <= 50) {
193
+ serviceData.speed = 'mediumHigh';
194
+ } else if (speed <= 75) {
195
+ serviceData.speed = 'medium';
196
+ } else if (speed <= 100) {
197
+ serviceData.speed = 'high';
198
+ }
199
+ this.log(`Setting speed on the '${this.name}' to ${serviceData.speed}`);
200
+
201
+ this.client.callService(this.domain, 'set_speed', serviceData, (data2) => {
202
+ if (data2) {
203
+ that.log(`Successfully set power state on the '${that.name}' to on`);
204
+ callback();
205
+ } else {
206
+ callback(communicationError);
207
+ }
208
+ });
209
+ } else {
210
+ callback(communicationError);
211
+ }
212
+ });
213
+ }
214
+ },
215
+ getServices() {
216
+ this.fanService = new Service.Fan();
217
+ const informationService = new Service.AccessoryInformation();
218
+
219
+ informationService
220
+ .setCharacteristic(Characteristic.Manufacturer, this.manufacturer)
221
+ .setCharacteristic(Characteristic.Model, this.model)
222
+ .setCharacteristic(Characteristic.SerialNumber, this.serial)
223
+ .setCharacteristic(Characteristic.FirmwareRevision, this.firmware);
224
+
225
+ this.fanService
226
+ .getCharacteristic(Characteristic.On)
227
+ .on('get', this.getPowerState.bind(this))
228
+ .on('set', this.setPowerState.bind(this));
229
+
230
+ this.fanService
231
+ .getCharacteristic(Characteristic.RotationSpeed)
232
+ .setProps({
233
+ minValue: 0,
234
+ maxValue: this.maxValue,
235
+ minStep: 1
236
+ })
237
+ .on('get', this.getRotationSpeed.bind(this))
238
+ .on('set', this.setRotationSpeed.bind(this));
239
+
240
+ return [informationService, this.fanService];
241
+ },
242
+
243
+ };
244
+
245
+ function HomeAssistantFanPlatform(oService, oCharacteristic, oCommunicationError) {
246
+ Service = oService;
247
+ Characteristic = oCharacteristic;
248
+ communicationError = oCommunicationError;
249
+
250
+ return HomeAssistantFan;
251
+ }
252
+
253
+ module.exports = HomeAssistantFanPlatform;
254
+ module.exports.HomeAssistantFan = HomeAssistantFan;