Skip to content

Commit

Permalink
[skip ci] Show and process alive state.
Browse files Browse the repository at this point in the history
  • Loading branch information
XHunter74 committed Apr 23, 2024
1 parent 6546c0a commit 4028f79
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class GreeHvac extends utils.Adapter {
if (!this.config.devicelist || this.config.devicelist.length === 0 || !this.validateIPList(this.config.devicelist)) {
this.log.error(`Invalid device list: ${JSON.stringify(this.config.devicelist)}`);
await this.stop();
return
return;
}

if (this.config.pollInterval < MinPollInterval || isNaN(this.config.pollInterval) || this.config.pollInterval > MaxPollInterval) {
Expand Down Expand Up @@ -337,14 +337,16 @@ class GreeHvac extends utils.Adapter {
const deviceId = obj.message.deviceId;
let state;
const powerState = (await this.getStateAsync(`${deviceId}.power`)).val;
const isAlive = (await this.getStateAsync(`${deviceId}.alive`)).val;
let newState;
switch (command) {
case 'on-off-btn':
if (isAlive === false) return;
newState = powerState === 1 ? 0 : 1;
await this.setStateAsync(`${deviceId}.power`, newState);
break;
case 'temperature-up-btn':
if (powerState === 0) return;
if (powerState === 0 || isAlive === false) return;
state = (await this.getStateAsync(`${deviceId}.target-temperature`)).val;
newState = Number(state) + 1;
if (newState > 30) {
Expand All @@ -353,7 +355,7 @@ class GreeHvac extends utils.Adapter {
await this.setStateAsync(`${deviceId}.target-temperature`, newState);
break;
case 'temperature-down-btn':
if (powerState === 0) return;
if (powerState === 0 || isAlive === false) return;
state = (await this.getStateAsync(`${deviceId}.target-temperature`)).val;
newState = Number(state) - 1;
if (newState < 16) {
Expand All @@ -362,7 +364,7 @@ class GreeHvac extends utils.Adapter {
await this.setStateAsync(`${deviceId}.target-temperature`, newState);
break;
case 'mode-btn':
if (powerState === 0) return;
if (powerState === 0 || isAlive === false) return;
state = (await this.getStateAsync(`${deviceId}.mode`)).val;
newState = Number(state) + 1;
if (newState > 4) {
Expand All @@ -371,7 +373,7 @@ class GreeHvac extends utils.Adapter {
await this.setStateAsync(`${deviceId}.mode`, newState);
break;
case 'fan-btn':
if (powerState === 0) return;
if (powerState === 0 || isAlive === false) return;
const fan_speeds = [0, 1, 3, 5]; // eslint-disable-line no-case-declarations
state = (await this.getStateAsync(`${deviceId}.fan-speed`)).val;
let idx = fan_speeds.indexOf(Number(state)); // eslint-disable-line no-case-declarations
Expand All @@ -381,7 +383,7 @@ class GreeHvac extends utils.Adapter {
await this.setStateAsync(`${deviceId}.fan-speed`, newState);
break;
case 'turbo-btn':
if (powerState === 0) return;
if (powerState === 0 || isAlive === false) return;
state = (await this.getStateAsync(`${deviceId}.turbo`)).val;
newState = Number(state) + 1;
if (newState > 1) {
Expand All @@ -390,6 +392,7 @@ class GreeHvac extends utils.Adapter {
await this.setStateAsync(`${deviceId}.turbo`, newState);
break;
case 'display-btn':
if (isAlive === false) return;
state = (await this.getStateAsync(`${deviceId}.display-state`)).val;
newState = Number(state) + 1;
if (newState > 1) {
Expand Down

0 comments on commit 4028f79

Please sign in to comment.