Skip to content

Commit

Permalink
chore: improved debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jasper-seinhorst committed Mar 24, 2024
1 parent d727a69 commit 207b765
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "homebridge-homewizard-power-consumption",
"displayName": "Homewizard Power Consumption",
"version": "1.6.1",
"version": "1.6.2",
"description": "See current power consumption and power return in Homekit",
"license": "Apache-2.0",
"author": "Jasper Seinhorst",
Expand Down Expand Up @@ -32,7 +32,8 @@
"power-return",
"solar",
"solar-panels",
"p1"
"p1",
"solar-yield"
],
"devDependencies": {
"@types/node": "^20.11.25",
Expand Down
9 changes: 4 additions & 5 deletions src/Accessories/PowerConsumption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import { HomewizardDevice, HomewizardPowerConsumptionAccessory } from '../Platfo
export default class PowerConsumption implements HomewizardPowerConsumptionAccessory {
public readonly Service: typeof Service = this.api.hap.Service;
public readonly Characteristic: typeof Characteristic = this.api.hap.Characteristic;
private chargingPower: Service;
private powerService: Service;

constructor(public config: PlatformConfig, public readonly log: Logger, public readonly api: API, public accessory: PlatformAccessory, public device: HomewizardDevice) {
this.accessory.getService(this.Service.AccessoryInformation)
.setCharacteristic(this.Characteristic.Manufacturer, 'Homewizard')
.setCharacteristic(this.Characteristic.Model, device.product_name)
.setCharacteristic(this.Characteristic.SerialNumber, device.serial)
.setCharacteristic(this.Characteristic.Version, device.firmware_version);
.setCharacteristic(this.Characteristic.SerialNumber, device.serial);

this.chargingPower = this.accessory.getService(this.Service.LightSensor) || this.accessory.addService(this.Service.LightSensor);
this.powerService = this.accessory.getService(this.Service.LightSensor) || this.accessory.addService(this.Service.LightSensor);
}

public beat(consumption: number) {
Expand All @@ -22,6 +21,6 @@ export default class PowerConsumption implements HomewizardPowerConsumptionAcces
if (consumption > 0) {
newPowerConsumptionLevel = consumption;
}
this.chargingPower.setCharacteristic(this.Characteristic.CurrentAmbientLightLevel, newPowerConsumptionLevel);
this.powerService.setCharacteristic(this.Characteristic.CurrentAmbientLightLevel, newPowerConsumptionLevel);
}
}
9 changes: 4 additions & 5 deletions src/Accessories/PowerReturn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import { HomewizardDevice, HomewizardPowerConsumptionAccessory } from '../Platfo
export default class PowerReturn implements HomewizardPowerConsumptionAccessory {
public readonly Service: typeof Service = this.api.hap.Service;
public readonly Characteristic: typeof Characteristic = this.api.hap.Characteristic;
private chargingPower: Service;
private powerService: Service;

constructor(public config: PlatformConfig, public readonly log: Logger, public readonly api: API, public accessory: PlatformAccessory, public device: HomewizardDevice) {
this.accessory.getService(this.Service.AccessoryInformation)
.setCharacteristic(this.Characteristic.Manufacturer, 'Homewizard')
.setCharacteristic(this.Characteristic.Model, device.product_name)
.setCharacteristic(this.Characteristic.SerialNumber, device.serial)
.setCharacteristic(this.Characteristic.Version, device.firmware_version);
.setCharacteristic(this.Characteristic.SerialNumber, device.serial);

this.chargingPower = this.accessory.getService(this.Service.LightSensor) || this.accessory.addService(this.Service.LightSensor);
this.powerService = this.accessory.getService(this.Service.LightSensor) || this.accessory.addService(this.Service.LightSensor);
}

public beat(consumption: number) {
Expand All @@ -22,6 +21,6 @@ export default class PowerReturn implements HomewizardPowerConsumptionAccessory
if (consumption < 0) {
newPowerConsumptionLevel = consumption * -1;
}
this.chargingPower.setCharacteristic(this.Characteristic.CurrentAmbientLightLevel, newPowerConsumptionLevel);
this.powerService.setCharacteristic(this.Characteristic.CurrentAmbientLightLevel, newPowerConsumptionLevel);
}
}
12 changes: 7 additions & 5 deletions src/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ export class HomewizardPowerConsumption implements DynamicPlatformPlugin {

private setupAccessoires() {

const powerConsumptionName = 'Power Consumption';
const powerConsumptionUuid = this.api.hap.uuid.generate('homewizard-power-consumption');
const powerConsumptionExistingAccessory = this.accessories.find(accessory => accessory.UUID === powerConsumptionUuid);
if (this.config.hidePowerConsumptionDevice !== true) {
if (powerConsumptionExistingAccessory) {
this.devices.push(new PowerConsumption(this.config, this.log, this.api, powerConsumptionExistingAccessory, this.device));
} else {
this.log.info('Power Consumption added as accessory');
const accessory = new this.api.platformAccessory('Power Consumption', powerConsumptionUuid);
this.log.info(`${powerConsumptionName} added as accessory`);
const accessory = new this.api.platformAccessory(powerConsumptionName, powerConsumptionUuid);
this.devices.push(new PowerConsumption(this.config, this.log, this.api, accessory, this.device));
this.api.registerPlatformAccessories('homebridge-homewizard-power-consumption', 'HomewizardPowerConsumption', [accessory]);
}
Expand All @@ -80,14 +81,15 @@ export class HomewizardPowerConsumption implements DynamicPlatformPlugin {
}
}

const powerReturnName = 'Power Return';
const powerReturnUuid = this.api.hap.uuid.generate('homewizard-power-return');
const powerReturnExistingAccessory = this.accessories.find(accessory => accessory.UUID === powerReturnUuid);
if (this.config.hidePowerReturnDevice !== true) {
if (powerReturnExistingAccessory) {
this.devices.push(new PowerReturn(this.config, this.log, this.api, powerReturnExistingAccessory, this.device));
} else {
this.log.info('Power Return added as accessory');
const accessory = new this.api.platformAccessory('Power Return', powerReturnUuid);
this.log.info(`${powerReturnName} added as accessory`);
const accessory = new this.api.platformAccessory(powerReturnName, powerReturnUuid);
this.devices.push(new PowerReturn(this.config, this.log, this.api, accessory, this.device));
this.api.registerPlatformAccessories('homebridge-homewizard-power-consumption', 'HomewizardPowerConsumption', [accessory]);
}
Expand All @@ -105,7 +107,7 @@ export class HomewizardPowerConsumption implements DynamicPlatformPlugin {
this.devices.forEach((device: HomewizardPowerConsumptionAccessory) => {
device.beat(consumption);
});
this.log.debug('heartbeat', consumption);
this.log.debug('heart beat', consumption);
} catch(error) {
this.log.error('Something went wrong, please double check the Wi-Fi P1 meter\'s IP address');
this.log.debug(error);
Expand Down

0 comments on commit 207b765

Please sign in to comment.