Skip to content

Commit

Permalink
Fix for mqtt not working for the air-conditioner temperature.
Browse files Browse the repository at this point in the history
  • Loading branch information
lprhodes committed Mar 28, 2018
1 parent 4470923 commit 9d44e98
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
24 changes: 18 additions & 6 deletions accessories/aircon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { assert } = require('chai');
const uuid = require('uuid');
const fs = require('fs');
const findKey = require('find-key');

const delayForDuration = require('../helpers/delayForDuration');
const ServiceManagerTypes = require('../helpers/serviceManagerTypes');
Expand Down Expand Up @@ -369,15 +370,15 @@ class AirConAccessory extends BroadlinkRMAccessory {
log(`${name} onTemperature (${temperature})`);

if (temperature > config.maxTemperature) {
log(`\x1b[35m[INFO]\x1b[0m Reported temperature (${temperature}) is too high, setting to \x1b[33mmaxTemperature\x1b[0m (${maxTemperature}).`)
temperature = config.maxTemperature

log(`\x1b[35m[INFO]\x1b[0m Reported temperature (${temperature}) is too high, setting to \x1b[33mmaxTemperature\x1b[0m`)
}

if (temperature < config.minTemperature) {
temperature = config.minTemperature

log(`\x1b[35m[INFO]\x1b[0m Reported temperature (${temperature}) is too low, setting to \x1b[33mminTemperature\x1b[0m`)
log(`\x1b[35m[INFO]\x1b[0m Reported temperature (${temperature}) is too low, setting to \x1b[33mminTemperature\x1b[0m (${minTemperature}).`)
temperature = config.minTemperature

}

assert.isBelow(temperature, config.maxTemperature + 1, `\x1b[31m[CONFIG ERROR] \x1b[33mmaxTemperature\x1b[0m (${config.maxTemperature}) must be more than the reported temperature (${temperature})`)
Expand Down Expand Up @@ -571,15 +572,24 @@ class AirConAccessory extends BroadlinkRMAccessory {

super.onMQTTMessage(identifier, message);

let temperature = this.mqttValues[identifier];
let temperature = this.mqttValuesTemp[identifier];

if (debug) log(`\x1b[33m[DEBUG]\x1b[0m ${name} onMQTTMessage (raw value: ${temperature})`);

try {
const temperatureJSON = JSON.parse(temperature);

if (typeof temperatureJSON === 'object') {
temperature = temperatureJSON.temp || temperatureJSON.Temp || temperatureJSON.temperature || temperatureJSON.Temperature
let values = findKey(temperatureJSON, 'temp');
if (values.length === 0) values = findKey(temperatureJSON, 'Temp');
if (values.length === 0) values = findKey(temperatureJSON, 'temperature');
if (values.length === 0) values = findKey(temperatureJSON, 'Temperature');

if (values.length > 0) {
temperature = values[0];
} else {
temperature = undefined;
}
}
} catch (err) {}

Expand All @@ -598,6 +608,8 @@ class AirConAccessory extends BroadlinkRMAccessory {
this.mqttValues[identifier] = temperature;
this.updateTemperatureUI();
}



// Service Manager Setup

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
"dependencies": {
"broadlinkjs-rm": "^0.6.0",
"chai": "^4.1.2",
"find-key": "^2.0.1",
"github-version-checker": "^1.2.0",
"homebridge-platform-helper": "1.1.0",
"homebridge-platform-helper": "1.1.1",
"ping": "^0.2.2",
"uuid": "^3.2.1"
},
Expand Down
26 changes: 25 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,14 @@ base@^0.11.1:
mixin-deep "^1.2.0"
pascalcase "^0.1.1"

basic-utils@^1.6.0:
version "1.7.4"
resolved "https://registry.yarnpkg.com/basic-utils/-/basic-utils-1.7.4.tgz#b710a47db43daff50724c0e1ea4247e1e6d49946"
dependencies:
deep-freeze "0.0.1"
mkdirp "^0.5.1"
rimraf "^2.6.1"

before-after-hook@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/before-after-hook/-/before-after-hook-1.1.0.tgz#83165e15a59460d13702cb8febd6a1807896db5a"
Expand Down Expand Up @@ -1204,6 +1212,10 @@ deep-extend@~0.4.0:
version "0.4.2"
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.4.2.tgz#48b699c27e334bf89f10892be432f6e4c7d34a7f"

[email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/deep-freeze/-/deep-freeze-0.0.1.tgz#3a0b0005de18672819dfd38cd31f91179c893e84"

defaults@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"
Expand Down Expand Up @@ -1397,6 +1409,12 @@ fill-range@^4.0.0:
repeat-string "^1.6.1"
to-regex-range "^2.1.0"

find-key@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/find-key/-/find-key-2.0.1.tgz#e985c95e0089787290d9a0512e139888c13f102b"
dependencies:
basic-utils "^1.6.0"

find-up@^1.0.0:
version "1.1.2"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f"
Expand Down Expand Up @@ -1522,7 +1540,7 @@ glob-to-regexp@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab"

[email protected], glob@^7.0.0, glob@^7.0.3, glob@^7.1.1, glob@^7.1.2:
[email protected], glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2:
version "7.1.2"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
dependencies:
Expand Down Expand Up @@ -3018,6 +3036,12 @@ right-align@^0.1.1:
dependencies:
align-text "^0.1.1"

rimraf@^2.6.1:
version "2.6.2"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"
dependencies:
glob "^7.0.5"

run-async@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0"
Expand Down

0 comments on commit 9d44e98

Please sign in to comment.