Skip to content

Commit

Permalink
feat: serial number and firmware version
Browse files Browse the repository at this point in the history
  • Loading branch information
jasper-seinhorst committed Mar 23, 2024
1 parent 34c5c57 commit a54c3dc
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 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.

2 changes: 1 addition & 1 deletion 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.5.0",
"version": "1.6.0",
"description": "See current power consumption and power return in Homekit",
"license": "Apache-2.0",
"author": "Jasper Seinhorst",
Expand Down
10 changes: 7 additions & 3 deletions src/Accessories/PowerConsumption.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { Service, PlatformAccessory, PlatformConfig, Logger, API, Characteristic } from 'homebridge';
import { HomewizardPowerConsumptionAccessory } from '../PlatformTypes';
import { HomewizardDevice, HomewizardPowerConsumptionAccessory } from '../PlatformTypes';

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;

constructor(public config: PlatformConfig, public readonly log: Logger, public readonly api: API, public accessory: PlatformAccessory) {
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, 'P1');
.setCharacteristic(this.Characteristic.Model, device.product_name)
.setCharacteristic(this.Characteristic.SerialNumber, device.serial)
.setCharacteristic(this.Characteristic.Version, device.firmware_version);

console.log(accessory.context);

this.chargingPower = this.accessory.getService(this.Service.LightSensor) || this.accessory.addService(this.Service.LightSensor);
}
Expand Down
8 changes: 5 additions & 3 deletions src/Accessories/PowerReturn.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Service, PlatformAccessory, PlatformConfig, Logger, API, Characteristic } from 'homebridge';
import { HomewizardPowerConsumptionAccessory } from '../PlatformTypes';
import { HomewizardDevice, HomewizardPowerConsumptionAccessory } from '../PlatformTypes';

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;

constructor(public config: PlatformConfig, public readonly log: Logger, public readonly api: API, public accessory: PlatformAccessory) {
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, 'P1');
.setCharacteristic(this.Characteristic.Model, device.product_name)
.setCharacteristic(this.Characteristic.SerialNumber, device.serial)
.setCharacteristic(this.Characteristic.Version, device.firmware_version);

this.chargingPower = this.accessory.getService(this.Service.LightSensor) || this.accessory.addService(this.Service.LightSensor);
}
Expand Down
12 changes: 7 additions & 5 deletions src/Platform.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service, Characteristic } from 'homebridge';
import axios from 'axios';
import { HomewizardPowerConsumptionAccessory } from './PlatformTypes';
import { HomewizardPowerConsumptionAccessory, HomewizardDevice } from './PlatformTypes';
import PowerConsumption from './Accessories/PowerConsumption';
import PowerReturn from './Accessories/PowerReturn';

Expand All @@ -10,6 +10,7 @@ export class HomewizardPowerConsumption implements DynamicPlatformPlugin {
public readonly accessories: PlatformAccessory[] = [];
private heartBeatInterval: number;
private devices: HomewizardPowerConsumptionAccessory[] = [];
private device: HomewizardDevice;


constructor(public readonly log: Logger, public readonly config: PlatformConfig, public readonly api: API) {
Expand All @@ -31,6 +32,7 @@ export class HomewizardPowerConsumption implements DynamicPlatformPlugin {
try {
const { data } = await axios.get(`http://${this.config.ip}/api/`, { timeout: 2000 });
if (data && data.product_type === 'HWE-P1') {
this.device = data;
return true;
}
return false;
Expand Down Expand Up @@ -65,11 +67,11 @@ export class HomewizardPowerConsumption implements DynamicPlatformPlugin {
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.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.devices.push(new PowerConsumption(this.config, this.log, this.api, accessory));
this.devices.push(new PowerConsumption(this.config, this.log, this.api, accessory, this.device));
this.api.registerPlatformAccessories('homebridge-homewizard-power-consumption', 'HomewizardPowerConsumption', [accessory]);
}
} else {
Expand All @@ -82,11 +84,11 @@ export class HomewizardPowerConsumption implements DynamicPlatformPlugin {
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.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.devices.push(new PowerReturn(this.config, this.log, this.api, accessory));
this.devices.push(new PowerReturn(this.config, this.log, this.api, accessory, this.device));
this.api.registerPlatformAccessories('homebridge-homewizard-power-consumption', 'HomewizardPowerConsumption', [accessory]);
}
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/PlatformTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ export interface HomewizardPowerConsumptionAccessory {
accessory: PlatformAccessory;
displayName?: string;
beat(consumption: number): void;
}

export interface HomewizardDevice {
product_name: string;
product_type: string;
serial: string;
firmware_version: string;
api_version: string;
}

0 comments on commit a54c3dc

Please sign in to comment.