Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from simonarnell/enhancements/downgrade-axios-e…
Browse files Browse the repository at this point in the history
…rrors

Enhancements/downgrade axios errors
  • Loading branch information
simonarnell authored Dec 24, 2020
2 parents d5c98ec + 446a776 commit 9d6a16d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Service,
Units} from "homebridge";
import SolisInverterClient = require('solis-inverter/lib/solis_inverter_client');
import type { AxiosError } from "axios"
import { InverterDataFrame } from "./types/inverterDataFrame";

let hap: HAP;
Expand Down Expand Up @@ -104,22 +105,21 @@ class SolisInverter implements AccessoryPlugin {
}

fetchData(): void {
this.generating = false;
this.on = false;
this.currentlyGenerating = 0;
this.solisInverterClient.fetchData()
.then((data: InverterDataFrame) => {
this.log.debug(JSON.stringify(data))
if (data.inverter.serial) {
this.on = true
this.generatedToday = data.energy.today;
this.currentlyGenerating = data.power
if(data.power > 0)
this.generating = true;
this.generating = data.power > 0
}
})
.catch((err: unknown) => {
this.log.error(JSON.stringify(err));
.catch((err: AxiosError) => {
this.log.warn(`Error communicating with inverter - ${err.code}`);
this.on = false;
this.generating = false;
this.currentlyGenerating = 0;
})
}
}

0 comments on commit 9d6a16d

Please sign in to comment.