fix(ignore): fix 5fcf295ab8

This commit is contained in:
Koen Kanters committed 2024-07-25 21:59:40 +02:00
1 parent 5fcf295ab8
commit d9ba4524e4
3 files changed
+16 -7

No files matched your search

+11 -6
View File
@@ -25,7 +25,6 @@ export default class Frontend extends Extension {
private sslCert = settings.get().frontend.ssl_cert;
private sslKey = settings.get().frontend.ssl_key;
private authToken = settings.get().frontend.auth_token;
private retainedMessages = new Map();
private server: http.Server;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private fileServer: RequestHandler;
@@ -127,8 +126,17 @@ export default class Frontend extends Extension {
}
});
for (const [key, value] of this.retainedMessages) {
ws.send(stringify({topic: key, payload: value}));
for (const [topic, payload] of Object.entries(this.mqtt.retainedMessages)) {
/* istanbul ignore else */
if (topic.startsWith(`${this.mqttBaseTopic}/`)) {
ws.send(
stringify({
// Send topic without base_topic
topic: topic.substring(this.mqttBaseTopic.length + 1),
payload: utils.parseJSON(payload.payload, payload.payload),
}),
);
}
}
for (const device of this.zigbee.devices(false)) {
@@ -153,9 +161,6 @@ export default class Frontend extends Extension {
// Send topic without base_topic
const topic = data.topic.substring(this.mqttBaseTopic.length + 1);
const payload = utils.parseJSON(data.payload, data.payload);
if (data.options.retain) {
this.retainedMessages.set(topic, payload);
}
for (const client of this.wss.clients) {
/* istanbul ignore else */
+1 -1
View File
@@ -17,7 +17,7 @@ export default class MQTT {
private eventBus: EventBus;
private initialConnect = true;
private republishRetainedTimer: NodeJS.Timeout;
private retainedMessages: {
public retainedMessages: {
[s: string]: {payload: string; options: MQTTOptions; skipLog: boolean; skipReceive: boolean; topic: string; base: string};
} = {};
+4
View File
@@ -243,6 +243,10 @@ describe('Frontend', () => {
mockWS.implementation.clients.push(mockWSClient.implementation);
await mockWS.events.connection(mockWSClient.implementation);
const allTopics = mockWSClient.implementation.send.mock.calls.map((m) => JSON.parse(m).topic);
expect(allTopics).toContain('bridge/devices');
expect(allTopics).toContain('bridge/info');
expect(allTopics).toContain('bridge/config');
expect(mockWSClient.implementation.send).toHaveBeenCalledWith(stringify({topic: 'bridge/state', payload: 'online'}));
expect(mockWSClient.implementation.send).toHaveBeenCalledWith(stringify({topic: 'remote', payload: {brightness: 255}}));