From 7fbbbc3b17f7f1cc6e8ada0e70d57287ac1a9bf2 Mon Sep 17 00:00:00 2001 From: Luan Taraschi <130802253+luantaraschi@users.noreply.github.com> Date: Wed, 26 Aug 2026 07:02:15 -0300 Subject: [PATCH] fix: Preserve duration in state (#32900) Co-authored-by: Koen Kanters --- lib/state.ts | 1 - test/controller.test.ts | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/state.ts b/lib/state.ts index 514615dcb..14c253fef 100644 --- a/lib/state.ts +++ b/lib/state.ts @@ -22,7 +22,6 @@ const CACHE_IGNORE_PROPERTIES = [ "no_occupancy_since", "step_mode", "transition_time", - "duration", "elapsed", "from_side", "to_side", diff --git a/test/controller.test.ts b/test/controller.test.ts index 318784ebe..a5fbcbf51 100644 --- a/test/controller.test.ts +++ b/test/controller.test.ts @@ -1100,6 +1100,28 @@ describe("Controller", () => { expect(mockMQTTPublishAsync).toHaveBeenCalledWith("zigbee2mqtt/bulb", stringify({state: "ON", brightness: 200}), {qos: 0, retain: true}); }); + it("Publish entity state caches a duration reported by the device", async () => { + await controller.start(); + mockMQTTPublishAsync.mockClear(); + + const device = getZ2MDevice("bulb"); + await controller.publishEntityState(device, {state: "ON", duration: 30}); + await flushPromises(); + + expect(controller.state.get(device)).toStrictEqual({brightness: 50, color_temp: 370, linkquality: 99, state: "ON", duration: 30}); + }); + + it("Publish entity state keeps an action_duration out of the cache", async () => { + await controller.start(); + mockMQTTPublishAsync.mockClear(); + + const device = getZ2MDevice("bulb"); + await controller.publishEntityState(device, {state: "ON", action_duration: 1500}); + await flushPromises(); + + expect(controller.state.get(device)).toStrictEqual({brightness: 50, color_temp: 370, linkquality: 99, state: "ON"}); + }); + it("Publish entity state attribute_json output filtered cache", async () => { await controller.start(); settings.set(["advanced", "output"], "attribute_and_json");