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

reportAttribute modernExtend #8965

Merged
merged 5 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/devices/dqsmart.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const m = require("zigbee-herdsman-converters/lib/modernExtend");
import * as m from "../lib/modernExtend";
import type {DefinitionWithExtend} from "../lib/types";

export const definitions: DefinitionWithExtend[] = [
Expand Down
30 changes: 24 additions & 6 deletions src/lib/modernExtend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ export interface BatteryArgs {
percentageReporting?: boolean;
voltageReportingConfig?: ReportingConfigWithoutAttribute;
voltageReporting?: boolean;
lowStatusReportingConfig?: ReportingConfigWithoutAttribute;
}
export function battery(args?: BatteryArgs): ModernExtend {
// biome-ignore lint/style/noParameterAssign: ignored using `--suppress`
Expand Down Expand Up @@ -433,18 +434,18 @@ export function battery(args?: BatteryArgs): ModernExtend {
},
];

const result: ModernExtend = {exposes, fromZigbee, toZigbee, isModernExtend: true};
const result: ModernExtend = {exposes, fromZigbee, toZigbee, configure: [], isModernExtend: true};

if (args.percentageReporting || args.voltageReporting) {
const configure: Configure[] = [];
if (args.percentageReporting) {
configure.push(setupConfigureForReporting("genPowerCfg", "batteryPercentageRemaining", args.percentageReportingConfig, ea.STATE_GET));
result.configure.push(
setupConfigureForReporting("genPowerCfg", "batteryPercentageRemaining", args.percentageReportingConfig, ea.STATE_GET),
);
}
if (args.voltageReporting) {
configure.push(setupConfigureForReporting("genPowerCfg", "batteryVoltage", args.voltageReportingConfig, ea.STATE_GET));
result.configure.push(setupConfigureForReporting("genPowerCfg", "batteryVoltage", args.voltageReportingConfig, ea.STATE_GET));
}
configure.push(configureSetPowerSourceWhenUnknown("Battery"));
result.configure = configure;
result.configure.push(configureSetPowerSourceWhenUnknown("Battery"));
}

if (args.voltageToPercentage || args.dontDividePercentage) {
Expand All @@ -454,6 +455,10 @@ export function battery(args?: BatteryArgs): ModernExtend {
result.meta = meta;
}

if (args.lowStatusReportingConfig) {
result.configure.push(setupConfigureForReporting("genPowerCfg", "batteryAlarmState", args.lowStatusReportingConfig, ea.STATE_GET));
}

return result;
}

Expand Down Expand Up @@ -2686,4 +2691,17 @@ export function bindCluster(args: {cluster: string | number; clusterType: "input
return {configure, isModernExtend: true};
}

export function reportAttribute(args: {
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this is used? Please remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently not used, but can be used along with/like bindCluster modernExtend https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/src/lib/modernExtend.ts#L2684C17

Copy link
Owner

Choose a reason for hiding this comment

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

If it is not used than I propose to remove it for now.

cluster: string | number;
attribute: ReportingConfigAttribute;
config: ReportingConfigWithoutAttribute;
access?: Access;
endpointNames?: string[];
}): ModernExtend {
const configure: Configure[] = [
setupConfigureForReporting(args.cluster, args.attribute, args.config, args.access || ea.STATE_GET, args.endpointNames),
];
return {configure, isModernExtend: true};
}

// #endregion