Skip to content

Commit

Permalink
fix: Fix IKEA E2001/E2002 configure Koenkk/zigbee2mqtt#22458
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed May 7, 2024
1 parent 4a02de0 commit ec20f70
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/devices/ikea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
linkQuality, deviceEndpoints, deviceAddCustomCluster, bindCluster,
} from '../lib/modernExtend';
import {
ikeaConfigureRemote, ikeaLight, ikeaOta,
ikeaConfigureRemote, ikeaLight, ikeaOta, ikeaConfigureStyrbar,
ikeaBattery, ikeaAirPurifier, legacy as ikeaLegacy,
ikeaVoc, ikeaConfigureGenPollCtrl, tradfriOccupancy,
tradfriRequestedBrightness,
Expand Down Expand Up @@ -782,12 +782,12 @@ const definitions: Definition[] = [
vendor: 'IKEA',
description: 'STYRBAR remote control',
extend: [
ikeaConfigureRemote(),
ikeaConfigureStyrbar(),
identify({isSleepy: true}),
styrbarCommandOn(),
commandsOnOff({commands: ['off']}),
commandsLevelCtrl({commands: ['brightness_move_up', 'brightness_move_down', 'brightness_stop']}),
ikeaArrowClick({styrbar: true}),
commandsOnOff({commands: ['off'], bind: false}),
commandsLevelCtrl({commands: ['brightness_move_up', 'brightness_move_down', 'brightness_stop'], bind: false}),
ikeaArrowClick({styrbar: true, bind: false}),
ikeaBattery(),
ikeaOta(),
],
Expand Down
27 changes: 20 additions & 7 deletions src/lib/ikea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ export function ikeaBattery(): ModernExtend {
return {exposes, fromZigbee, toZigbee, configure, isModernExtend: true};
}

export function ikeaConfigureStyrbar(): ModernExtend {
const configure: Configure[] = [
async (device, coordinatorEndpoint, definition) => {
// https://github.com/Koenkk/zigbee2mqtt/issues/15725
if (semver.gte(device.softwareBuildID, '2.4.0', true)) {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'genLevelCtrl', 'genScenes']);
}
},
];

return {configure, isModernExtend: true};
}

export function ikeaConfigureRemote(): ModernExtend {
const configure: Configure[] = [
async (device, coordinatorEndpoint, definition) => {
Expand Down Expand Up @@ -551,11 +565,8 @@ export function ikeaDotsClick(args: {actionLookup?: KeyValue, dotsPrefix?: boole
return {exposes, fromZigbee, configure, isModernExtend: true};
}

export function ikeaArrowClick(args?: {styrbar: boolean}): ModernExtend {
args = {
styrbar: false,
...args,
};
export function ikeaArrowClick(args?: {styrbar?: boolean, bind?: boolean}): ModernExtend {
args = {styrbar: false, bind: true, ...args};
const actions = ['arrow_left_click', 'arrow_left_hold', 'arrow_left_release',
'arrow_right_click', 'arrow_right_hold', 'arrow_right_release'];
const exposes: Expose[] = [presets.action(actions)];
Expand Down Expand Up @@ -601,9 +612,11 @@ export function ikeaArrowClick(args?: {styrbar: boolean}): ModernExtend {
},
];

const configure: Configure[] = [setupConfigureForBinding('genScenes', 'output')];
const result: ModernExtend = {exposes, fromZigbee, isModernExtend: true};

return {exposes, fromZigbee, configure, isModernExtend: true};
if (args.bind) result.configure = [setupConfigureForBinding('genScenes', 'output')];

return result;
}

export function ikeaMediaCommands(): ModernExtend {
Expand Down

0 comments on commit ec20f70

Please sign in to comment.