homebridge-orro 1.0.1 → 1.0.5
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/config.schema.json +39 -24
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +5 -15
- package/dist/platform.js.map +1 -1
- package/dist/platformAccessory.d.ts +1 -6
- package/dist/platformAccessory.d.ts.map +1 -1
- package/dist/platformAccessory.js +72 -51
- package/dist/platformAccessory.js.map +1 -1
- package/package.json +3 -2
package/config.schema.json
CHANGED
|
@@ -2,15 +2,26 @@
|
|
|
2
2
|
"pluginAlias": "Homebridge Orro",
|
|
3
3
|
"pluginType": "platform",
|
|
4
4
|
"singular": true,
|
|
5
|
+
"headerDisplay": "Add one or more switches from your Orro network below",
|
|
5
6
|
"schema": {
|
|
7
|
+
"homeID": {
|
|
8
|
+
"title": "Home ID",
|
|
9
|
+
"type": "string",
|
|
10
|
+
"required": true
|
|
11
|
+
},
|
|
12
|
+
"accessToken": {
|
|
13
|
+
"title": "Offline Access Token",
|
|
14
|
+
"type": "string",
|
|
15
|
+
"required": true
|
|
16
|
+
},
|
|
6
17
|
"switches": {
|
|
7
18
|
"type": "array",
|
|
8
19
|
"items": {
|
|
9
|
-
"title": "
|
|
20
|
+
"title": "Switches",
|
|
10
21
|
"type": "object",
|
|
11
22
|
"properties": {
|
|
12
|
-
"
|
|
13
|
-
"title": "
|
|
23
|
+
"name": {
|
|
24
|
+
"title": "Name",
|
|
14
25
|
"type": "string",
|
|
15
26
|
"required": true
|
|
16
27
|
},
|
|
@@ -28,29 +39,33 @@
|
|
|
28
39
|
"title": "IP Address",
|
|
29
40
|
"type": "string",
|
|
30
41
|
"required": true
|
|
31
|
-
},
|
|
32
|
-
"accessToken": {
|
|
33
|
-
"title": "Offline Access Token",
|
|
34
|
-
"type": "string",
|
|
35
|
-
"required": true
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
44
|
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"layout": [
|
|
48
|
+
{
|
|
49
|
+
"key": "config",
|
|
50
|
+
"type": "section",
|
|
51
|
+
"title": "Configuration",
|
|
52
|
+
"expandable": false,
|
|
53
|
+
"items": [
|
|
54
|
+
"homeID",
|
|
55
|
+
"accessToken"
|
|
56
|
+
]
|
|
39
57
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
]
|
|
55
|
-
}
|
|
58
|
+
{
|
|
59
|
+
"key": "switches",
|
|
60
|
+
"type": "array",
|
|
61
|
+
"orderable": false,
|
|
62
|
+
"buttonText": "Add Switch",
|
|
63
|
+
"items": [
|
|
64
|
+
"switches[].name",
|
|
65
|
+
"switches[].serialNumber",
|
|
66
|
+
"switches[].switchID",
|
|
67
|
+
"switches[].ipAddress"
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
]
|
|
56
71
|
}
|
package/dist/platform.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,qBAAqB,EAAE,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAK5H;;;;EAIE;AACF,qBAAa,YAAa,YAAW,qBAAqB;aAQlC,GAAG,EAAE,MAAM;aACX,MAAM,EAAE,cAAc;aACtB,GAAG,EAAE,GAAG;IAT5B,SAAgB,OAAO,EAAE,OAAO,OAAO,CAAwB;IAC/D,SAAgB,cAAc,EAAE,OAAO,cAAc,CAA+B;IAGpF,SAAgB,WAAW,EAAE,iBAAiB,EAAE,CAAM;gBAGlC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,GAAG;IAe5B;;;MAGE;IACF,kBAAkB,CAAC,SAAS,EAAE,iBAAiB;IAO/C;;;;MAIE;IACF,eAAe;
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,qBAAqB,EAAE,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAK5H;;;;EAIE;AACF,qBAAa,YAAa,YAAW,qBAAqB;aAQlC,GAAG,EAAE,MAAM;aACX,MAAM,EAAE,cAAc;aACtB,GAAG,EAAE,GAAG;IAT5B,SAAgB,OAAO,EAAE,OAAO,OAAO,CAAwB;IAC/D,SAAgB,cAAc,EAAE,OAAO,cAAc,CAA+B;IAGpF,SAAgB,WAAW,EAAE,iBAAiB,EAAE,CAAM;gBAGlC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,GAAG;IAe5B;;;MAGE;IACF,kBAAkB,CAAC,SAAS,EAAE,iBAAiB;IAO/C;;;;MAIE;IACF,eAAe;CAkDlB"}
|
package/dist/platform.js
CHANGED
|
@@ -17,7 +17,7 @@ class OrroPlatform {
|
|
|
17
17
|
this.Characteristic = this.api.hap.Characteristic;
|
|
18
18
|
// this is used to track restored cached accessories
|
|
19
19
|
this.accessories = [];
|
|
20
|
-
this.log.debug('Finished initializing platform:', this.config.
|
|
20
|
+
this.log.debug('Finished initializing platform:', this.config.platform);
|
|
21
21
|
// When this event is fired it means Homebridge has restored all cached accessories from disk.
|
|
22
22
|
// Dynamic Platform plugins should only register new accessories after this event was fired,
|
|
23
23
|
// in order to ensure they weren't added to homebridge already. This event can also be used
|
|
@@ -43,22 +43,12 @@ class OrroPlatform {
|
|
|
43
43
|
* must not be registered again to prevent "duplicate UUID" errors.
|
|
44
44
|
*/
|
|
45
45
|
discoverDevices() {
|
|
46
|
-
// EXAMPLE ONLY
|
|
47
|
-
// A real plugin you would discover accessories from the local network, cloud services
|
|
48
|
-
// or a user-defined array in the platform config.
|
|
49
|
-
const exampleDevices = [{
|
|
50
|
-
exampleUniqueId: 'ABCD',
|
|
51
|
-
exampleDisplayName: 'Bedroom',
|
|
52
|
-
}, {
|
|
53
|
-
exampleUniqueId: 'EFGH',
|
|
54
|
-
exampleDisplayName: 'Kitchen',
|
|
55
|
-
}];
|
|
56
46
|
// loop over the discovered devices and register each one if it has not already been registered
|
|
57
|
-
for (const device of
|
|
47
|
+
for (const device of this.config.switches) {
|
|
58
48
|
// generate a unique id for the accessory this should be generated from
|
|
59
49
|
// something globally unique, but constant, for example, the device serial
|
|
60
50
|
// number or MAC address
|
|
61
|
-
const uuid = this.api.hap.uuid.generate(device.
|
|
51
|
+
const uuid = this.api.hap.uuid.generate(device.serialNumber);
|
|
62
52
|
// see if an accessory with the same uuid has already been registered and restored from
|
|
63
53
|
// the cached devices we stored in the `configureAccessory` method above
|
|
64
54
|
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
|
|
@@ -78,9 +68,9 @@ class OrroPlatform {
|
|
|
78
68
|
}
|
|
79
69
|
else {
|
|
80
70
|
// the accessory does not yet exist, so we need to create it
|
|
81
|
-
this.log.info('Adding new accessory:', device.
|
|
71
|
+
this.log.info('Adding new accessory:', device.name);
|
|
82
72
|
// create a new accessory
|
|
83
|
-
const accessory = new this.api.platformAccessory(device.
|
|
73
|
+
const accessory = new this.api.platformAccessory(device.name, uuid);
|
|
84
74
|
// store a copy of the device object in the `accessory.context`
|
|
85
75
|
// the `context` property can be used to store any data about the accessory you may need
|
|
86
76
|
accessory.context.device = device;
|
package/dist/platform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":";;;AAEA,yCAAwD;AACxD,2DAA6C;AAE7C;;;;EAIE;AACF,MAAa,YAAY;IAOrB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,+DAA+D;gBAC/D,wFAAwF;gBACxF,SAAS,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;gBAElC,8DAA8D;gBAC9D,+CAA+C;gBAC/C,IAAI,0BAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;gBAE5B,sCAAsC;gBACtC,IAAI,CAAC,GAAG,CAAC,2BAA2B,CAAC,sBAAW,EAAE,wBAAa,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;aACjF;SACJ;IACL,CAAC;CACJ;AA3FD,oCA2FC"}
|
|
@@ -15,13 +15,8 @@ export declare class Switch {
|
|
|
15
15
|
*/
|
|
16
16
|
private state;
|
|
17
17
|
private connection;
|
|
18
|
-
private serialNumber;
|
|
19
|
-
private switchIP;
|
|
20
|
-
private switchID;
|
|
21
|
-
private homeID;
|
|
22
|
-
private accessToken;
|
|
23
18
|
constructor(platform: OrroPlatform, accessory: PlatformAccessory);
|
|
24
|
-
|
|
19
|
+
connect: () => Promise<void>;
|
|
25
20
|
/**
|
|
26
21
|
* Handle "SET" requests from HomeKit
|
|
27
22
|
* These are sent when the user changes the state of an accessory, for example, turning on a Light bulb.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platformAccessory.d.ts","sourceRoot":"","sources":["../src/platformAccessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAW,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C;;;;EAIE;AACF,qBAAa,MAAM;
|
|
1
|
+
{"version":3,"file":"platformAccessory.d.ts","sourceRoot":"","sources":["../src/platformAccessory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAW,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C;;;;EAIE;AACF,qBAAa,MAAM;IAeX,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAf9B,OAAO,CAAC,OAAO,CAAU;IAEzB;;;MAGE;IACF,OAAO,CAAC,KAAK,CAGX;IAEF,OAAO,CAAC,UAAU,CAAY;gBAGT,QAAQ,EAAE,YAAY,EACtB,SAAS,EAAE,iBAAiB;IAgCjD,OAAO,sBA0CN;IAED;;;MAGE;IACI,KAAK,CAAC,KAAK,EAAE,mBAAmB;IAoBtC;;;;;;;;;;;;MAYE;IACI,KAAK,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAM3C;;;MAGE;IACI,aAAa,CAAC,KAAK,EAAE,mBAAmB;CAoBjD"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.Switch = void 0;
|
|
4
|
-
const
|
|
7
|
+
const ws_1 = __importDefault(require("ws"));
|
|
5
8
|
/**
|
|
6
9
|
* Platform Accessory
|
|
7
10
|
* An instance of this class is created for each accessory your platform registers
|
|
@@ -19,49 +22,56 @@ class Switch {
|
|
|
19
22
|
On: false,
|
|
20
23
|
Brightness: 100
|
|
21
24
|
};
|
|
22
|
-
this.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (this.connection) {
|
|
29
|
-
resolve(this.connection);
|
|
30
|
-
}
|
|
31
|
-
const client = new websocket_1.client();
|
|
32
|
-
client.connect(`ws://${this.switchIP}:8080/edison/${this.homeID}`, null, null, [{ 'offline-access-token': this.accessToken }]);
|
|
33
|
-
client.on('connect', connection => {
|
|
25
|
+
this.connect = async () => {
|
|
26
|
+
const url = `ws://${this.accessory.context.device.ipAddress}:8080/edison/${this.platform.config.homeID}`;
|
|
27
|
+
this.platform.log.info('Connecting to:', url);
|
|
28
|
+
this.connection = new ws_1.default(url, { headers: { 'offline-access-token': this.accessory.context.device.accessToken } });
|
|
29
|
+
this.connection.on('open', connection => {
|
|
30
|
+
this.platform.log.info(`Connected to ${this.accessory.context.device.name}`);
|
|
34
31
|
// listen for system events
|
|
35
|
-
connection.on('message',
|
|
32
|
+
connection.on('message', response => {
|
|
36
33
|
try {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
const { data } = JSON.parse(response.toString());
|
|
35
|
+
const { dimmerLevel, onOff } = data || {};
|
|
36
|
+
// update on/off state if changed externally
|
|
37
|
+
if (typeof (onOff) === 'boolean' && onOff !== this.state.On) {
|
|
38
|
+
this.platform.log.info(`Updated on to ${onOff ? 'true' : 'false'} from system event`);
|
|
39
|
+
this.state.On = onOff;
|
|
40
|
+
this.service.updateCharacteristic(this.platform.Characteristic.On, onOff);
|
|
41
|
+
}
|
|
42
|
+
// update dimmer level if changed externally
|
|
43
|
+
if (dimmerLevel >= 0 && dimmerLevel !== this.state.Brightness) {
|
|
44
|
+
this.platform.log.info(`Updated brightness to ${dimmerLevel} from system event`);
|
|
45
|
+
this.state.Brightness = dimmerLevel;
|
|
46
|
+
this.service.updateCharacteristic(this.platform.Characteristic.Brightness, dimmerLevel);
|
|
40
47
|
}
|
|
41
48
|
}
|
|
42
49
|
catch (e) {
|
|
43
|
-
this.platform.log.error('Websocket api error:', e.message);
|
|
50
|
+
this.platform.log.error('Websocket api response error:', e.message);
|
|
44
51
|
}
|
|
45
52
|
});
|
|
46
53
|
this.connection = connection;
|
|
47
|
-
resolve(connection);
|
|
48
54
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.
|
|
55
|
+
this.connection.on('disconnect', () => {
|
|
56
|
+
this.platform.log.error(`Disconnected from ${this.accessory.context.device.name}`);
|
|
57
|
+
this.connect();
|
|
58
|
+
});
|
|
59
|
+
this.connection.on('error', error => {
|
|
60
|
+
this.platform.log.error('Websocket api error:', error.message);
|
|
61
|
+
this.connect();
|
|
52
62
|
});
|
|
53
|
-
}
|
|
63
|
+
};
|
|
54
64
|
// set accessory information
|
|
55
65
|
this.accessory.getService(this.platform.Service.AccessoryInformation)
|
|
56
66
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'Orro')
|
|
57
67
|
.setCharacteristic(this.platform.Characteristic.Model, 'Switch')
|
|
58
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber,
|
|
68
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, accessory.context.device.serialNumber);
|
|
59
69
|
// get the LightBulb service if it exists, otherwise create a new LightBulb service
|
|
60
70
|
// you can create multiple services for each accessory
|
|
61
71
|
this.service = this.accessory.getService(this.platform.Service.Lightbulb) || this.accessory.addService(this.platform.Service.Lightbulb);
|
|
62
72
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
63
73
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
64
|
-
this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.
|
|
74
|
+
this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.context.device.name);
|
|
65
75
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
66
76
|
// see https://developers.homebridge.io/#/service/Lightbulb
|
|
67
77
|
// register handlers for the On/Off Characteristic
|
|
@@ -71,24 +81,30 @@ class Switch {
|
|
|
71
81
|
// register handlers for the Brightness Characteristic
|
|
72
82
|
this.service.getCharacteristic(this.platform.Characteristic.Brightness)
|
|
73
83
|
.onSet(this.setBrightness.bind(this)); // SET - bind to the 'setBrightness` method below
|
|
84
|
+
this.connect();
|
|
74
85
|
}
|
|
75
86
|
/**
|
|
76
87
|
* Handle "SET" requests from HomeKit
|
|
77
88
|
* These are sent when the user changes the state of an accessory, for example, turning on a Light bulb.
|
|
78
89
|
*/
|
|
79
90
|
async setOn(value) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
try {
|
|
92
|
+
const payload = JSON.stringify({
|
|
93
|
+
targetId: this.accessory.context.device.switchID,
|
|
94
|
+
clientId: 'homebridge-orro',
|
|
95
|
+
type: 'RemoteCommand',
|
|
96
|
+
timestamp: Date.now(),
|
|
97
|
+
data: {
|
|
98
|
+
command: value ? 'on' : 'off'
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
this.connection.send(payload);
|
|
102
|
+
this.state.On = value;
|
|
103
|
+
this.platform.log.info('Set Characteristic On ->', value);
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
this.platform.log.error('Set Characteristic On Error -> ', e.message);
|
|
107
|
+
}
|
|
92
108
|
}
|
|
93
109
|
/**
|
|
94
110
|
* Handle the "GET" requests from HomeKit
|
|
@@ -105,7 +121,7 @@ class Switch {
|
|
|
105
121
|
*/
|
|
106
122
|
async getOn() {
|
|
107
123
|
const isOn = this.state.On;
|
|
108
|
-
this.platform.log.
|
|
124
|
+
this.platform.log.info('Get Characteristic On ->', isOn);
|
|
109
125
|
return isOn;
|
|
110
126
|
}
|
|
111
127
|
/**
|
|
@@ -113,19 +129,24 @@ class Switch {
|
|
|
113
129
|
* These are sent when the user changes the state of an accessory, for example, changing the Brightness
|
|
114
130
|
*/
|
|
115
131
|
async setBrightness(value) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
132
|
+
try {
|
|
133
|
+
const payload = JSON.stringify({
|
|
134
|
+
targetId: this.accessory.context.device.switchID,
|
|
135
|
+
clientId: 'homebridge-orro',
|
|
136
|
+
type: 'RemoteCommand',
|
|
137
|
+
timestamp: Date.now(),
|
|
138
|
+
data: {
|
|
139
|
+
command: 'dimmer_set',
|
|
140
|
+
value: value
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
this.connection.send(payload);
|
|
144
|
+
this.state.Brightness = value;
|
|
145
|
+
this.platform.log.info('Set Characteristic Brightness -> ', value);
|
|
146
|
+
}
|
|
147
|
+
catch (e) {
|
|
148
|
+
this.platform.log.error('Set Characteristic Brightness Error -> ', e.message);
|
|
149
|
+
}
|
|
129
150
|
}
|
|
130
151
|
}
|
|
131
152
|
exports.Switch = Switch;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platformAccessory.js","sourceRoot":"","sources":["../src/platformAccessory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"platformAccessory.js","sourceRoot":"","sources":["../src/platformAccessory.ts"],"names":[],"mappings":";;;;;;AAEA,4CAA2B;AAE3B;;;;EAIE;AACF,MAAa,MAAM;IAcf,YACqB,QAAsB,EACtB,SAA4B;QAD5B,aAAQ,GAAR,QAAQ,CAAc;QACtB,cAAS,GAAT,SAAS,CAAmB;QAbjD;;;UAGE;QACM,UAAK,GAAG;YACZ,EAAE,EAAE,KAAK;YACT,UAAU,EAAE,GAAG;SAClB,CAAC;QAsCF,YAAO,GAAG,KAAK,IAAI,EAAE;YAEjB,MAAM,GAAG,GAAG,QAAQ,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,gBAAgB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACzG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;YAC9C,IAAI,CAAC,UAAU,GAAG,IAAI,YAAS,CAAC,GAAG,EAAE,EAAE,OAAO,EAAG,EAAE,sBAAsB,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YAC1H,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,MAAM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,CAAC,CAAC;SAEtE;QAAC,OAAM,CAAC,EAAE;YACP,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,yCAAyC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;SACjF;IACL,CAAC;CACJ;AA/JD,wBA+JC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "Homebridge Orro",
|
|
3
3
|
"name": "homebridge-orro",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.5",
|
|
5
5
|
"description": "Homebridge support for Orro lan switches.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"typescript": "^4.2.2"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"websocket": "^1.0.34"
|
|
40
|
+
"websocket": "^1.0.34",
|
|
41
|
+
"ws": "^8.4.0"
|
|
41
42
|
}
|
|
42
43
|
}
|