From 298baaf162e606d4eb77ee147efef3d4af26555e Mon Sep 17 00:00:00 2001 From: Dennis Blommesteijn Date: Wed, 20 Dec 2023 21:19:29 +0100 Subject: [PATCH] Bump version; Attempt fix zombie processes for sfk --- .vscode/settings.json | 2 +- package-lock.json | 48 +++++++++++++++++++++---------------------- package.json | 2 +- src/platform.ts | 44 ++++++++------------------------------- 4 files changed, 34 insertions(+), 62 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 31b20d1..89d2e29 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,7 @@ { "files.eol": "\n", "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" }, "editor.rulers": [ 140 ], "eslint.enable": true diff --git a/package-lock.json b/package-lock.json index 4984b19..19cdcb1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2225,9 +2225,9 @@ } }, "node_modules/nodemon": { - "version": "2.0.20", - "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.20.tgz", - "integrity": "sha512-Km2mWHKKY5GzRg6i1j5OxOHQtuvVsgskLfigG25yTtbyfRGn/GNvIbRyOf1PSCKJ2aT/58TiuUsuOU5UToVViw==", + "version": "2.0.22", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.22.tgz", + "integrity": "sha512-B8YqaKMmyuCO7BowF1Z1/mkPqLk6cs/l63Ojtd6otKjMx47Dq1utxfRxcavH1I7VSaL8n5BUaoutadnsX3AAVQ==", "dev": true, "dependencies": { "chokidar": "^3.5.2", @@ -2271,9 +2271,9 @@ } }, "node_modules/nodemon/node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "dev": true, "bin": { "semver": "bin/semver" @@ -2676,9 +2676,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "node_modules/semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" @@ -3195,9 +3195,9 @@ } }, "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true, "engines": { "node": ">=0.10.0" @@ -4870,9 +4870,9 @@ } }, "nodemon": { - "version": "2.0.20", - "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.20.tgz", - "integrity": "sha512-Km2mWHKKY5GzRg6i1j5OxOHQtuvVsgskLfigG25yTtbyfRGn/GNvIbRyOf1PSCKJ2aT/58TiuUsuOU5UToVViw==", + "version": "2.0.22", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.22.tgz", + "integrity": "sha512-B8YqaKMmyuCO7BowF1Z1/mkPqLk6cs/l63Ojtd6otKjMx47Dq1utxfRxcavH1I7VSaL8n5BUaoutadnsX3AAVQ==", "dev": true, "requires": { "chokidar": "^3.5.2", @@ -4903,9 +4903,9 @@ "dev": true }, "semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "dev": true }, "supports-color": { @@ -5166,9 +5166,9 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, "requires": { "lru-cache": "^6.0.0" @@ -5548,9 +5548,9 @@ } }, "word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true }, "wrappy": { diff --git a/package.json b/package.json index ce16c03..b621d86 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "private": false, "displayName": "Homebridge GoodWe Inverter", "name": "homebridge-goodwe-inverter", - "version": "0.0.3", + "version": "0.0.4", "description": "This plugin consumes the Local IP that is broadcased via UDP from any GoodWe Inverter", "license": "Apache-2.0", "repository": { diff --git a/src/platform.ts b/src/platform.ts index b09aaa0..a53b8bc 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -35,27 +35,6 @@ export class HomebridgeGoodWeInverter implements DynamicPlatformPlugin { this.accessories.push(accessory); } - // loadElectricityAccessory(inverterData, dataDigPa) - - // loadElectricityAccessory(powerStationId, powerStationData, dataDigPath, name, multiplier = 1): ElectricityWattAccessory { - // const uuid = this.api.hap.uuid.generate(`power_station_${powerStationId}_${dataDigPath.join()}`); - // const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid); - // let ret; - - // if(existingAccessory) { - // this.log.info('found cached accessory', existingAccessory.displayName); - // ret = new ElectricityWattAccessory(this, existingAccessory); - // } else { - // this.log.info('found new accessory', name); - // const accessory = new this.api.platformAccessory(name, uuid); - // accessory.context.device = { data: powerStationData, dataDigPath: dataDigPath, id: powerStationId, name: name, - // multiplier: multiplier }; - // ret = new ElectricityWattAccessory(this, accessory); - // this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]); - // } - // return ret; - // } - loadElectricityAccessory(localInstanceConfig, instanceData, dataDigPath, name): ElectricityWattAccessory { const uuid = this.api.hap.uuid.generate(`local_instance_${localInstanceConfig.localIp}_${dataDigPath.join()}`); const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid); @@ -98,7 +77,7 @@ export class HomebridgeGoodWeInverter implements DynamicPlatformPlugin { this.log.debug('running cmd: ', cmd); let output = ''; try { - const { stdout, stderr } = await execPromise(cmd); + const { stdout, stderr } = await execPromise(cmd, { timeout: localInstanceConfig.timeout as number, killSignal: 'SIGKILL' }); this.log.debug('cmd:response:stdout', stdout); this.log.debug('cmd:response:stderr', stderr); output = stdout; @@ -108,25 +87,13 @@ export class HomebridgeGoodWeInverter implements DynamicPlatformPlugin { this.log.debug('cmd:error', e.stdout); output = e.stdout; } - if (output === '[timeout]') { - if(!this.retry[localInstanceConfig.localIp]) { - this.retry[localInstanceConfig.localIp] = 0; - } - this.retry[localInstanceConfig.localIp]++; - await this.sleep(10000, () => { - this.log.debug('sleeping...'); - }); - return await this.lookupLocalInstance(localInstanceConfig); - } - // TODO: add error output here! return this.parseInverter(output); } parseInverter(output) { this.log.debug('parseInverter:output', output); - - const ret = { internalTemperature: -1, mode: '', generationToday: -1, power: -1, generationTotal: -1 }; + const ret = { internalTemperature: -1, mode: 'offline', generationToday: -1, power: -1, generationTotal: -1 }; const temperatureIndex = 174; const temperature = Number('0x' + output.substring(temperatureIndex, temperatureIndex + 4)) / 10; if(temperature && temperature < 80 && temperature > -20) { @@ -150,7 +117,7 @@ export class HomebridgeGoodWeInverter implements DynamicPlatformPlugin { // in kWh const generationTodayIndex = 186; const generationToday = Number('0x' + output.substring(generationTodayIndex, generationTodayIndex + 4)) * 100; - if (generationToday > 0) { + if (generationToday >= 0) { ret.generationToday = generationToday; } @@ -176,6 +143,9 @@ export class HomebridgeGoodWeInverter implements DynamicPlatformPlugin { for(const localInstanceConfig of this.config.localIps) { const accessories: PowerStationAccessory[] = []; const inverterData = await this.lookupLocalInstance(localInstanceConfig); + + // TODO: add some timeout values, and wait upon timeout with requesting new lookup. + if(this.config.showCurrentPowerLevel) { accessories.push( this.loadElectricityAccessory(localInstanceConfig, inverterData, ['power'], 'Generation Watt')); @@ -192,6 +162,8 @@ export class HomebridgeGoodWeInverter implements DynamicPlatformPlugin { accessories.push( this.loadElectricityAccessory(localInstanceConfig, inverterData, ['generationTotal'], 'Total Generation MWh')); } + + // TODO: check if this will still work with a timeout catch around the block.. this.fetchLocalInstanceUpdate(localInstanceConfig.timeout + 500, localInstanceConfig, accessories); } }