Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration for the reporting type of power in electricityMeter… #8909

Merged
merged 11 commits into from
Mar 8, 2025
6 changes: 3 additions & 3 deletions src/devices/shinasystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,23 +595,23 @@ export const definitions: DefinitionWithExtend[] = [
model: "PMM-300Z1",
vendor: "ShinaSystem",
description: "SiHAS energy monitor",
extend: [m.electricityMeter()],
extend: [m.electricityMeter({reportingPowerType: "metering"})],
},
{
zigbeeModel: ["PMM-300Z2"],
model: "PMM-300Z2",
vendor: "ShinaSystem",
ota: true,
description: "SiHAS energy monitor",
extend: [m.electricityMeter({acFrequency: {multiplier: 1, divisor: 10}, powerFactor: true}), m.temperature()],
extend: [m.electricityMeter({reportingPowerType: "metering", acFrequency: {multiplier: 1, divisor: 10}, powerFactor: true}), m.temperature()],
},
{
zigbeeModel: ["PMM-300Z3"],
model: "PMM-300Z3",
vendor: "ShinaSystem",
ota: true,
description: "SiHAS 3phase energy monitor",
extend: [m.electricityMeter({acFrequency: {multiplier: 1, divisor: 10}, powerFactor: true}), m.temperature()],
extend: [m.electricityMeter({reportingPowerType: "metering", acFrequency: {multiplier: 1, divisor: 10}, powerFactor: true}), m.temperature()],
},
{
zigbeeModel: ["DLM-300Z"],
Expand Down
7 changes: 5 additions & 2 deletions src/lib/modernExtend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,7 @@ interface MeterArgs {
configureReporting?: boolean;
endpointNames?: string[];
fzMetering?: Fz.Converter;
reportingPowerType?: "metering" | "electrical";
// applies only to electrical
electricalMeasurementType?: "both" | "ac" | "dc";
voltage?: false | (MultiplierDivisor & Partial<ReportingConfigWithoutAttribute>);
Expand Down Expand Up @@ -1894,15 +1895,16 @@ function genericMeter(args?: MeterArgs) {
if (args.producedEnergy !== false) exposes.push(e.produced_energy().withAccess(ea.STATE_GET));
fromZigbee = [args.fzElectricalMeasurement ?? fz.electrical_measurement, args.fzMetering ?? fz.metering];
toZigbee = [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
toZigbee = [
const useMetering = args.power !== false && args.power?.cluster === "metering";
toZigbee = [

Then use it below (to avoid having the same condition twice.

tz.electrical_measurement_power,
args.reportingPowerType === "electrical" ? tz.electrical_measurement_power : tz.metering_power,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we base this off the cluster parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a good idea at the moment. I can't find a suitable parameter in the cluster. Do you have any good methods in mind?
Thanks.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
args.reportingPowerType === "electrical" ? tz.electrical_measurement_power : tz.metering_power,
cluster === "electrical" ? tz.electrical_measurement_power : tz.metering_power,

I mean this

Copy link
Contributor Author

@shinasys shinasys Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean adding an argument such as 'both_meter' in the args.cluster parameter?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you want to do now, maybe we can do something like this?

power?: false | (MultiplierDivisor & Partial<ReportingConfigWithoutAttribute> & {cluster?: "metering" | "electrical"});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see now. Thanks for clarifying. I will apply this immediately.

tz.acvoltage,
tz.accurrent,
tz.currentsummdelivered,
tz.currentsummreceived,
tz.frequency,
tz.powerfactor,
];
delete configureLookup.seMetering.power;
if (args.reportingPowerType === "electrical") delete configureLookup.seMetering.power;
else delete configureLookup.haElectricalMeasurement.power;
} else if (args.cluster === "metering" && args.type === "electricity") {
if (args.power !== false) exposes.push(e.power().withAccess(ea.STATE_GET));
if (args.energy !== false) exposes.push(e.energy().withAccess(ea.STATE_GET));
Expand Down Expand Up @@ -2038,6 +2040,7 @@ export function electricityMeter(args?: ElectricityMeterArgs): ModernExtend {
powerFactor: false,
status: false,
extendedStatus: false,
reportingPowerType: "electrical",
...args,
};
return genericMeter(args);
Expand Down