Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use built-in "thermostat_mode" for HVAC mode #158

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GreeHVAC extends Homey.App {
// Register conditions for flows
this._conditionHVACModeIs = 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;
});
Expand Down Expand Up @@ -70,8 +70,8 @@ class GreeHVAC extends Homey.App {
// Register actions for flows
this._actionChangeHVACMode = 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, {});
});
});

Expand Down
116 changes: 53 additions & 63 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"id": "com.gree",
"version": "0.8.0",
"compatibility": ">=5.0.0",
"id": "com.gree.test",
aivus marked this conversation as resolved.
Show resolved Hide resolved
"version": "0.8.1",
"compatibility": ">=12.0.1",
"sdk": 3,
"brandColor": "#ff732e",
"name": {
"en": "Gree"
"en": "Gree (test)"
aivus marked this conversation as resolved.
Show resolved Hide resolved
},
"description": {
"en": "Control your Gree and other EWPE Smart compatible HVAC devices",
Expand Down Expand Up @@ -1254,64 +1254,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 +1611,6 @@
"measure_temperature",
"target_temperature",
"thermostat_mode",
"hvac_mode",
"fan_speed",
"turbo_mode",
"lights",
Expand All @@ -1683,6 +1624,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
100 changes: 35 additions & 65 deletions drivers/gree_cooper_hunter_hvac/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GreeHVACDevice extends Homey.Device {
await this._executeCapabilityMigrations();
this._registerCapabilityListeners();

this._markOffline();
// this._markOffline();
aivus marked this conversation as resolved.
Show resolved Hide resolved
this._startLookingForDevice();
}

Expand Down Expand Up @@ -154,7 +154,6 @@ class GreeHVACDevice extends Homey.Device {
const rawValue = HVAC.VALUE.mode[value];
this.log('[thermostat_mode change]', `Value: ${value}`, `Raw value: ${rawValue}`);
this._setClientProperty(HVAC.PROPERTY.mode, rawValue);
this.setCapabilityValue('hvac_mode', rawValue);

// Turn on if needed.
const properties = this._client._transformer.fromVendor(this._client._properties);
Expand All @@ -167,27 +166,6 @@ class GreeHVACDevice extends Homey.Device {
return Promise.resolve();
});

this.registerCapabilityListener('hvac_mode', (value) => {
let rawValue = HVAC.VALUE.mode[value];
this.log('[hvac_mode change]', `Value: ${value}`, `Raw value: ${rawValue}`);
this._setClientProperty(HVAC.PROPERTY.mode, rawValue);
this._flowTriggerHvacModeChanged.trigger(this, { hvac_mode: rawValue });

// Update thermostat_mode when on
if (this.getCapabilityValue('onoff') === true) {
// Homey doesn't support fan_only or dry
if (rawValue === 'fan_only') {
rawValue = 'off';
} else if (value === 'dry') {
rawValue = 'cool';
}

this.setCapabilityValue('thermostat_mode', rawValue);
}

return Promise.resolve();
});

this.registerCapabilityListener('fan_speed', (value) => {
const rawValue = HVAC.VALUE.fanSpeed[value];
this.log('[fan speed change]', `Value: ${value}`, `Raw value: ${rawValue}`);
Expand Down Expand Up @@ -313,22 +291,11 @@ class GreeHVACDevice extends Homey.Device {
}).catch(this.error);
} else {
// Restore Homey thermostat mode when turned on.
let restoredHvacMode = updatedProperties[HVAC.PROPERTY.mode] === undefined ? properties[HVAC.PROPERTY.mode] : updatedProperties[HVAC.PROPERTY.mode];

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

// Homey thermostat doesn't support fan_only or dry
if (restoredHvacMode === 'fan_only') {
restoredHvacMode = 'off';
} else if (restoredHvacMode === 'dry') {
restoredHvacMode = 'cool';
}
const restoredHvacMode = updatedProperties[HVAC.PROPERTY.mode] === undefined ? properties[HVAC.PROPERTY.mode] : updatedProperties[HVAC.PROPERTY.mode];

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

Expand Down Expand Up @@ -357,9 +324,7 @@ class GreeHVACDevice extends Homey.Device {
}).catch(this.error);
}

