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

fix: Replace defaultSendRequestWhen with pendingRequestTimeout #6865

Merged
merged 6 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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/adeo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ const definitions: Definition[] = [
toZigbee: [tz.warning],
exposes: [e.warning(), e.battery(), e.battery_low(), e.tamper()],
configure: async (device, coordinatorEndpoint, logger) => {
device.defaultSendRequestWhen = 'immediate';
device.pendingRequestTimeout = 0;
device.save();
await device.getEndpoint(1).unbind('genPollCtrl', coordinatorEndpoint);
},
Expand Down
2 changes: 1 addition & 1 deletion src/devices/bosch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ const definitions: Definition[] = [
await reporting.bind(endpoint, coordinatorEndpoint, ['genPowerCfg', 'ssIasZone', 'ssIasWd', 'genBasic']);
await reporting.batteryVoltage(endpoint);
await endpoint.read(0x0502, [0xa000, 0xa001, 0xa002, 0xa003, 0xa004, 0xa005], manufacturerOptions);
device.defaultSendRequestWhen = 'immediate';
device.pendingRequestTimeout = 0;
device.save();
await endpoint.unbind('genPollCtrl', coordinatorEndpoint);
},
Expand Down
4 changes: 2 additions & 2 deletions src/devices/xiaomi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import extend from '../lib/extend';
import {
light, numeric, binary, enumLookup, forceDeviceType,
temperature, humidity, forcePowerSource, quirkAddEndpointCluster,
quirkSendWhenActive,
quirkPendingRequestTimeout,
} from '../lib/modernExtend';
const e = exposes.presets;
const ea = exposes.access;
Expand Down Expand Up @@ -3121,7 +3121,7 @@ const definitions: Definition[] = [
meta: {battery: {voltageToPercentage: '3V_2850_3000'}},
exposes: [e.device_temperature(), e.battery(), e.battery_voltage()],
extend: [
quirkSendWhenActive(),
quirkPendingRequestTimeout('1_HOUR'),
quirkAddEndpointCluster({
endpointID: 1,
inputClusters: [
Expand Down
13 changes: 7 additions & 6 deletions src/lib/modernExtend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ function getEndpointsWithInputCluster(device: Zh.Device, cluster: string | numbe
return endpoints;
}

const reportingConfigTimeLookup = {
const timeLookup = {
'1_HOUR': 3600,
'MAX': 65000,
'30_MINUTES': 1800,
'10_SECONDS': 10,
};

type ReportingConfigTime = number | keyof typeof reportingConfigTimeLookup;
type ReportingConfigTime = number | keyof typeof timeLookup;
type ReportingConfigAttribute = string | number | {ID: number, type: number};
type ReportingConfig = {min: ReportingConfigTime, max: ReportingConfigTime, change: number | [number, number], attribute: ReportingConfigAttribute}
export type ReportingConfigWithoutAttribute = Omit<ReportingConfig, 'attribute'>;

function convertReportingConfigTime(time: ReportingConfigTime): number {
if (isString(time)) {
if (!(time in reportingConfigTimeLookup)) throw new Error(`Reporting time '${time}' is unknown`);
return reportingConfigTimeLookup[time];
if (!(time in timeLookup)) throw new Error(`Reporting time '${time}' is unknown`);
return timeLookup[time];
} else {
return time;
}
Expand Down Expand Up @@ -569,9 +569,10 @@ export function quirkAddEndpointCluster(args: QuirkAddEndpointClusterArgs): Mode
return {configure, isModernExtend: true};
}

export function quirkSendWhenActive(): ModernExtend {
export function quirkPendingRequestTimeout(timeout: keyof typeof timeLookup): ModernExtend {
const timeoutMs = timeLookup[timeout] * 1000;
const configure: Configure = async (device, coordinatorEndpoint, logger) => {
device.defaultSendRequestWhen = 'active';
device.pendingRequestTimeout = timeoutMs;
device.save();
};

Expand Down