Skip to content

Commit

Permalink
Fix issues with multi system discovery. Improve logging (#7)
Browse files Browse the repository at this point in the history
* Fix issues with multi system discovery. Improve logging
* Update version to v1.1.2
  • Loading branch information
grivkees authored May 23, 2021
1 parent 45ea2f7 commit 77ef287
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Homebridge Carrier Infinity",
"name": "homebridge-carrier-infinity",
"version": "1.1.1",
"version": "1.1.2",
"description": "Standalone homebridge plugin for Carrier Infinity / Bryant Evolution / ICP Brands Ion thermostats.",
"license": "MIT",
"repository": {
Expand Down
14 changes: 5 additions & 9 deletions src/infinityApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,13 @@ export class InfinityEvolutionLocations extends BaseInfinityEvolutionApiModel {
return `/users/${this.InfinityEvolutionApi.username}/locations`;
}

async getSystems(): Promise<Record<string, string>> {
async getSystems(): Promise<string[]> {
await this.fetch();
const systems = {};
const locations = this.data_object.locations.location;
for (const i in locations) {
const locaton = locations[i];
for (const j in locaton.systems) {
const system = locaton.systems[j].system[0];
const systems: string[] = [];
for (const location of this.data_object.locations.location) {
for (const system of location.systems[0].system) {
const linkparts = system['atom:link'][0]['$']['href'].split('/');
const name = system['atom:link'][0]['$']['title'];
systems[name] = linkparts[linkparts.length - 1];
systems.push(linkparts[linkparts.length - 1]);
}
}
return systems;
Expand Down
8 changes: 6 additions & 2 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class CarrierInfinityHomebridgePlatform implements DynamicPlatformPlugin
}

async registerAccessory(serialNumber: string, zone: string): Promise<PlatformAccessory> {
this.log.info(`Discovered device serial:${serialNumber} zone:${zone}`);
let is_new = false;
const uuid = this.api.hap.uuid.generate(`${serialNumber}:${zone}`);
let accessory = this.accessories.find(accessory => accessory.UUID === uuid);
Expand All @@ -76,16 +77,19 @@ export class CarrierInfinityHomebridgePlatform implements DynamicPlatformPlugin
async discoverDevices(): Promise<void> {
const systems = await new InfinityEvolutionLocations(this.InfinityEvolutionApi).getSystems();
const accessories: PlatformAccessory[] = [];
for (const name in systems) {
const serialNumber = systems[name];
for (const serialNumber of systems) {
const zones = await new InfinityEvolutionSystemProfile(this.InfinityEvolutionApi, serialNumber).getZones();
// TODO: messed up here. This is the zone index, not the zone id. index = id - 1
for (const zone in zones) {
accessories.push(await this.registerAccessory(serialNumber, zone));
}
}
const old_accessories = this.accessories.filter(
accesory => !accessories.includes(accesory),
);
old_accessories.forEach(accessory => {
this.log.info(`Removing old device serial:${accessory.context.serialNumber} zone:${accessory.context.zone}`);
});
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, old_accessories);
}
}

0 comments on commit 77ef287

Please sign in to comment.