Skip to content

Commit

Permalink
fix: Fix IKEA E2103 battery % multiplied by 2 Koenkk/zigbee2mqtt#22528
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed May 10, 2024
1 parent 4182889 commit 5032c2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/devices/ikea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ const definitions: Definition[] = [
ikeaConfigureGenPollCtrl(),
windowCovering({controls: ['lift']}),
identify(),
battery({dontDividePercentage: true}),
ikeaBattery(),
ikeaOta(),
],
},
Expand Down
20 changes: 13 additions & 7 deletions src/lib/ikea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,21 @@ export function ikeaBattery(): ModernExtend {
if (msg.data.hasOwnProperty('batteryPercentageRemaining') && (msg.data['batteryPercentageRemaining'] < 255)) {
// Some devices do not comply to the ZCL and report a
// batteryPercentageRemaining of 100 when the battery is full (should be 200).
//
// IKEA corrected this on newer remote fw version, but many people are still
// 2.2.010 which is the last version supporting group bindings. We try to be
// smart and pick the correct one for IKEA remotes.
let dividePercentage = true;
// If softwareBuildID is below 2.4.0 it should not be divided
if (semver.lt(meta.device.softwareBuildID, '2.4.0', true)) {
dividePercentage = false;
if (model.model === 'E2103') {
if (semver.lt(meta.device.softwareBuildID, '24.4.13', true)) {
dividePercentage = false;
}
} else {
// IKEA corrected this on newer remote fw version, but many people are still
// 2.2.010 which is the last version supporting group bindings. We try to be
// smart and pick the correct one for IKEA remotes.
// If softwareBuildID is below 2.4.0 it should not be divided
if (semver.lt(meta.device.softwareBuildID, '2.4.0', true)) {
dividePercentage = false;
}
}

let percentage = msg.data['batteryPercentageRemaining'];
percentage = dividePercentage ? percentage / 2 : percentage;
payload.battery = precisionRound(percentage, 2);
Expand Down

0 comments on commit 5032c2a

Please sign in to comment.