Skip to content

Commit

Permalink
fix event
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk authored and mundschenk-at committed Oct 26, 2024
1 parent b44fe09 commit 9681bb2
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/homeassistant.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,48 @@ describe('HomeAssistant extension', () => {
{retain: true, qos: 1},
expect.any(Function),
);

payload = {
availability: [{topic: 'zigbee2mqtt/bridge/state'}],
device: {
identifiers: ['zigbee2mqtt_0x0017880104e45520'],
manufacturer: 'Aqara',
model: 'Wireless mini switch (WXKG11LM)',
name: 'button',
sw_version: null,
via_device: 'zigbee2mqtt_bridge_0x00124b00120144ae',
},
event_types: ['single', 'double', 'triple', 'quadruple', 'hold', 'release'],
icon: 'mdi:gesture-double-tap',
json_attributes_topic: 'zigbee2mqtt/button',
name: 'Action',
object_id: 'button_action',
origin: origin,
state_topic: 'zigbee2mqtt/button',
unique_id: '0x0017880104e45520_action_zigbee2mqtt',
// Needs to be updated whenever one of the ACTION_*_PATTERN constants changes.
value_template:
'{%- set buttons = value_json.action|regex_findall_index(^(?P<button>[a-z]+)_(?P<action>(?:press|hold)(?:_release)?)$) -%}{%- set scenes = value_json.action|regex_findall_index(^(?P<action>recall|scene)_(?P<scene>[0-2][0-9]{0,2})$) -%}{%- set regions = value_json.action|regex_findall_index(^region_(?P<region>[1-9]|10)_(?P<action>enter|leave|occupied|unoccupied)$) -%}{%- if buttons -%}\n {%- set d = dict(event_type = "{{buttons[1]}}", button = "{{buttons[0]}}_button" -%}\n{%- elif scenes -%}\n {%- set d = dict(event_type = "{{scenes[0]}}", scene = "{{scenes[1]}}" -%}\n{%- elif regions -%}\n {%- set d = dict(event_type = "region_{{regions[1]}}", region = "{{regions[0]}}" -%}\n{%- else -%}\n {%- set d = dict(event_type = "{{value_json.action}}" ) -%}\n{%- endif -%}\n{{d|to_json}}',
};

expect(MQTT.publish).toHaveBeenCalledWith(
'homeassistant/event/0x0017880104e45520/action/config',
stringify(payload),
{retain: true, qos: 1},
expect.any(Function),
);
});

it.each([
['recall_1', {action: 'recall', scene: '1'}],
['on', {action: 'on'}],
['on_1', {action: 'on_1'}],
['release_left', {action: 'release_left'}],
['region_1_enter', {action: 'enter', region: '1'}],
['region_enter', {action: 'region_enter', region: 'wildcard'}],
['left_press', {action: 'press', button: 'left'}],
])('parseActionValue', (action, expected) => {
expect(extension.parseActionValue(action)).toStrictEqual(expected);
});

it('Should not discovery devices which are already discovered', async () => {
Expand Down

0 comments on commit 9681bb2

Please sign in to comment.