Skip to content

Commit

Permalink
fix(ignore): Update zigbee-herdsman-converters to 20.53.0 (#24906)
Browse files Browse the repository at this point in the history
Co-authored-by: Ilya Kirov <kirovilya@gmail.com>
  • Loading branch information
Koenkk and kirovilya authored Nov 24, 2024
1 parent ca64935 commit 790373b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
5 changes: 5 additions & 0 deletions lib/eventBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ export default class EventBus {
this.on('stateChange', callback, key);
}

public emitExposesAndDevicesChanged(device: Device): void {
this.emitDevicesChanged();
this.emitExposesChanged({device});
}

private on<K extends keyof EventBusMap>(event: K, callback: EventBusListener<K>, key: ListenerKey): void {
if (!this.callbacksByExtension[key.constructor.name]) {
this.callbacksByExtension[key.constructor.name] = [];
Expand Down
6 changes: 4 additions & 2 deletions lib/extension/onEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ export default class OnEvent extends Extension {
private async callOnEvent(device: Device, type: zhc.OnEventType, data: KeyValue): Promise<void> {
if (device.options.disabled) return;
const state = this.state.get(device);
await zhc.onEvent(type, data, device.zh);
const deviceExposesChanged = (): void => this.eventBus.emitExposesAndDevicesChanged(data.device);

await zhc.onEvent(type, data, device.zh, {deviceExposesChanged});

if (device.definition?.onEvent) {
const options: KeyValue = device.options;
await device.definition.onEvent(type, data, device.zh, options, state);
await device.definition.onEvent(type, data, device.zh, options, state, {deviceExposesChanged});
}
}
}
10 changes: 5 additions & 5 deletions lib/extension/receive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ export default class Receive extends Extension {
}
};

const deviceExposesChanged = (): void => {
this.eventBus.emitDevicesChanged();
this.eventBus.emitExposesChanged({device: data.device});
const meta = {
device: data.device.zh,
logger,
state: this.state.get(data.device),
deviceExposesChanged: (): void => this.eventBus.emitExposesAndDevicesChanged(data.device),
};

const meta = {device: data.device.zh, logger, state: this.state.get(data.device), deviceExposesChanged: deviceExposesChanged};
let payload: KeyValue = {};
for (const converter of converters) {
try {
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"winston-transport": "^4.9.0",
"ws": "^8.18.0",
"zigbee-herdsman": "2.1.9",
"zigbee-herdsman-converters": "20.52.0",
"zigbee-herdsman-converters": "20.53.0",
"zigbee2mqtt-frontend": "0.7.5"
},
"devDependencies": {
Expand Down
20 changes: 18 additions & 2 deletions test/onEvent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,30 @@ describe('On event', () => {
await zigbeeHerdsman.events.deviceAnnounce({device});
await flushPromises();
expect(mockOnEvent).toHaveBeenCalledTimes(1);
expect(mockOnEvent).toHaveBeenCalledWith('deviceAnnounce', {device}, device, settings.getDevice(device.ieeeAddr), {});
expect(mockOnEvent).toHaveBeenCalledWith(
'deviceAnnounce',
{device},
device,
settings.getDevice(device.ieeeAddr),
{},
{
deviceExposesChanged: expect.any(Function),
},
);

// Test deviceExposesChanged
MQTT.publish.mockClear();
console.log(mockOnEvent.mock.calls[0][5].deviceExposesChanged());
expect(MQTT.publish.mock.calls[0][0]).toStrictEqual('zigbee2mqtt/bridge/devices');
});

it('Should call index onEvent with zigbee event', async () => {
zigbeeHerdsmanConverters.onEvent.mockClear();
await zigbeeHerdsman.events.deviceAnnounce({device});
await flushPromises();
expect(zigbeeHerdsmanConverters.onEvent).toHaveBeenCalledTimes(1);
expect(zigbeeHerdsmanConverters.onEvent).toHaveBeenCalledWith('deviceAnnounce', {device}, device);
expect(zigbeeHerdsmanConverters.onEvent).toHaveBeenCalledWith('deviceAnnounce', {device}, device, {
deviceExposesChanged: expect.any(Function),
});
});
});

0 comments on commit 790373b

Please sign in to comment.