mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-26 20:50:07 +00:00
fix: Only send JSON state over WebSocket (#27225)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import * as data from "../mocks/data";
|
||||
import {mockLogger} from "../mocks/logger";
|
||||
import {mockMQTTPublishAsync} from "../mocks/mqtt";
|
||||
import {events as mockMQTTEvents, mockMQTTPublishAsync} from "../mocks/mqtt";
|
||||
import {type EventHandler, flushPromises} from "../mocks/utils";
|
||||
import {devices} from "../mocks/zigbeeHerdsman";
|
||||
import {devices, events as mockZHEvents} from "../mocks/zigbeeHerdsman";
|
||||
|
||||
import path from "node:path";
|
||||
|
||||
@@ -224,7 +224,7 @@ describe("Extension: Frontend", () => {
|
||||
await controller.stop();
|
||||
});
|
||||
|
||||
it("Websocket interaction", async () => {
|
||||
it("onlythis Websocket interaction", async () => {
|
||||
controller = new Controller(vi.fn(), vi.fn());
|
||||
await controller.start();
|
||||
mockWSClient.readyState = "open";
|
||||
@@ -268,13 +268,27 @@ describe("Extension: Frontend", () => {
|
||||
expect(mockWSClient.send).toHaveBeenCalledWith(
|
||||
stringify({
|
||||
topic: "bulb_color",
|
||||
payload: {
|
||||
state: "ON",
|
||||
effect: null,
|
||||
power_on_behavior: null,
|
||||
linkquality: null,
|
||||
update: {state: null, installed_version: -1, latest_version: -1},
|
||||
},
|
||||
payload: {state: "ON"},
|
||||
}),
|
||||
);
|
||||
|
||||
// Should publish bridge messages
|
||||
await mockZHEvents.deviceJoined({device: devices.bulb});
|
||||
await flushPromises();
|
||||
expect(mockWSClient.send).toHaveBeenCalledWith(
|
||||
stringify({payload: {data: {friendly_name: "bulb", ieee_address: "0x000b57fffec6a5b2"}, type: "device_joined"}, topic: "bridge/event"}),
|
||||
);
|
||||
|
||||
// Should send JSON state event when `output: attribute`
|
||||
mockWSClient.send.mockClear();
|
||||
settings.set(["advanced", "output"], "attribute");
|
||||
await mockMQTTEvents.message("zigbee2mqtt/bulb_color/set", stringify({brightness: 90}));
|
||||
await flushPromises();
|
||||
expect(mockWSClient.send).toHaveBeenCalledTimes(1);
|
||||
expect(mockWSClient.send).toHaveBeenCalledWith(
|
||||
stringify({
|
||||
topic: "bulb_color",
|
||||
payload: {state: "ON", brightness: 90},
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user