Skip to content

Commit

Permalink
Use built-in "thermostat_mode" for HVAC mode (#158)
Browse files Browse the repository at this point in the history
* [WIP] Switch back from custom hvac_mode (reintroduced in v0.8.0) to built-in "thermostat_mode"

* Deprecate old "hvac_mode" Flow Cards

* Remove not needed properties

* Handle built-in flow cards

* Revert test changes
  • Loading branch information
aivus authored Sep 20, 2024
1 parent 94b9477 commit ff3260d
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 158 deletions.
38 changes: 19 additions & 19 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,113 +17,113 @@ class GreeHVAC extends Homey.App {
this.log('Gree HVAC app is up and running...');

// Register conditions for flows
this._conditionHVACModeIs = this.homey.flow.getConditionCard('hvac_mode_is')
this.homey.flow.getConditionCard('hvac_mode_is')
.registerRunListener((args, state) => {
const hvacMode = args.device.getCapabilityValue('hvac_mode');
const hvacMode = args.device.getCapabilityValue('thermostat_mode');
args.device.log('[condition]', '[current hvac mode]', hvacMode);
return args.mode === hvacMode;
});

this._conditionFanSpeedIs = this.homey.flow.getConditionCard('fan_speed_is')
this.homey.flow.getConditionCard('fan_speed_is')
.registerRunListener((args, state) => {
const fanSpeed = args.device.getCapabilityValue('fan_speed');
args.device.log('[condition]', '[current fan speed]', fanSpeed);
return args.speed === fanSpeed;
});

this._conditionTurboModeIs = this.homey.flow.getConditionCard('turbo_mode_is')
this.homey.flow.getConditionCard('turbo_mode_is')
.registerRunListener((args, state) => {
const turboMode = args.device.getCapabilityValue('turbo_mode');
args.device.log('[condition]', '[current turbo mode]', turboMode);
return onoffToBoolean(args.mode) === turboMode;
});

this._conditionLightsIs = this.homey.flow.getConditionCard('lights_is')
this.homey.flow.getConditionCard('lights_is')
.registerRunListener((args, state) => {
const lightsMode = args.device.getCapabilityValue('lights');
args.device.log('[condition]', '[current lights]', lightsMode);
return onoffToBoolean(args.mode) === lightsMode;
});

this._conditionXFanModeIs = this.homey.flow.getConditionCard('xfan_mode_is')
this.homey.flow.getConditionCard('xfan_mode_is')
.registerRunListener((args, state) => {
const xfanMode = args.device.getCapabilityValue('xfan_mode');
args.device.log('[condition]', '[current xfan mode]', xfanMode);
return onoffToBoolean(args.mode) === xfanMode;
});

this._conditionVerticalSwingIs = this.homey.flow.getConditionCard('vertical_swing_is')
this.homey.flow.getConditionCard('vertical_swing_is')
.registerRunListener((args, state) => {
const verticalSwing = args.device.getCapabilityValue('vertical_swing');
args.device.log('[condition]', '[current swing vertical]', verticalSwing);
return args.vertical_swing === verticalSwing;
});

this._conditionHorizontalSwingIs = this.homey.flow.getConditionCard('horizontal_swing_is')
this.homey.flow.getConditionCard('horizontal_swing_is')
.registerRunListener((args, state) => {
const horizontalSwing = args.device.getCapabilityValue('horizontal_swing');
args.device.log('[condition]', '[current swing horizontal]', horizontalSwing);
return args.horizontal_swing === horizontalSwing;
});

this._conditionQuietModeIs = this.homey.flow.getConditionCard('quiet_mode_is')
this.homey.flow.getConditionCard('quiet_mode_is')
.registerRunListener((args, state) => {
const quietMode = args.device.getCapabilityValue('quiet_mode_is');
args.device.log('[condition]', '[quiet mode]', quietMode);
return args.mode === quietMode;
});

// Register actions for flows
this._actionChangeHVACMode = this.homey.flow.getActionCard('set_hvac_mode')
this.homey.flow.getActionCard('set_hvac_mode')
.registerRunListener((args, state) => {
return args.device.setCapabilityValue('hvac_mode', args.mode).then(() => {
return args.device.triggerCapabilityListener('hvac_mode', args.mode, {});
return args.device.setCapabilityValue('thermostat_mode', args.mode).then(() => {
return args.device.triggerCapabilityListener('thermostat_mode', args.mode, {});
});
});

this._actionChangeFanSpeed = this.homey.flow.getActionCard('set_fan_speed')
this.homey.flow.getActionCard('set_fan_speed')
.registerRunListener((args, state) => {
return args.device.setCapabilityValue('fan_speed', args.speed).then(() => {
return args.device.triggerCapabilityListener('fan_speed', args.speed, {});
});
});

this._actionChangeTurboMode = this.homey.flow.getActionCard('set_turbo_mode')
this.homey.flow.getActionCard('set_turbo_mode')
.registerRunListener((args, state) => {
return args.device.setCapabilityValue('turbo_mode', onoffToBoolean(args.mode)).then(() => {
return args.device.triggerCapabilityListener('turbo_mode', onoffToBoolean(args.mode), {});
});
});

this._actionChangeLights = this.homey.flow.getActionCard('set_lights')
this.homey.flow.getActionCard('set_lights')
.registerRunListener((args, state) => {
return args.device.setCapabilityValue('lights', onoffToBoolean(args.mode)).then(() => {
return args.device.triggerCapabilityListener('lights', onoffToBoolean(args.mode), {});
});
});

this._actionChangeXFanMode = this.homey.flow.getActionCard('set_xfan_mode')
this.homey.flow.getActionCard('set_xfan_mode')
.registerRunListener((args, state) => {
return args.device.setCapabilityValue('xfan_mode', onoffToBoolean(args.mode)).then(() => {
return args.device.triggerCapabilityListener('xfan_mode', onoffToBoolean(args.mode), {});
});
});

this._actionChangeVerticalSwing = this.homey.flow.getActionCard('set_vertical_swing')
this.homey.flow.getActionCard('set_vertical_swing')
.registerRunListener((args, state) => {
return args.device.setCapabilityValue('vertical_swing', args.vertical_swing).then(() => {
return args.device.triggerCapabilityListener('vertical_swing', args.vertical_swing, {});
});
});

this._actionChangeHorizontalSwing = this.homey.flow.getActionCard('set_horizontal_swing')
this.homey.flow.getActionCard('set_horizontal_swing')
.registerRunListener((args, state) => {
return args.device.setCapabilityValue('horizontal_swing', args.horizontal_swing).then(() => {
return args.device.triggerCapabilityListener('horizontal_swing', args.horizontal_swing, {});
});
});

this._actionChangeQuietMode = this.homey.flow.getActionCard('set_quiet_mode')
this.homey.flow.getActionCard('set_quiet_mode')
.registerRunListener((args, state) => {
return args.device.setCapabilityValue('quiet_mode', args.mode).then(() => {
return args.device.triggerCapabilityListener('quiet_mode', args.mode, {});
Expand Down
115 changes: 54 additions & 61 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "com.gree",
"version": "0.8.0",
"compatibility": ">=5.0.0",
"version": "0.8.1",
"compatibility": ">=12.0.1",
"sdk": 3,
"brandColor": "#ff732e",
"name": {
Expand Down Expand Up @@ -90,6 +90,7 @@
},
{
"id": "hvac_mode_changed",
"deprecated": true,
"title": {
"en": "HVAC mode changed"
},
Expand Down Expand Up @@ -267,6 +268,7 @@
"conditions": [
{
"id": "hvac_mode_is",
"deprecated": true,
"title": {
"en": "Current HVAC mode !{{is|isn't}} ..."
},
Expand Down Expand Up @@ -765,6 +767,7 @@
"actions": [
{
"id": "set_hvac_mode",
"deprecated": true,
"title": {
"en": "Set HVAC mode",
"nl": "Stel de HVAC-modus in",
Expand Down Expand Up @@ -1254,64 +1257,6 @@
]
},
"capabilities": {
"hvac_mode": {
"type": "enum",
"title": {
"en": "HVAC mode",
"nl": "HVAC modus",
"de": "HVAC-Modus"
},
"desc": {
"en": "Mode of the HVAC",
"nl": "Modus van de HVAC",
"de": "Modus der HVAC"
},
"values": [
{
"id": "auto",
"title": {
"en": "Auto",
"nl": "Automatisch",
"de": "Automatisch"
}
},
{
"id": "cool",
"title": {
"en": "Cool",
"nl": "Koelen",
"de": "Kühlen"
}
},
{
"id": "heat",
"title": {
"en": "Heat",
"nl": "Verwarmen",
"de": "Heizen"
}
},
{
"id": "dry",
"title": {
"en": "Dry",
"nl": "Ontvochtigen",
"de": "Trocken"
}
},
{
"id": "fan_only",
"title": {
"en": "Fan Only",
"nl": "Alleen fans",
"de": "Nur Fan"
}
}
],
"getable": true,
"setable": true,
"uiComponent": "picker"
},
"fan_speed": {
"type": "enum",
"title": {
Expand Down Expand Up @@ -1669,7 +1614,6 @@
"measure_temperature",
"target_temperature",
"thermostat_mode",
"hvac_mode",
"fan_speed",
"turbo_mode",
"lights",
Expand All @@ -1683,6 +1627,55 @@
"min": 16,
"max": 30,
"step": 1
},
"thermostat_mode": {
"title": {
"en": "HVAC mode",
"nl": "HVAC modus",
"de": "HVAC-Modus"
},
"values": [
{
"id": "auto",
"title": {
"en": "Auto",
"nl": "Automatisch",
"de": "Automatisch"
}
},
{
"id": "cool",
"title": {
"en": "Cool",
"nl": "Koelen",
"de": "Kühlen"
}
},
{
"id": "heat",
"title": {
"en": "Heat",
"nl": "Verwarmen",
"de": "Heizen"
}
},
{
"id": "dry",
"title": {
"en": "Dry",
"nl": "Ontvochtigen",
"de": "Trocken"
}
},
{
"id": "fan_only",
"title": {
"en": "Fan Only",
"nl": "Alleen fans",
"de": "Nur Fan"
}
}
]
}
},
"pair": [
Expand Down
Loading

0 comments on commit ff3260d

Please sign in to comment.