@@ -32,7 +32,6 @@ import {
32
32
addActionGroup ,
33
33
assertNumber ,
34
34
batteryVoltageToPercentage ,
35
- configureSetBatteryPowerSourceWhenUnknown ,
36
35
flatten ,
37
36
getEndpointName ,
38
37
getFromLookup ,
@@ -49,6 +48,18 @@ import {
49
48
precisionRound ,
50
49
} from './utils' ;
51
50
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
+
52
63
function getEndpointsWithCluster ( device : Zh . Device , cluster : string | number , type : 'input' | 'output' ) {
53
64
if ( ! device . endpoints ) {
54
65
throw new Error ( device . ieeeAddr + ' ' + device . endpoints ) ;
@@ -395,7 +406,7 @@ export function battery(args?: BatteryArgs): ModernExtend {
395
406
if ( args . voltageReporting ) {
396
407
configure . push ( setupConfigureForReporting ( 'genPowerCfg' , 'batteryVoltage' , args . voltageReportingConfig , ea . STATE_GET ) ) ;
397
408
}
398
- configure . push ( configureSetBatteryPowerSourceWhenUnknown ) ;
409
+ configure . push ( configureSetPowerSourceWhenUnknown ( 'Battery' ) ) ;
399
410
result . configure = configure ;
400
411
}
401
412
@@ -505,6 +516,7 @@ export function onOff(args?: OnOffArgs): ModernExtend {
505
516
}
506
517
}
507
518
} ,
519
+ configureSetPowerSourceWhenUnknown ( 'Mains (single phase)' ) ,
508
520
] ;
509
521
}
510
522
return result ;
@@ -1046,6 +1058,7 @@ export function light(args?: LightArgs): ModernExtend {
1046
1058
}
1047
1059
}
1048
1060
} ,
1061
+ configureSetPowerSourceWhenUnknown ( 'Mains (single phase)' ) ,
1049
1062
] ;
1050
1063
1051
1064
const result : ModernExtend = { exposes, fromZigbee, toZigbee, configure, meta, isModernExtend : true } ;
0 commit comments