if (this._checkPropertyChanged(updatedProperties, HVAC.PROPERTY.mode, 'hvac_mode')) {
const value = updatedProperties[HVAC.PROPERTY.mode];

if (this._checkPropertyChanged(updatedProperties, HVAC.PROPERTY.mode, 'thermostat_mode')) {
// Update thermostat_mode
if (properties[HVAC.PROPERTY.power] === HVAC.VALUE.power.off) {
// When HVAC is off, thermostat_mode should be always "off".
Expand All @@ -369,24 +334,13 @@ class GreeHVACDevice extends Homey.Device {
}).catch(this.error);
}
} else {
let thermostatValue = updatedProperties[HVAC.PROPERTY.mode];

// Homey doesn't support fan_only or dry
if (thermostatValue === 'fan_only') {
thermostatValue = 'off';
} else if (value === 'dry') {
thermostatValue = 'cool';
}
const thermostatValue = updatedProperties[HVAC.PROPERTY.mode];

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

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

if (this._checkPropertyChanged(updatedProperties, HVAC.PROPERTY.fanSpeed, 'fan_speed')) {
Expand Down Expand Up @@ -594,55 +548,71 @@ class GreeHVACDevice extends Homey.Device {
async _executeCapabilityMigrations() {
// Added in v0.2.1
if (!this.hasCapability('turbo_mode')) {
this.log('[migration]', 'Adding "turbo_mode" capability');
this.log('[migration v0.2.1]', 'Adding "turbo_mode" capability');
await this.addCapability('turbo_mode');
}

// Added in v0.2.1
if (!this.hasCapability('lights')) {
this.log('[migration]', 'Adding "lights" capability');
this.log('[migration v0.2.1]', 'Adding "lights" capability');
await this.addCapability('lights');
}

// Added in v0.3.0
if (!this.hasCapability('xfan_mode')) {
this.log('[migration]', 'Adding "xfan_mode" capability');
this.log('[migration v0.3.0]', 'Adding "xfan_mode" capability');
await this.addCapability('xfan_mode');
}

// Added in v0.3.0
if (!this.hasCapability('vertical_swing')) {
this.log('[migration]', 'Adding "vertical_swing" capability');
this.log('[migration v0.3.0]', 'Adding "vertical_swing" capability');
await this.addCapability('vertical_swing');
}

// Added in v0.4.0
if (!this.hasCapability('measure_temperature')) {
this.log('[migration]', 'Adding "measure_temperature" capability');
this.log('[migration v0.4.0]', 'Adding "measure_temperature" capability');
await this.addCapability('measure_temperature');
}

// Added in v0.5.0
if (!this.hasCapability('thermostat_mode') && this.hasCapability('hvac_mode')) {
this.log('[migration]', 'Converting "hvac_mode" to "thermostat_mode"');
this.log('[migration v0.5.0]', 'Converting "hvac_mode" to "thermostat_mode"');
await this.removeCapability('hvac_mode');
await this.addCapability('thermostat_mode');
}

// Added in v0.8.0
// Added in v0.8.0 (test)
if (!this.hasCapability('horizontal_swing')) {
this.log('[migration]', 'Adding "horizontal_swing" capability');
this.log('[migration v0.8.0]', 'Adding "horizontal_swing" capability');
await this.addCapability('horizontal_swing');
}

if (!this.hasCapability('quiet_mode')) {
this.log('[migration]', 'Adding "quiet_mode" capability');
this.log('[migration v0.8.0]', 'Adding "quiet_mode" capability');
await this.addCapability('quiet_mode');
}

if (!this.hasCapability('hvac_mode')) {
this.log('[migration]', 'Adding "hvac_mode" capability');
await this.addCapability('hvac_mode');
// Commented in v0.8.1
// if (!this.hasCapability('hvac_mode')) {
// this.log('[migration]', 'Adding "hvac_mode" capability');
// await this.addCapability('hvac_mode');
// }

// Added in v0.8.1
// Revert back from "hvac_mode" to "thermostat_mode"
if (this.hasCapability('hvac_mode')) {
this.log('[migration v0.8.1]', 'Removing "hvac_mode" capability');
await this.removeCapability('hvac_mode');

// Re-add thermostat_mode with new configuration
if (this.hasCapability('thermostat_mode')) {
this.log('[migration v0.8.1]', 'Removing "thermostat_mode" capability');
await this.removeCapability('thermostat_mode');
}

this.log('[migration v0.8.1]', 'Adding "thermostat_mode" capability');
await this.addCapability('thermostat_mode');
}
}

Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading