MCPcopy
hub / github.com/Koenkk/zigbee2mqtt / on

Method on

lib/eventBus.ts:245–263  ·  view source on GitHub ↗
(event: K, callback: EventBusListener<K>, key: ListenerKey)

Source from the content-addressed store, hash-verified

243 }
244
245 private on<K extends keyof EventBusMap>(event: K, callback: EventBusListener<K>, key: ListenerKey): void {
246 if (!this.callbacksByExtension.has(key.constructor.name)) {
247 this.callbacksByExtension.set(key.constructor.name, []);
248 }
249
250 const wrappedCallback = async (...args: never[]): Promise<void> => {
251 try {
252 await callback(...args);
253 } catch (error) {
254 logger.error(`EventBus error '${key.constructor.name}/${event}': ${(error as Error).message}`);
255 // biome-ignore lint/style/noNonNullAssertion: always Error
256 logger.debug((error as Error).stack!);
257 }
258 };
259
260 // biome-ignore lint/style/noNonNullAssertion: just created if wasn't valid
261 this.callbacksByExtension.get(key.constructor.name)!.push({event, callback: wrappedCallback});
262 this.emitter.on(event, wrappedCallback as EventBusListener<K>);
263 }
264
265 public removeListeners(key: ListenerKey): void {
266 const callbacks = this.callbacksByExtension.get(key.constructor.name);

Callers 15

onAdapterDisconnectedMethod · 0.95
onPermitJoinChangedMethod · 0.95
onEntityRenamedMethod · 0.95
onEntityRemovedMethod · 0.95
onLastSeenChangedMethod · 0.95
onDeviceAnnounceMethod · 0.95
onDeviceInterviewMethod · 0.95
onDeviceJoinedMethod · 0.95
onExposesChangedMethod · 0.95
onDeviceLeaveMethod · 0.95

Calls 2

setMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected