Skip to content

Commit

Permalink
fixed bug in device control when two or more devices are present (all…
Browse files Browse the repository at this point in the history
… commands were sent to first one)
  • Loading branch information
Black-Thunder committed May 29, 2020
1 parent 5b6d612 commit 6f0a565
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/melcloudDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ const commonDefines = require("./commonDefines");
const JSONHelper = require("./jsonHelper");

let gthat = null; // pointer to "this" from main.js/MelCloud instance
let gthis = null; // pointer to "this" from MelcloudDevice

class MelcloudDevice {
constructor(that) {
gthat = that;
gthis = this;
this.platform = null;
this.airInfo = null;

Expand Down Expand Up @@ -543,22 +541,24 @@ class MelcloudDevice {
}

getDeviceInfo(callback, deviceOption, value) {
if (this.airInfo != null) {
gthat.log.debug("Data already available for: " + this.id + " (" + this.name + ")");
callback && callback(deviceOption, value);
const gthis = this;

if (gthis.airInfo != null) {
gthat.log.debug("Data already available for: " + gthis.id + " (" + gthis.name + ")");
callback && callback(deviceOption, value, gthis);
return;
}

gthat.log.info("Getting device data for " + this.id + " (" + this.name + ")");
gthat.log.info("Getting device data for " + gthis.id + " (" + gthis.name + ")");

const url = "https://app.melcloud.com/Mitsubishi.Wifi.Client/Device/Get?id=" + this.id + "&buildingID=" + this.buildingId;
const method = "get";
const url = "https://app.melcloud.com/Mitsubishi.Wifi.Client/Device/Get?id=" + gthis.id + "&buildingID=" + gthis.buildingId;
const method = "get";

request({
url: url,
method: method,
headers: {
"X-MitsContextKey": this.platform.contextKey
"X-MitsContextKey": gthis.platform.contextKey
}
}, function (err, response) {
if (err || response.body.search("<!DOCTYPE html>") != -1) {
Expand All @@ -575,16 +575,16 @@ class MelcloudDevice {
gthis.airInfo = null;
}, 60 * 1000);

callback && callback(deviceOption, value);
callback && callback(deviceOption, value, gthis);
}
});
}

setDevice(deviceOption, value) {
setDevice(deviceOption, value, gthis) {
gthat.log.info("Changing device option '" + deviceOption.id + "' to '" + (value.value != undefined ? value.value : value) + "'...");
const r = gthis.airInfo;

value = gthis.verifyDeviceOptionValue(deviceOption, value);
value = gthis.verifyDeviceOptionValue(deviceOption, value, gthis);

if (deviceOption == commonDefines.DeviceOptions.PowerState) {
switch (value) {
Expand Down Expand Up @@ -686,7 +686,7 @@ class MelcloudDevice {
});
}

verifyDeviceOptionValue(deviceOption, value) {
verifyDeviceOptionValue(deviceOption, value, gthis) {
switch (deviceOption) {
case commonDefines.DeviceOptions.FanSpeed:
if (value > gthis.numberOfFanSpeeds) {
Expand Down

0 comments on commit 6f0a565

Please sign in to comment.