diff --git a/docs/releasenotes/v02-00-03.md b/docs/releasenotes/v02-00-03.md new file mode 100644 index 00000000..ab970763 --- /dev/null +++ b/docs/releasenotes/v02-00-03.md @@ -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 diff --git a/src/app.json b/src/app.json index e582db6b..f1890c29 100644 --- a/src/app.json +++ b/src/app.json @@ -365,7 +365,8 @@ "capabilities": [ "target_temperature", "thermostat_override", - "measure_temperature" + "measure_temperature", + "onoff" ], "pair": [ { diff --git a/src/app/services/homey-api/declarations.ts b/src/app/services/homey-api/declarations.ts index e2af9ada..454f67b9 100644 --- a/src/app/services/homey-api/declarations.ts +++ b/src/app/services/homey-api/declarations.ts @@ -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"; diff --git a/src/drivers/virtual-thermostat/device.ts b/src/drivers/virtual-thermostat/device.ts index ce97ee6c..cf979e38 100644 --- a/src/drivers/virtual-thermostat/device.ts +++ b/src/drivers/virtual-thermostat/device.ts @@ -59,6 +59,9 @@ class VirtualThermostat extends Device implements IVirtualThermostat { this.tryRegisterCapability(CapabilityType.ThermostatOverride, AsyncDebounce(this.onThermostatModeChanged.bind(this), settings.get(InternalSettings.DriverDebounce, 5 * 1000))); + this.tryRegisterCapability(CapabilityType.OnOff, + AsyncDebounce(this.onOnOff.bind(this), settings.get(InternalSettings.DriverDebounce, 5 * 1000))); + this.repositoryChanged = this.plansChanged.bind(this); this.capabilitiesChanged = this.capabilititesChanged.bind(this); this.plansApplied = this.scheduleChanged.bind(this); @@ -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) @@ -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(); })); } @@ -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; diff --git a/src/drivers/virtual-thermostat/driver.ts b/src/drivers/virtual-thermostat/driver.ts index 741903ec..13a8e0e5 100644 --- a/src/drivers/virtual-thermostat/driver.ts +++ b/src/drivers/virtual-thermostat/driver.ts @@ -36,6 +36,7 @@ class VirtualThermostatsDriver extends Driver { CapabilityType.TargetTemperature, CapabilityType.MeasureTemperature, CapabilityType.ThermostatOverride, + CapabilityType.OnOff, ], }; });