homebridge-openwrt-control 0.0.1-beta.4 → 0.0.2-beta.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.
- package/CHANGELOG.md +3 -1
- package/package.json +1 -1
- package/src/apdevice.js +18 -18
- package/src/swdevice.js +28 -30
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/apdevice.js
CHANGED
|
@@ -12,7 +12,7 @@ class AccessPointDevice extends EventEmitter {
|
|
|
12
12
|
AccessoryUUID = api.hap.uuid;
|
|
13
13
|
|
|
14
14
|
//config
|
|
15
|
-
this.name = config.name;
|
|
15
|
+
this.name = config.accessPoint.name || openWrtInfo.systemInfo.hostname;
|
|
16
16
|
this.accessPoint = config.accessPoint;
|
|
17
17
|
this.logInfo = config.log?.info || false;
|
|
18
18
|
this.logDebug = config.log?.debug || false;
|
|
@@ -121,7 +121,7 @@ class AccessPointDevice extends EventEmitter {
|
|
|
121
121
|
//prepare accessory
|
|
122
122
|
if (this.logDebug) this.emit('debug', `prepare accessory`);
|
|
123
123
|
const accessoryName = this.name;
|
|
124
|
-
const accessoryUUID = AccessoryUUID.generate(this.
|
|
124
|
+
const accessoryUUID = AccessoryUUID.generate(this.openWrtInfo.systemInfo.hostname);
|
|
125
125
|
const accessoryCategory = Categories.AIRPORT;
|
|
126
126
|
const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
|
|
127
127
|
|
|
@@ -129,9 +129,9 @@ class AccessPointDevice extends EventEmitter {
|
|
|
129
129
|
if (this.logDebug) this.emit('debug', `prepare information service`);
|
|
130
130
|
accessory.getService(Service.AccessoryInformation)
|
|
131
131
|
.setCharacteristic(Characteristic.Manufacturer, 'OpenWrt')
|
|
132
|
-
.setCharacteristic(Characteristic.Model,
|
|
133
|
-
.setCharacteristic(Characteristic.SerialNumber, this.
|
|
134
|
-
.setCharacteristic(Characteristic.FirmwareRevision, this.
|
|
132
|
+
.setCharacteristic(Characteristic.Model, this.openWrtInfo.systemInfo.model)
|
|
133
|
+
.setCharacteristic(Characteristic.SerialNumber, this.openWrtInfo.systemInfo.system)
|
|
134
|
+
.setCharacteristic(Characteristic.FirmwareRevision, this.openWrtInfo.systemInfo.release?.description)
|
|
135
135
|
.setCharacteristic(Characteristic.ConfiguredName, accessoryName);
|
|
136
136
|
|
|
137
137
|
if (this.logDebug) this.emit('debug', `prepare service`);
|
|
@@ -139,37 +139,37 @@ class AccessPointDevice extends EventEmitter {
|
|
|
139
139
|
//device
|
|
140
140
|
this.services = [];
|
|
141
141
|
for (const ssid of this.ssids) {
|
|
142
|
-
const
|
|
143
|
-
if (this.logDebug) this.emit('debug', `prepare ssid: ${
|
|
142
|
+
const name = ssid.name;
|
|
143
|
+
if (this.logDebug) this.emit('debug', `prepare ssid: ${name} service`);
|
|
144
144
|
|
|
145
|
-
const serviceName = this.accessPoint.namePrefix ? `${
|
|
146
|
-
const service = accessory.addService(Service.Switch, serviceName, `service${
|
|
145
|
+
const serviceName = this.accessPoint.namePrefix ? `${accessoryName} ${name}` : name;
|
|
146
|
+
const service = accessory.addService(Service.Switch, serviceName, `service${name}`);
|
|
147
147
|
service.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
148
148
|
service.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
149
149
|
service.getCharacteristic(Characteristic.On)
|
|
150
150
|
.onGet(async () => {
|
|
151
151
|
const state = ssid.state;
|
|
152
|
-
if (this.logInfo) this.emit('message', `SSID: ${
|
|
152
|
+
if (this.logInfo) this.emit('message', `SSID: ${name}, state: ${state ? 'Enabled' : 'Disabled'}`);
|
|
153
153
|
return state;
|
|
154
154
|
})
|
|
155
155
|
.onSet(async (state) => {
|
|
156
156
|
try {
|
|
157
157
|
state = state ? true : false;
|
|
158
|
-
await this.openWrt.send('ssid',
|
|
159
|
-
if (this.logInfo) this.emit('message', `SSID: ${
|
|
158
|
+
await this.openWrt.send('ssid', name, state);
|
|
159
|
+
if (this.logInfo) this.emit('message', `SSID: ${name}, set State: ${state ? 'Enabled' : 'Disabled'}`);
|
|
160
160
|
} catch (error) {
|
|
161
|
-
this.emit('warn', `SSID: ${
|
|
161
|
+
this.emit('warn', `SSID: ${name}, set state error: ${error}`);
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
164
|
this.services.push(service);
|
|
165
165
|
|
|
166
166
|
if (this.accessPoint.sensor) {
|
|
167
|
-
if (this.logDebug) this.emit('debug', `prepare ssid: ${
|
|
167
|
+
if (this.logDebug) this.emit('debug', `prepare ssid: ${name} sensor service`);
|
|
168
168
|
|
|
169
169
|
this.sensorServices = [];
|
|
170
|
-
const sensorService = accessory.addService(Service.ContactSensor,
|
|
170
|
+
const sensorService = accessory.addService(Service.ContactSensor, serviceName, `sensorService${name}`);
|
|
171
171
|
sensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
172
|
-
sensorService.setCharacteristic(Characteristic.ConfiguredName,
|
|
172
|
+
sensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
173
173
|
sensorService.getCharacteristic(Characteristic.ContactSensorState)
|
|
174
174
|
.onGet(async () => {
|
|
175
175
|
const state = ssid.state;
|
|
@@ -195,12 +195,12 @@ class AccessPointDevice extends EventEmitter {
|
|
|
195
195
|
this.emit('devInfo', `Name: ${this.openWrtInfo.systemInfo.hostname}`);
|
|
196
196
|
this.emit('devInfo', `Model: ${this.openWrtInfo.systemInfo.model}`);
|
|
197
197
|
this.emit('devInfo', `System: ${this.openWrtInfo.systemInfo.system}`);
|
|
198
|
-
this.emit('devInfo', `
|
|
198
|
+
this.emit('devInfo', `Firmware: ${this.openWrtInfo.systemInfo.release?.description}`);
|
|
199
199
|
this.emit('devInfo', `----------------------------------`);
|
|
200
200
|
|
|
201
201
|
//denon client
|
|
202
202
|
this.openWrt.on('systemInfo', (info) => {
|
|
203
|
-
this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.
|
|
203
|
+
this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.description);
|
|
204
204
|
})
|
|
205
205
|
.on('wirelessStatus', async (status) => {
|
|
206
206
|
})
|
package/src/swdevice.js
CHANGED
|
@@ -12,7 +12,7 @@ class SwitchDevice extends EventEmitter {
|
|
|
12
12
|
AccessoryUUID = api.hap.uuid;
|
|
13
13
|
|
|
14
14
|
//config
|
|
15
|
-
this.name = config.name;
|
|
15
|
+
this.name = config.switch.name || openWrtInfo.systemInfo.hostname;
|
|
16
16
|
this.switch = config.switch;
|
|
17
17
|
this.logInfo = config.log?.info || false;
|
|
18
18
|
this.logDebug = config.log?.debug || false;
|
|
@@ -121,58 +121,58 @@ class SwitchDevice extends EventEmitter {
|
|
|
121
121
|
//prepare accessory
|
|
122
122
|
if (this.logDebug) this.emit('debug', `prepare accessory`);
|
|
123
123
|
const accessoryName = this.name;
|
|
124
|
-
const accessoryUUID = AccessoryUUID.generate(this.
|
|
125
|
-
const accessoryCategory = Categories.
|
|
124
|
+
const accessoryUUID = AccessoryUUID.generate(this.openWrtInfo.systemInfo.hostname);
|
|
125
|
+
const accessoryCategory = Categories.ROUTER;
|
|
126
126
|
const accessory = new Accessory(accessoryName, accessoryUUID, accessoryCategory);
|
|
127
127
|
|
|
128
128
|
//prepare information service
|
|
129
129
|
if (this.logDebug) this.emit('debug', `prepare information service`);
|
|
130
130
|
accessory.getService(Service.AccessoryInformation)
|
|
131
131
|
.setCharacteristic(Characteristic.Manufacturer, 'OpenWrt')
|
|
132
|
-
.setCharacteristic(Characteristic.Model,
|
|
133
|
-
.setCharacteristic(Characteristic.SerialNumber, this.
|
|
134
|
-
.setCharacteristic(Characteristic.FirmwareRevision, this.
|
|
132
|
+
.setCharacteristic(Characteristic.Model, this.openWrtInfo.systemInfo.model)
|
|
133
|
+
.setCharacteristic(Characteristic.SerialNumber, this.openWrtInfo.systemInfo.system)
|
|
134
|
+
.setCharacteristic(Characteristic.FirmwareRevision, this.openWrtInfo.systemInfo.release?.description)
|
|
135
135
|
.setCharacteristic(Characteristic.ConfiguredName, accessoryName);
|
|
136
136
|
|
|
137
137
|
if (this.logDebug) this.emit('debug', `prepare service`);
|
|
138
138
|
|
|
139
139
|
//device
|
|
140
140
|
this.services = [];
|
|
141
|
-
for (const
|
|
142
|
-
const
|
|
143
|
-
if (this.logDebug) this.emit('debug', `prepare
|
|
141
|
+
for (const port of this.ports) {
|
|
142
|
+
const name = port.name;
|
|
143
|
+
if (this.logDebug) this.emit('debug', `prepare port: ${name} service`);
|
|
144
144
|
|
|
145
|
-
const serviceName = this.accessPoint.namePrefix ? `${
|
|
145
|
+
const serviceName = this.accessPoint.namePrefix ? `${accessoryName} ${ssidName}` : ssidName;
|
|
146
146
|
const service = accessory.addService(Service.Switch, serviceName, `service${ssidName}`);
|
|
147
147
|
service.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
148
148
|
service.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
149
149
|
service.getCharacteristic(Characteristic.On)
|
|
150
150
|
.onGet(async () => {
|
|
151
|
-
const state =
|
|
152
|
-
if (this.logInfo) this.emit('message', `
|
|
151
|
+
const state = port.state;
|
|
152
|
+
if (this.logInfo) this.emit('message', `Port: ${name}, state: ${state ? 'Enabled' : 'Disabled'}`);
|
|
153
153
|
return state;
|
|
154
154
|
})
|
|
155
155
|
.onSet(async (state) => {
|
|
156
156
|
try {
|
|
157
157
|
state = state ? true : false;
|
|
158
|
-
await this.openWrt.send('
|
|
159
|
-
if (this.logInfo) this.emit('message', `
|
|
158
|
+
await this.openWrt.send('port', name, state);
|
|
159
|
+
if (this.logInfo) this.emit('message', `Port: ${name}, set State: ${state ? 'Enabled' : 'Disabled'}`);
|
|
160
160
|
} catch (error) {
|
|
161
|
-
this.emit('warn', `
|
|
161
|
+
this.emit('warn', `Port: ${name}, set state error: ${error}`);
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
164
|
this.services.push(service);
|
|
165
165
|
|
|
166
166
|
if (this.accessPoint.sensor) {
|
|
167
|
-
if (this.logDebug) this.emit('debug', `prepare
|
|
167
|
+
if (this.logDebug) this.emit('debug', `prepare port: ${name} sensor service`);
|
|
168
168
|
|
|
169
169
|
this.sensorServices = [];
|
|
170
|
-
const sensorService = accessory.addService(Service.ContactSensor,
|
|
170
|
+
const sensorService = accessory.addService(Service.ContactSensor, serviceName, `sensorService${name}`);
|
|
171
171
|
sensorService.addOptionalCharacteristic(Characteristic.ConfiguredName);
|
|
172
|
-
sensorService.setCharacteristic(Characteristic.ConfiguredName,
|
|
172
|
+
sensorService.setCharacteristic(Characteristic.ConfiguredName, serviceName);
|
|
173
173
|
sensorService.getCharacteristic(Characteristic.ContactSensorState)
|
|
174
174
|
.onGet(async () => {
|
|
175
|
-
const state =
|
|
175
|
+
const state = port.state;
|
|
176
176
|
return state;
|
|
177
177
|
});
|
|
178
178
|
this.sensorServices.push(sensorService);
|
|
@@ -202,17 +202,15 @@ class SwitchDevice extends EventEmitter {
|
|
|
202
202
|
this.openWrt.on('systemInfo', (info) => {
|
|
203
203
|
this.informationService?.updateCharacteristic(Characteristic.FirmwareRevision, info.release?.version);
|
|
204
204
|
})
|
|
205
|
-
.on('
|
|
205
|
+
.on('switchStatus', async (status) => {
|
|
206
206
|
})
|
|
207
|
-
.on('
|
|
208
|
-
})
|
|
209
|
-
.on('ssids', async (ssids) => {
|
|
207
|
+
.on('switchPorts', async (ports) => {
|
|
210
208
|
// sensors
|
|
211
|
-
for (let i = 0; i <
|
|
212
|
-
const
|
|
209
|
+
for (let i = 0; i < ports.length; i++) {
|
|
210
|
+
const port = ports[i];
|
|
213
211
|
|
|
214
|
-
const name =
|
|
215
|
-
const state =
|
|
212
|
+
const name = port[i].name;
|
|
213
|
+
const state = port[i].state;
|
|
216
214
|
const serviceName = this.accessPoint.namePrefix ? `${this.name} ${name}` : name;
|
|
217
215
|
this.services?.[i]
|
|
218
216
|
?.setCharacteristic(Characteristic.ConfiguredName, serviceName)
|
|
@@ -223,9 +221,9 @@ class SwitchDevice extends EventEmitter {
|
|
|
223
221
|
.updateCharacteristic(Characteristic.ContactSensorState, state ? 0 : 1);
|
|
224
222
|
|
|
225
223
|
if (this.logInfo) {
|
|
226
|
-
this.emit('info', `
|
|
227
|
-
this.emit('info', `Name: ${
|
|
228
|
-
this.emit('info', `Mode: ${
|
|
224
|
+
this.emit('info', `Port name: ${port.name}`);
|
|
225
|
+
this.emit('info', `Name: ${port.state}`);
|
|
226
|
+
this.emit('info', `Mode: ${port.mode}`);
|
|
229
227
|
}
|
|
230
228
|
}
|
|
231
229
|
})
|