Skip to content

Commit

Permalink
fix: Remaining durations large then 1h
Browse files Browse the repository at this point in the history
  • Loading branch information
QuickSander committed Mar 10, 2021
1 parent 0e99db1 commit 823e2f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ finer grained (per specific device type instead of per group of device types).

Washer Dryer / Washer / Dishwasher:
- HomeKit does not support a washer dryer, washing machine, tuble dryer or dish washer. It will be emulated as a valve.
- A HomeKit valve has a maximum remaining duration of 3600 seconds. The washing machine's remaining duration will thus only reflect the real
remaining duration as reported by your Miele device when the duration decreases to a value less than 3600 seconds.
- A HomeKit valve can be turned on and off, however Miele's 3rd party Web API does not always allow you to turn on or off the washing
machine. Flipping the switch when not allowed will revert the switch state when it is not allowed.

Expand Down
25 changes: 17 additions & 8 deletions src/mieleCharacteristics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export class MieleTargetCoolingCharacteristic extends MieleWritableBinaryStateCh
//-------------------------------------------------------------------------------------------------
export class MieleRemainingDurationCharacteristic extends MieleReadOnlyCharacteristic {

private readonly MAX_HOMEKIT_DURATION_S = 3600;
//private readonly MAX_HOMEKIT_DURATION_S = 3600;

constructor(
protected platform: MieleAtHomePlatform,
Expand All @@ -284,8 +284,15 @@ export class MieleRemainingDurationCharacteristic extends MieleReadOnlyCharacter
this.value = response.remainingTime[0]*3600 + response.remainingTime[1]*60;
this.platform.log.debug('Parsed Remaining Duration from API response:', this.value, '[s]');

this.value = this.value > this.MAX_HOMEKIT_DURATION_S ? this.MAX_HOMEKIT_DURATION_S : this.value;
this.value = this.value < 0 ? 0 : this.value;
// Clip to min and max value.
const characteristic = this.service.getCharacteristic(this.platform.Characteristic.RemainingDuration);
const maxValue = characteristic.props.maxValue;
const minValue = characteristic.props.minValue;

if(maxValue && minValue) {
this.value = this.value > maxValue ? maxValue : this.value;
this.value = this.value < minValue ? minValue : this.value;
}

this.service.updateCharacteristic(this.platform.Characteristic.RemainingDuration, this.value);
}
Expand All @@ -304,21 +311,21 @@ export class MieleTempCharacteristic extends MieleReadOnlyCharacteristic {
private readonly NULL_VALUE = 2**16/-2;
private readonly TEMP_CONVERSION_FACTOR = 100.0;
protected readonly DEFAULT_ZONE = 1; // Currently only 1 temperature zone supported.
static readonly OFF_TEMP = 1;

constructor(
platform: MieleAtHomePlatform,
service: Service,
protected type: TemperatureType,
protected type: TemperatureType,
private offTemp: number,
) {
super(platform, service, MieleTempCharacteristic.OFF_TEMP);
super(platform, service, offTemp);
}

//-------------------------------------------------------------------------------------------------
update(response: MieleStatusResponse): void {
let tempArray: MieleStatusResponseTemp[];
let characteristic;
let value = MieleTempCharacteristic.OFF_TEMP; // Set target temperature to 1 when no target temperature available since device is off.
let value = this.offTemp; // Set target temperature to 'off' when no target temperature available since device is off.

switch(this.type) {
case TemperatureType.Target:
Expand Down Expand Up @@ -363,8 +370,9 @@ export class MieleTargetTempCharacteristic extends MieleTempCharacteristic {
platform: MieleAtHomePlatform,
service: Service,
private serialNumber: string,
offTemp: number,
) {
super(platform, service, TemperatureType.Target);
super(platform, service, TemperatureType.Target, offTemp);
}

//-------------------------------------------------------------------------------------------------
Expand All @@ -388,6 +396,7 @@ export class MieleTargetTempCharacteristic extends MieleTempCharacteristic {
'Device most probably still acknowlegded (known Miele API misbehaviour).');
} else {
this.platform.log.error( createErrorString(response) );
// TODO: This characteristic needs to be added first.
this.service.setCharacteristic(this.platform.Characteristic.StatusFault, this.platform.Characteristic.StatusFault.GENERAL_FAULT);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/mieleWasherDryerPlatformAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { MieleActiveCharacteristic, MieleInUseCharacteristic, MieleRemainingDura
//-------------------------------------------------------------------------------------------------
export class MieleWasherDryerPlatformAccessory extends MieleBasePlatformAccessory {
private tempService: Service | undefined;
private readonly MAX_REMAINING_DURATION = 8*3600;

//-----------------------------------------------------------------------------------------------
constructor(
Expand Down Expand Up @@ -55,7 +56,7 @@ export class MieleWasherDryerPlatformAccessory extends MieleBasePlatformAccessor
.on('get', this.getGeneric.bind(this, remainingDurationCharacteristic))
.setProps({
minValue: 0,
maxValue: 8*3600,
maxValue: this.MAX_REMAINING_DURATION,
minStep: 1,
});

Expand Down

0 comments on commit 823e2f5

Please sign in to comment.