mirror of
https://github.com/bourquep/mysa2mqtt.git
synced 2025-11-02 04:39:40 +00:00
fix: Don't crash on undefined values returned by the Mysa API (#81)
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@@ -12,7 +12,7 @@
|
|||||||
"commander": "14.0.1",
|
"commander": "14.0.1",
|
||||||
"dotenv": "17.2.3",
|
"dotenv": "17.2.3",
|
||||||
"mqtt2ha": "4.1.2",
|
"mqtt2ha": "4.1.2",
|
||||||
"mysa-js-sdk": "1.4.0",
|
"mysa-js-sdk": "2.0.0",
|
||||||
"pino": "10.1.0",
|
"pino": "10.1.0",
|
||||||
"pino-pretty": "13.1.2"
|
"pino-pretty": "13.1.2"
|
||||||
},
|
},
|
||||||
@@ -8033,9 +8033,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/mysa-js-sdk": {
|
"node_modules/mysa-js-sdk": {
|
||||||
"version": "1.4.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/mysa-js-sdk/-/mysa-js-sdk-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/mysa-js-sdk/-/mysa-js-sdk-2.0.0.tgz",
|
||||||
"integrity": "sha512-Aw2ZMtRUlGLoQyukpcfWKtBZtGqWYiDKhvD6CD5NLAqjl7WgkoF7j+FKgsqohgEy/6WDXXp+Ur90TLvtBtjikQ==",
|
"integrity": "sha512-fxRJqnpLoBCAZh5NppSQobRnFJd2yiy1XD2K5HMkwuO8ye0AjhrqGGRH8HYzm+KHxNJ4b2T6Eb/ik7FwppKMDw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-iot": "3.920.0",
|
"@aws-sdk/client-iot": "3.920.0",
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
"commander": "14.0.1",
|
"commander": "14.0.1",
|
||||||
"dotenv": "17.2.3",
|
"dotenv": "17.2.3",
|
||||||
"mqtt2ha": "4.1.2",
|
"mqtt2ha": "4.1.2",
|
||||||
"mysa-js-sdk": "1.4.0",
|
"mysa-js-sdk": "2.0.0",
|
||||||
"pino": "10.1.0",
|
"pino": "10.1.0",
|
||||||
"pino-pretty": "13.1.2"
|
"pino-pretty": "13.1.2"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -187,18 +187,22 @@ export class Thermostat {
|
|||||||
try {
|
try {
|
||||||
const deviceStates = await this.mysaApiClient.getDeviceStates();
|
const deviceStates = await this.mysaApiClient.getDeviceStates();
|
||||||
const state = deviceStates.DeviceStatesObj[this.mysaDevice.Id];
|
const state = deviceStates.DeviceStatesObj[this.mysaDevice.Id];
|
||||||
|
const tstatMode = state.TstatMode?.v;
|
||||||
|
|
||||||
this.mqttClimate.currentTemperature = state.CorrectedTemp.v;
|
this.mqttClimate.currentTemperature = state.CorrectedTemp?.v;
|
||||||
this.mqttClimate.currentHumidity = state.Humidity.v;
|
this.mqttClimate.currentHumidity = state.Humidity?.v;
|
||||||
this.mqttClimate.currentMode = state.TstatMode.v === 1 ? 'off' : state.TstatMode.v === 3 ? 'heat' : undefined;
|
this.mqttClimate.currentMode = tstatMode === 1 ? 'off' : tstatMode === 3 ? 'heat' : undefined;
|
||||||
this.mqttClimate.currentAction = this.computeCurrentAction(undefined, state.Duty.v);
|
this.mqttClimate.currentAction = this.computeCurrentAction(undefined, state.Duty?.v);
|
||||||
this.mqttClimate.targetTemperature = this.mqttClimate.currentMode !== 'off' ? state.SetPoint.v : undefined;
|
this.mqttClimate.targetTemperature = this.mqttClimate.currentMode !== 'off' ? state.SetPoint?.v : undefined;
|
||||||
await this.mqttClimate.writeConfig();
|
await this.mqttClimate.writeConfig();
|
||||||
|
|
||||||
await this.mqttTemperature.setState('state_topic', state.CorrectedTemp.v.toFixed(2));
|
await this.mqttTemperature.setState(
|
||||||
|
'state_topic',
|
||||||
|
state.CorrectedTemp != null ? state.CorrectedTemp.v.toFixed(2) : 'None'
|
||||||
|
);
|
||||||
await this.mqttTemperature.writeConfig();
|
await this.mqttTemperature.writeConfig();
|
||||||
|
|
||||||
await this.mqttHumidity.setState('state_topic', state.Humidity.v.toFixed(2));
|
await this.mqttHumidity.setState('state_topic', state.Humidity != null ? state.Humidity.v.toFixed(2) : 'None');
|
||||||
await this.mqttHumidity.writeConfig();
|
await this.mqttHumidity.writeConfig();
|
||||||
|
|
||||||
// `state.Current.v` always has a non-zero value, even for thermostats that are off, so we can't use it to determine initial power state.
|
// `state.Current.v` always has a non-zero value, even for thermostats that are off, so we can't use it to determine initial power state.
|
||||||
@@ -242,7 +246,7 @@ export class Thermostat {
|
|||||||
this.mqttClimate.currentHumidity = status.humidity;
|
this.mqttClimate.currentHumidity = status.humidity;
|
||||||
this.mqttClimate.targetTemperature = this.mqttClimate.currentMode !== 'off' ? status.setPoint : undefined;
|
this.mqttClimate.targetTemperature = this.mqttClimate.currentMode !== 'off' ? status.setPoint : undefined;
|
||||||
|
|
||||||
if (status.current != null) {
|
if (this.mysaDevice.Voltage != null && status.current != null) {
|
||||||
const watts = this.mysaDevice.Voltage * status.current;
|
const watts = this.mysaDevice.Voltage * status.current;
|
||||||
await this.mqttPower.setState('state_topic', watts.toFixed(2));
|
await this.mqttPower.setState('state_topic', watts.toFixed(2));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user