mirror of
https://github.com/bourquep/mysa2mqtt.git
synced 2025-12-18 06:02:36 +00:00
fix: Don't crash on undefined values returned by the Mysa API (#81)
This commit is contained in:
@@ -187,18 +187,22 @@ export class Thermostat {
|
||||
try {
|
||||
const deviceStates = await this.mysaApiClient.getDeviceStates();
|
||||
const state = deviceStates.DeviceStatesObj[this.mysaDevice.Id];
|
||||
const tstatMode = state.TstatMode?.v;
|
||||
|
||||
this.mqttClimate.currentTemperature = state.CorrectedTemp.v;
|
||||
this.mqttClimate.currentHumidity = state.Humidity.v;
|
||||
this.mqttClimate.currentMode = state.TstatMode.v === 1 ? 'off' : state.TstatMode.v === 3 ? 'heat' : undefined;
|
||||
this.mqttClimate.currentAction = this.computeCurrentAction(undefined, state.Duty.v);
|
||||
this.mqttClimate.targetTemperature = this.mqttClimate.currentMode !== 'off' ? state.SetPoint.v : undefined;
|
||||
this.mqttClimate.currentTemperature = state.CorrectedTemp?.v;
|
||||
this.mqttClimate.currentHumidity = state.Humidity?.v;
|
||||
this.mqttClimate.currentMode = tstatMode === 1 ? 'off' : tstatMode === 3 ? 'heat' : undefined;
|
||||
this.mqttClimate.currentAction = this.computeCurrentAction(undefined, state.Duty?.v);
|
||||
this.mqttClimate.targetTemperature = this.mqttClimate.currentMode !== 'off' ? state.SetPoint?.v : undefined;
|
||||
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.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();
|
||||
|
||||
// `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.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;
|
||||
await this.mqttPower.setState('state_topic', watts.toFixed(2));
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user