Skip to content

Commit

Permalink
Handle built-in flow cards
Browse files Browse the repository at this point in the history
  • Loading branch information
aivus committed Sep 19, 2024
1 parent 3f11737 commit 1abb6f0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
7 changes: 0 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ class GreeHVAC extends Homey.App {
return args.mode === hvacMode;
});

this.homey.flow.getConditionCard('thermostat_mode_is')
.registerRunListener((args, state) => {
const hvacMode = args.device.getCapabilityValue('thermostat_mode');
args.device.log('[condition]', '[current thermostat mode]', hvacMode);
return args.thermostat_mode === hvacMode;
});

this.homey.flow.getConditionCard('fan_speed_is')
.registerRunListener((args, state) => {
const fanSpeed = args.device.getCapabilityValue('fan_speed');
Expand Down
16 changes: 8 additions & 8 deletions drivers/gree_cooper_hunter_hvac/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,24 +278,24 @@ class GreeHVACDevice extends Homey.Device {
}

if (this._checkBoolPropertyChanged(updatedProperties, HVAC.PROPERTY.power, 'onoff')) {
const value = updatedProperties[HVAC.PROPERTY.power] === HVAC.VALUE.power.on;
this.setCapabilityValue('onoff', value).then(() => {
this.log('[update properties]', '[onoff]', value);
const isOn = updatedProperties[HVAC.PROPERTY.power] === HVAC.VALUE.power.on;
this.setCapabilityValue('onoff', isOn).then(() => {
this.log('[update properties]', '[onoff]', isOn);
return Promise.resolve();
}).catch(this.error);

if (!value) {
if (!isOn) {
// Set Homey thermostat mode to Off when turned off.
this.setCapabilityValue('thermostat_mode', 'off').then(() => {
this.log('[update properties]', '[thermostat_mode]', 'off');
}).catch(this.error);
} else {
// Restore Homey thermostat mode when turned on.
const restoredHvacMode = updatedProperties[HVAC.PROPERTY.mode] === undefined ? properties[HVAC.PROPERTY.mode] : updatedProperties[HVAC.PROPERTY.mode];
const thermostatValue = properties[HVAC.PROPERTY.mode];

this.setCapabilityValue('thermostat_mode', restoredHvacMode).then(() => {
this.log('[update properties]', '[thermostat_mode]', restoredHvacMode);
return this._flowTriggerHvacModeChanged.trigger(this, { hvac_mode: restoredHvacMode });
this.setCapabilityValue('thermostat_mode', thermostatValue).then(() => {
this.log('[update properties]', '[thermostat_mode]', thermostatValue);
return this._flowTriggerHvacModeChanged.trigger(this, { hvac_mode: thermostatValue });
}).catch(this.error);
}

Expand Down

0 comments on commit 1abb6f0

Please sign in to comment.