From 1bc1f283881e055718af8ea1005e5f8d5897e2bf Mon Sep 17 00:00:00 2001 From: Jasper Seinhorst Date: Sun, 24 Mar 2024 19:52:17 +0100 Subject: [PATCH] fix: minimum lux value and duplicate serial numbers --- package-lock.json | 4 ++-- package.json | 2 +- src/Accessories/CurrentPowerProduction.ts | 8 ++++---- src/Accessories/TodayYield.ts | 8 ++++---- src/Accessories/TotalYield.ts | 8 ++++---- src/Platform.ts | 3 +-- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index 83a8e45..7bb4cd4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "homebridge-omnik", - "version": "1.2.0", + "version": "1.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "homebridge-omnik", - "version": "1.2.0", + "version": "1.2.1", "license": "Apache-2.0", "dependencies": { "axios": "^1.6.7" diff --git a/package.json b/package.json index 938dcbe..a338d11 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "homebridge-omnik", "displayName": "Omnik Inverter", - "version": "1.2.0", + "version": "1.2.1", "description": "Add your Omnik-Inverter to Homekit", "license": "Apache-2.0", "author": "Jasper Seinhorst", diff --git a/src/Accessories/CurrentPowerProduction.ts b/src/Accessories/CurrentPowerProduction.ts index 44d9000..7bc98f7 100644 --- a/src/Accessories/CurrentPowerProduction.ts +++ b/src/Accessories/CurrentPowerProduction.ts @@ -10,14 +10,14 @@ export default class CurrentPowerProduction implements OmnikAccessory { this.accessory.getService(this.Service.AccessoryInformation) .setCharacteristic(this.Characteristic.Manufacturer, 'Omnik') .setCharacteristic(this.Characteristic.Model, device.name) - .setCharacteristic(this.Characteristic.SerialNumber, device.serial); - - + .setCharacteristic(this.Characteristic.SerialNumber, `${device.serial}-power-production`); this.powerService = this.accessory.getService(this.Service.LightSensor) || this.accessory.addService(this.Service.LightSensor); } public beat(powerProduction: PowerProduction) { + const minimumValue = 0.0001; const consumption = powerProduction.now; - this.powerService.setCharacteristic(this.Characteristic.CurrentAmbientLightLevel, consumption); + const newValue = consumption > minimumValue ? consumption : minimumValue; + this.powerService.setCharacteristic(this.Characteristic.CurrentAmbientLightLevel, newValue); } } diff --git a/src/Accessories/TodayYield.ts b/src/Accessories/TodayYield.ts index 2c96aac..aa5866d 100644 --- a/src/Accessories/TodayYield.ts +++ b/src/Accessories/TodayYield.ts @@ -10,14 +10,14 @@ export default class TodayYield implements OmnikAccessory { this.accessory.getService(this.Service.AccessoryInformation) .setCharacteristic(this.Characteristic.Manufacturer, 'Omnik') .setCharacteristic(this.Characteristic.Model, device.name) - .setCharacteristic(this.Characteristic.SerialNumber, device.serial); - - + .setCharacteristic(this.Characteristic.SerialNumber, `${device.serial}-today-yield`); this.powerService = this.accessory.getService(this.Service.LightSensor) || this.accessory.addService(this.Service.LightSensor); } public beat(powerProduction: PowerProduction) { + const minimumValue = 0.0001; const consumption = powerProduction.today / 100; - this.powerService.setCharacteristic(this.Characteristic.CurrentAmbientLightLevel, consumption); + const newValue = consumption > minimumValue ? consumption : minimumValue; + this.powerService.setCharacteristic(this.Characteristic.CurrentAmbientLightLevel, newValue); } } diff --git a/src/Accessories/TotalYield.ts b/src/Accessories/TotalYield.ts index c6d21e0..5468e35 100644 --- a/src/Accessories/TotalYield.ts +++ b/src/Accessories/TotalYield.ts @@ -10,14 +10,14 @@ export default class TotalYield implements OmnikAccessory { this.accessory.getService(this.Service.AccessoryInformation) .setCharacteristic(this.Characteristic.Manufacturer, 'Omnik') .setCharacteristic(this.Characteristic.Model, device.name) - .setCharacteristic(this.Characteristic.SerialNumber, device.serial); - - + .setCharacteristic(this.Characteristic.SerialNumber, `${device.serial}-total-yield`); this.powerService = this.accessory.getService(this.Service.LightSensor) || this.accessory.addService(this.Service.LightSensor); } public beat(powerProduction: PowerProduction) { + const minimumValue = 0.0001; const consumption = powerProduction.total / 10; - this.powerService.setCharacteristic(this.Characteristic.CurrentAmbientLightLevel, consumption); + const newValue = consumption > minimumValue ? consumption : minimumValue; + this.powerService.setCharacteristic(this.Characteristic.CurrentAmbientLightLevel, newValue); } } diff --git a/src/Platform.ts b/src/Platform.ts index f64052f..ebb93e5 100644 --- a/src/Platform.ts +++ b/src/Platform.ts @@ -9,12 +9,11 @@ export class OmnikPlugin implements DynamicPlatformPlugin { public readonly Service: typeof Service = this.api.hap.Service; public readonly Characteristic: typeof Characteristic = this.api.hap.Characteristic; public readonly accessories: PlatformAccessory[] = []; - private heartBeatInterval; + private heartBeatInterval: number; private devices: OmnikAccessory[] = []; private omnikApi: OmnikApi; private device: OmnikDevice; - constructor(public readonly log: Logger, public readonly config: PlatformConfig, public readonly api: API) { this.heartBeatInterval = (config.pollInterval || 5) * 60 * 1000; // minutes to miliseconds this.api.on('didFinishLaunching', () => {