Skip to content

Commit

Permalink
Merge pull request #98 from Jason-Morcos/fix/Preserve-override-addres…
Browse files Browse the repository at this point in the history
…s-between-API-refreshes

Fix Preserve override address between API refreshes
  • Loading branch information
fjs21 authored Nov 5, 2023
2 parents b295fe1 + d18049d commit e748ef4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/kumo-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export class KumoApi {
serial: serial,
label: zoneTable[serial].label,
zoneTable: zoneTable[serial],
overrideAddress: null,
};
let existingDeviceIndex: string|number|undefined = undefined;
for (const anExistingDeviceIndex in this.devices) {
Expand Down Expand Up @@ -436,12 +437,14 @@ export class KumoApi {
// sends request
private async directRequest(post_data: string, serial: string, attempt_number = 0) {
let zoneTable;
let overrideAddress;
for (const device of this.devices) {
if (device.serial === serial){
zoneTable = device.zoneTable;
overrideAddress = device.overrideAddress;
}
}
const address: string = zoneTable.address;
const address: string = overrideAddress ?? zoneTable.address;
const cryptoSerial: string = zoneTable.cryptoSerial;
const password: string = zoneTable.password;

Expand Down
8 changes: 4 additions & 4 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ export class KumoHomebridgePlatform implements DynamicPlatformPlugin {
const overrideAddress = this.optionGetOverrideAddress(device);
if (overrideAddress !== null) {
this.log.info('Override address found for device - using IP %s instead of %s for direct access', overrideAddress, existingAccessory.context.zoneTable.address);
existingAccessory.context.zoneTable.address = overrideAddress;
existingAccessory.context.overrideAddress = overrideAddress;
}

this.log.debug(device.zoneTable);

if (this.config.directAccess) {
existingAccessory.context.device = await this.kumo.queryDevice_Direct(device.serial);
if(existingAccessory.context.device === null) {
this.log.error('Failed to connect to device IP (%s) at %s', device.serial, existingAccessory.context.zoneTable.address);
this.log.error('Failed to connect to device IP (%s) at %s', device.serial, existingAccessory.context.overrideAddress ?? existingAccessory.context.zoneTable.address);
existingAccessory.context.device = await this.kumo.queryDevice(device.serial);
this.config.directAccess = false;
this.log.info('Disabling directAccess to Kumo devices');
Expand Down Expand Up @@ -185,15 +185,15 @@ export class KumoHomebridgePlatform implements DynamicPlatformPlugin {
const overrideAddress = this.optionGetOverrideAddress(device);
if (overrideAddress !== null) {
this.log.info('Override address found for device - using IP %s instead of %s for direct access', overrideAddress, accessory.context.zoneTable.address);
accessory.context.zoneTable.address = overrideAddress;
accessory.context.overrideAddress = overrideAddress;
}

this.log.debug(device.zoneTable);

if (this.config.directAccess) {
accessory.context.device = await this.kumo.queryDevice_Direct(device.serial);
if(accessory.context.device === null) {
this.log.error('Failed to connect to device IP (%s) at %s', device.serial, accessory.context.zoneTable.address);
this.log.error('Failed to connect to device IP (%s) at %s', device.serial, accessory.context.overrideAddress ?? accessory.context.zoneTable.address);
this.config.directAccess = false;
this.log.info('Disabling directAccess to Kumo devices');
accessory.context.device = await this.kumo.queryDevice(device.serial);
Expand Down

0 comments on commit e748ef4

Please sign in to comment.