Skip to content

Commit e12576c

Browse files
committed
fix: Fix power source unknown for some lights and switches Koenkk/zigbee2mqtt#24074
1 parent 41be85d commit e12576c

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/lib/modernExtend.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import {
3232
addActionGroup,
3333
assertNumber,
3434
batteryVoltageToPercentage,
35-
configureSetBatteryPowerSourceWhenUnknown,
3635
flatten,
3736
getEndpointName,
3837
getFromLookup,
@@ -49,6 +48,18 @@ import {
4948
precisionRound,
5049
} from './utils';
5150

51+
const NS = 'zhc:modernextend';
52+
53+
function configureSetPowerSourceWhenUnknown(powerSource: 'Battery' | 'Mains (single phase)'): Configure {
54+
return async (device: Zh.Device): Promise<void> => {
55+
if (!device.powerSource) {
56+
logger.debug(`Device has no power source, forcing to '${powerSource}'`, NS);
57+
device.powerSource = powerSource;
58+
device.save();
59+
}
60+
};
61+
}
62+
5263
function getEndpointsWithCluster(device: Zh.Device, cluster: string | number, type: 'input' | 'output') {
5364
if (!device.endpoints) {
5465
throw new Error(device.ieeeAddr + ' ' + device.endpoints);
@@ -395,7 +406,7 @@ export function battery(args?: BatteryArgs): ModernExtend {
395406
if (args.voltageReporting) {
396407
configure.push(setupConfigureForReporting('genPowerCfg', 'batteryVoltage', args.voltageReportingConfig, ea.STATE_GET));
397408
}
398-
configure.push(configureSetBatteryPowerSourceWhenUnknown);
409+
configure.push(configureSetPowerSourceWhenUnknown('Battery'));
399410
result.configure = configure;
400411
}
401412

@@ -505,6 +516,7 @@ export function onOff(args?: OnOffArgs): ModernExtend {
505516
}
506517
}
507518
},
519+
configureSetPowerSourceWhenUnknown('Mains (single phase)'),
508520
];
509521
}
510522
return result;
@@ -1046,6 +1058,7 @@ export function light(args?: LightArgs): ModernExtend {
10461058
}
10471059
}
10481060
},
1061+
configureSetPowerSourceWhenUnknown('Mains (single phase)'),
10491062
];
10501063

10511064
const result: ModernExtend = {exposes, fromZigbee, toZigbee, configure, meta, isModernExtend: true};

src/lib/utils.ts

-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as globalStore from './store';
66
import {
77
BatteryLinearVoltage,
88
BatteryNonLinearVoltage,
9-
Configure,
109
Definition,
1110
Expose,
1211
Fz,
@@ -712,14 +711,6 @@ export function isLightExpose(expose: Expose): expose is Light {
712711
return expose?.type === 'light';
713712
}
714713

715-
export const configureSetBatteryPowerSourceWhenUnknown: Configure = async (device) => {
716-
if (!device.powerSource) {
717-
logger.debug(`Device has no power source, forcing to 'Battery'`, NS);
718-
device.powerSource = 'Battery';
719-
device.save();
720-
}
721-
};
722-
723714
exports.noOccupancySince = noOccupancySince;
724715
exports.getOptions = getOptions;
725716
exports.isLegacyEnabled = isLegacyEnabled;

0 commit comments

Comments
 (0)