Skip to content

Commit

Permalink
listen to zone events
Browse files Browse the repository at this point in the history
  • Loading branch information
harriedegroot committed Jan 27, 2019
1 parent 4e01038 commit ee4ec87
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions DeviceManager.js
Expand Up @@ -105,6 +105,10 @@ class DeviceManager {
this.api.devices.on('device.delete', this._removeDevice.bind(this));
this.api.devices.on('device.update', this._updateDevice.bind(this));

this.api.zones.on('zones.create', this._addZone.bind(this));
this.api.zones.on('zones.delete', this._removeZone.bind(this));
this.api.zones.on('zones.update', this._updateZone.bind(this));

this.devices = await this.api.devices.getDevices();
this.zones = await this.api.zones.getZones();

Expand Down Expand Up @@ -202,6 +206,27 @@ class DeviceManager {
await this.onUpdate.emit(id);
}

async _addZone(id) {
Log.info('New zone found!');
if (id) {
this.zones = this.zones || {};
const zone = await this.api.zones.getZone({ id });
if (zone) {
this.zones[id] = zone;
}
}
}

async _removeZone(id) {
if (id && this.zones && this.zones.hasOwnProperty(id)) {
delete this.zones[id];
}
}

async _updateZone(id) {
await this._addZone(id);
}

async getCapabillities(device) {
device = await this.getDevice(device);
return device ? device.capabilitiesObj || device.capabilities : undefined; // 1.5.13 vs 2.0
Expand Down

0 comments on commit ee4ec87

Please sign in to comment.