Skip to content

Commit

Permalink
Added onoff capability for plan device
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Kling committed May 1, 2023
1 parent 8202c00 commit 5d7694b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/releasenotes/v02-00-03.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
layout: page
title: Release Notes v2.0.3
---

## Fixes
- Add on/off capability for virtual thermostats

## Docs
Compatibility with Homey 3.0 SDK
3 changes: 2 additions & 1 deletion src/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@
"capabilities": [
"target_temperature",
"thermostat_override",
"measure_temperature"
"measure_temperature",
"onoff"
],
"pair": [
{
Expand Down
1 change: 1 addition & 0 deletions src/app/services/homey-api/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum CapabilityType {

// Can not be called mode as this is a standard capability
ThermostatOverride = "thermostat_override",
OnOff = "onoff",
}

export const CLASS_THERMOSTAT: string = "thermostat";
Expand Down
30 changes: 30 additions & 0 deletions src/drivers/virtual-thermostat/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class VirtualThermostat extends Device implements IVirtualThermostat {
this.tryRegisterCapability(CapabilityType.ThermostatOverride,
AsyncDebounce(this.onThermostatModeChanged.bind(this), settings.get<number>(InternalSettings.DriverDebounce, 5 * 1000)));

this.tryRegisterCapability(CapabilityType.OnOff,
AsyncDebounce(this.onOnOff.bind(this), settings.get<number>(InternalSettings.DriverDebounce, 5 * 1000)));

this.repositoryChanged = this.plansChanged.bind(this);
this.capabilitiesChanged = this.capabilititesChanged.bind(this);
this.plansApplied = this.scheduleChanged.bind(this);
Expand All @@ -72,6 +75,7 @@ class VirtualThermostat extends Device implements IVirtualThermostat {
this.plan = await this.repository.find(this.id);
await this.updateCapabilitiesFromPlan();
await this.updateTemperature();
await this.updateOnOffStatus();
}

@trycatchlog(true)
Expand Down Expand Up @@ -110,6 +114,7 @@ class VirtualThermostat extends Device implements IVirtualThermostat {
// must be processed, we don't care
await this.updateCapabilitiesFromPlan();
await this.updateTemperature();
await this.updateOnOffStatus();
}));
}

Expand Down Expand Up @@ -337,6 +342,31 @@ class VirtualThermostat extends Device implements IVirtualThermostat {
this.logger.debug(`we don't have associated devices`);
}
}

/**
* React to a thermostat onoff.
*
* @param value boolean
* @param opts unused
*/
@trycatchlog(true)
private async onOnOff(value: boolean, _opts: any) {
if (this.plan == null) { return; } // should not happen unavailable
this.logger.information(`${CapabilityType.OnOff} ${value}`);

this.plan.enabled = value;
await this.repository.update(this.plan);
}

/**
* Update this device's state
*/
private async updateOnOffStatus() {
if (this.plan == null) { return; }

this.logger.debug(`Updating ${CapabilityType.OnOff} ${this.plan.enabled}`);
await this.doSetCapabilityValue(CapabilityType.OnOff, this.plan.enabled);
}
}

module.exports = VirtualThermostat;
1 change: 1 addition & 0 deletions src/drivers/virtual-thermostat/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class VirtualThermostatsDriver extends Driver {
CapabilityType.TargetTemperature,
CapabilityType.MeasureTemperature,
CapabilityType.ThermostatOverride,
CapabilityType.OnOff,
],
};
});
Expand Down

0 comments on commit 5d7694b

Please sign in to comment.