From c4118a7644aa155e5e0c6f728d7879872f582b48 Mon Sep 17 00:00:00 2001 From: Simon Arnell Date: Thu, 24 Dec 2020 10:05:39 +0000 Subject: [PATCH 1/4] downgraded axios errors to warnings --- src/accessory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/accessory.ts b/src/accessory.ts index c372076..a719751 100644 --- a/src/accessory.ts +++ b/src/accessory.ts @@ -119,7 +119,7 @@ class SolisInverter implements AccessoryPlugin { } }) .catch((err: unknown) => { - this.log.error(JSON.stringify(err)); + this.log.warn(JSON.stringify(err)); }) } } \ No newline at end of file From 3fc7b81459c922f5060aa40d17f622cf727f8d79 Mon Sep 17 00:00:00 2001 From: Simon Arnell Date: Thu, 24 Dec 2020 10:15:34 +0000 Subject: [PATCH 2/4] import axios error type --- src/accessory.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/accessory.ts b/src/accessory.ts index a719751..3166ce6 100644 --- a/src/accessory.ts +++ b/src/accessory.ts @@ -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; @@ -118,7 +119,7 @@ class SolisInverter implements AccessoryPlugin { this.generating = true; } }) - .catch((err: unknown) => { + .catch((err: AxiosError) => { this.log.warn(JSON.stringify(err)); }) } From a193afa1ba56c74306559e6c32d284bc7b22380b Mon Sep 17 00:00:00 2001 From: Simon Arnell Date: Thu, 24 Dec 2020 10:29:18 +0000 Subject: [PATCH 3/4] simplified error reporting --- src/accessory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/accessory.ts b/src/accessory.ts index 3166ce6..258f6fc 100644 --- a/src/accessory.ts +++ b/src/accessory.ts @@ -120,7 +120,7 @@ class SolisInverter implements AccessoryPlugin { } }) .catch((err: AxiosError) => { - this.log.warn(JSON.stringify(err)); + this.log.warn(`Error communicating with inverter - ${err.code}`); }) } } \ No newline at end of file From 446a776466938e391c8efd60d98b0ca7e7faf0eb Mon Sep 17 00:00:00 2001 From: Simon Arnell Date: Thu, 24 Dec 2020 10:30:08 +0000 Subject: [PATCH 4/4] improved state management from connection errors --- src/accessory.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/accessory.ts b/src/accessory.ts index 258f6fc..65205fc 100644 --- a/src/accessory.ts +++ b/src/accessory.ts @@ -105,9 +105,6 @@ 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)) @@ -115,12 +112,14 @@ class SolisInverter implements AccessoryPlugin { 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: AxiosError) => { this.log.warn(`Error communicating with inverter - ${err.code}`); + this.on = false; + this.generating = false; + this.currentlyGenerating = 0; }) } } \ No newline at end of file