Skip to content

Commit

Permalink
Use context values re: OpenWonderLabs#779
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlt8 committed Aug 15, 2023
1 parent cab038d commit 3877db4
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/irdevice/airconditioner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,39 +293,35 @@ export class AirConditioner {
}

async CurrentTemperatureGet(): Promise<CharacteristicValue> {
if (this.meter) {
this.CurrentTemperature =
this.meter.context?.CurrentTemperature ||
this.meter.getService(this.platform.Service.TemperatureSensor)?.getCharacteristic(this.platform.Characteristic.CurrentTemperature).value ||
24;
if (this.meter?.context?.CurrentTemperature) {
this.CurrentTemperature = this.meter.context.CurrentTemperature;
this.debugLog(
`${this.device.remoteType}: ${this.accessory.displayName} `
+ `Using CurrentTemperature from ${this.meter.context?.deviceType} (${this.meter.context?.deviceID})`,
+ `Using CurrentTemperature from ${this.meter.context.deviceType} (${this.meter.context.deviceID})`,
);
} else if (this.CurrentTemperature === undefined) {
this.CurrentTemperature = 24;
} else {
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
}
if (this.CurrentTemperature === undefined) {
this.CurrentTemperature = 24;
}
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CurrentTemperature: ${this.CurrentTemperature}`);
return this.CurrentTemperature;
}

async CurrentRelativeHumidityGet(): Promise<CharacteristicValue> {
if (this.meter) {
this.CurrentRelativeHumidity =
this.meter.context?.CurrentRelativeHumidity ||
this.meter.getService(this.platform.Service.HumiditySensor)?.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value ||
0;
if (this.meter?.context?.CurrentRelativeHumidity) {
this.CurrentRelativeHumidity = this.meter.context.CurrentRelativeHumidity;
this.debugLog(
`${this.device.remoteType}: ${this.accessory.displayName} `
+ `Using CurrentRelativeHumidity from ${this.meter.context?.deviceType} (${this.meter.context?.deviceID})`,
+ `Using CurrentRelativeHumidity from ${this.meter.context.deviceType} (${this.meter.context.deviceID})`,
);
} else if (this.CurrentRelativeHumidity === undefined) {
this.CurrentRelativeHumidity = 0;
} else {
this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
}
if (this.CurrentRelativeHumidity === undefined) {
this.CurrentRelativeHumidity = 0;
}
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Get CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
return this.CurrentRelativeHumidity as CharacteristicValue;
}
Expand Down

0 comments on commit 3877db4

Please sign in to comment.