Skip to content

Commit

Permalink
Fix meters and emeters. Add update for both
Browse files Browse the repository at this point in the history
  • Loading branch information
Luligu committed Jun 19, 2024
1 parent da3a32a commit d46b0ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,24 @@ export class ShellyPlatform extends MatterbridgeDynamicPlatform {
ClusterRegistry.register(EveHistory.Complete);
const child = mbDevice.addChildDeviceTypeWithClusterServer(key, [powerSource], [EveHistory.Cluster.id]);
// Set the electrical attributes
const voltage = pmComponent.getValue('voltage');
const voltage = pmComponent.hasProperty('voltage') ? pmComponent.getValue('voltage') : undefined;
if (voltage !== undefined) child.getClusterServer(EveHistoryCluster.with(EveHistory.Feature.EveEnergy))?.setVoltageAttribute(voltage as number);
const current = pmComponent.getValue('current');

const current = pmComponent.hasProperty('current') ? pmComponent.getValue('current') : undefined;
if (current !== undefined) child.getClusterServer(EveHistoryCluster.with(EveHistory.Feature.EveEnergy))?.setCurrentAttribute(current as number);
const power = pmComponent.getValue('apower') ?? pmComponent.getValue('power');
if (power !== undefined) child.getClusterServer(EveHistoryCluster.with(EveHistory.Feature.EveEnergy))?.setConsumptionAttribute(power as number);
const energy1 = pmComponent.getValue('total'); // Gen 1 devices

const power1 = pmComponent.hasProperty('power') ? pmComponent.getValue('power') : undefined; // Gen 1 devices
if (power1 !== undefined) child.getClusterServer(EveHistoryCluster.with(EveHistory.Feature.EveEnergy))?.setConsumptionAttribute(power1 as number);
const power2 = pmComponent.hasProperty('apower') ? pmComponent.getValue('apower') : undefined; // Gen 2 devices
if (power2 !== undefined) child.getClusterServer(EveHistoryCluster.with(EveHistory.Feature.EveEnergy))?.setConsumptionAttribute(power2 as number);

const energy1 = pmComponent.hasProperty('total') ? pmComponent.getValue('total') : undefined; // Gen 1 devices
if (energy1 !== undefined && energy1 !== null)
child.getClusterServer(EveHistoryCluster.with(EveHistory.Feature.EveEnergy))?.setTotalConsumptionAttribute(energy1 as number);
const energy2 = pmComponent.getValue('aenergy'); // Gen 2 devices
const energy2 = pmComponent.hasProperty('aenergy') ? pmComponent.getValue('aenergy') : undefined; // Gen 2 devices
if (energy2 !== undefined && energy2 !== null)
child.getClusterServer(EveHistoryCluster.with(EveHistory.Feature.EveEnergy))?.setTotalConsumptionAttribute((energy2 as ShellyData).total as number);

// Add event handler
pmComponent.on('update', (component: string, property: string, value: ShellyDataType) => {
this.shellyUpdateHandler(mbDevice, device, component, property, value);
Expand Down
2 changes: 2 additions & 0 deletions src/shellyDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ export class ShellyDevice extends EventEmitter {
device.addComponent(new ShellyComponent(device, `roller:${index++}`, 'Roller', roller as ShellyData));
}
}
}
for (const key in statusPayload) {
if (key === 'meters') {
let index = 0;
for (const meter of statusPayload[key] as ShellyData[]) {
Expand Down

0 comments on commit d46b0ab

Please sign in to comment.