Skip to content

Commit

Permalink
Turn off air-conditioner accessory automatically after onDuration sec…
Browse files Browse the repository at this point in the history
…onds. (#446)

* adds a onDuration of air-conditioner accessory
  • Loading branch information
banboobee authored Feb 9, 2022
1 parent 6a4df81 commit 9b78af3
Show file tree
Hide file tree
Showing 4 changed files with 5,762 additions and 82 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unrelased]
### Security
## [Unreleased]
### Added
- Adds AutoOff support to the AirConditioner accessory (Thanks @banboobee)
- Updated dependencies to remove security vulnerabilities.

## [4.4.8] - 2021-12-08
Expand Down
34 changes: 34 additions & 0 deletions accessories/aircon.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ class AirConAccessory extends BroadlinkRMAccessory {
this.turnOnWhenOffDelayPromise.cancel();
this.turnOnWhenOffDelayPromise = undefined;
}

if (this.autoOffTimeoutPromise) {
this.autoOffTimeoutPromise.cancel();
this.autoOffTimeoutPromise = null;
}
}

updateServiceTargetHeatingCoolingState (value) {
Expand Down Expand Up @@ -215,6 +220,8 @@ class AirConAccessory extends BroadlinkRMAccessory {
await this.performSend(data.off);
}

this.reset();

return;
}

Expand Down Expand Up @@ -269,6 +276,33 @@ class AirConAccessory extends BroadlinkRMAccessory {

serviceManager.refreshCharacteristicUI(Characteristic.CurrentHeatingCoolingState);
serviceManager.refreshCharacteristicUI(Characteristic.TargetHeatingCoolingState);

this.checkAutoOff();
}

async checkAutoOff () {
await catchDelayCancelError(async () => {
const {config, name, data, log} = this;
let {enableAutoOff, onDuration, enableAutoOn, offDuration} = config;
onDuration = onDuration|| 60;
offDuration = offDuration|| 60;

if (enableAutoOn) {
log(`${name} enableAutoOn is not supported.`);
}
if (enableAutoOff && parseInt(onDuration) > 0) {
log(`${name} setTargetHeatingCoolingState: (automatically turn off in ${onDuration} seconds)`);
if (this.autoOffTimeoutPromise) {
this.autoOffTimeoutPromise.cancel();
this.autoOffTimeoutPromise = null;
}
this.autoOffTimeoutPromise = delayForDuration(onDuration);
await this.autoOffTimeoutPromise;
await this.performSend(data.off);
this.updateServiceTargetHeatingCoolingState(this.HeatingCoolingStates.off);
this.updateServiceCurrentHeatingCoolingState(this.HeatingCoolingStates.off);
}
});
}

// Thermostat
Expand Down
Loading

0 comments on commit 9b78af3

Please sign in to comment.