From 2fe085d409acfcc40613bb3c291fb014caf225ad Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Sat, 1 May 2021 17:01:59 +0200 Subject: [PATCH] Home Assistant: don't publish mocked values anymore replaced by unknown state in #7032 --- lib/extension/homeassistant.js | 31 ------------------------------- test/configure.test.js | 2 -- test/frontend.test.js | 8 ++++---- test/homeassistant.test.js | 8 ++++---- 4 files changed, 8 insertions(+), 41 deletions(-) diff --git a/lib/extension/homeassistant.js b/lib/extension/homeassistant.js index eab6af15..735a6979 100644 --- a/lib/extension/homeassistant.js +++ b/lib/extension/homeassistant.js @@ -494,37 +494,6 @@ class HomeAssistant extends Extension { await this.mqtt.publish(`${data.entity.name}/${key}`, value, {}); } } - - /** - * Publish a value for update_available (if not there yet) to prevent Home Assistant generating warnings of - * this value not being available. - */ - const supportsOTA = data.entity.definition && data.entity.definition.hasOwnProperty('ota'); - const mockedValues = [ - { - property: 'update_available', - condition: supportsOTA && this.legacyApi, - value: false, - }, - { - property: 'update', - condition: supportsOTA, - value: {state: 'idle'}, - }, - { - property: 'water_leak', - condition: data.entity.device && data.entity.definition && this.mapping[data.entity.definition.model] && - this.mapping[data.entity.definition.model].filter((c) => c.object_id === 'water_leak').length === 1, - value: false, - }, - ]; - - for (const entry of mockedValues) { - if (entry.condition && !data.messagePayload.hasOwnProperty(entry.property)) { - logger.debug(`Mocking '${entry.property}' value for Home Assistant`); - this.publishEntityState(data.entity.device.ieeeAddr, {[entry.property]: entry.value}); - } - } } onDeviceRenamed(device, homeAssisantRename) { diff --git a/test/configure.test.js b/test/configure.test.js index 389337c1..fd25837b 100644 --- a/test/configure.test.js +++ b/test/configure.test.js @@ -29,7 +29,6 @@ describe('Configure', () => { expectBulbConfigured = () => { const device = zigbeeHerdsman.devices.bulb; const endpoint1 = device.getEndpoint(1); - console.log(endpoint1.read.mock.calls); expect(endpoint1.read).toHaveBeenCalledTimes(2); expect(endpoint1.read).toHaveBeenCalledWith('lightingColorCtrl', ['colorCapabilities']); expect(endpoint1.read).toHaveBeenCalledWith('lightingColorCtrl', [ 'colorTempPhysicalMin', 'colorTempPhysicalMax' ]); @@ -38,7 +37,6 @@ describe('Configure', () => { expectBulbNotConfigured = () => { const device = zigbeeHerdsman.devices.bulb; const endpoint1 = device.getEndpoint(1); - console.log(endpoint1.read.mock.calls); expect(endpoint1.read).toHaveBeenCalledTimes(0); } diff --git a/test/frontend.test.js b/test/frontend.test.js index d23d6ebc..d105de37 100644 --- a/test/frontend.test.js +++ b/test/frontend.test.js @@ -120,14 +120,14 @@ describe('Frontend', () => { await mockWS.events.connection(mockWSClient.implementation); expect(mockWSClient.implementation.send).toHaveBeenCalledWith(stringify({topic: 'bridge/state', payload: 'online'})); - expect(mockWSClient.implementation.send).toHaveBeenCalledWith(stringify({topic:"remote", payload:{brightness:255, update:{state: "idle"}, update_available: false}})); + expect(mockWSClient.implementation.send).toHaveBeenCalledWith(stringify({topic:"remote", payload:{brightness:255}})); // Message MQTT.publish.mockClear(); mockWSClient.implementation.send.mockClear(); mockWSClient.events.message(stringify({topic: 'bulb_color/set', payload: {state: 'ON'}})) await flushPromises(); - expect(MQTT.publish).toHaveBeenCalledTimes(4); + expect(MQTT.publish).toHaveBeenCalledTimes(1); expect(MQTT.publish).toHaveBeenCalledWith( 'zigbee2mqtt/bulb_color', stringify({state: 'ON', linkquality: null}), @@ -140,7 +140,7 @@ describe('Frontend', () => { await flushPromises(); // Received message on socket - expect(mockWSClient.implementation.send).toHaveBeenCalledTimes(4); + expect(mockWSClient.implementation.send).toHaveBeenCalledTimes(1); expect(mockWSClient.implementation.send).toHaveBeenCalledWith(stringify({topic: 'bulb_color', payload: {state: 'ON', linkquality: null}})); // Shouldnt set when not ready @@ -155,7 +155,7 @@ describe('Frontend', () => { settings.set(['advanced'], {last_seen: 'ISO_8601'}); mockWS.implementation.clients.push(mockWSClient.implementation); await mockWS.events.connection(mockWSClient.implementation); - expect(mockWSClient.implementation.send).toHaveBeenCalledWith(stringify({topic:"remote", payload:{brightness:255, last_seen: "1970-01-01T00:00:01.000Z", update:{state: "idle"}, update_available: false}})); + expect(mockWSClient.implementation.send).toHaveBeenCalledWith(stringify({topic:"remote", payload:{brightness:255, last_seen: "1970-01-01T00:00:01.000Z"}})); }); it('onReques/onUpgrade', async () => { diff --git a/test/homeassistant.test.js b/test/homeassistant.test.js index 2b0bca6b..4f760bd2 100644 --- a/test/homeassistant.test.js +++ b/test/homeassistant.test.js @@ -834,13 +834,13 @@ describe('HomeAssistant extension', () => { await flushPromises(); expect(MQTT.publish).toHaveBeenCalledWith( 'zigbee2mqtt/bulb', - stringify({"state":"ON","brightness":50,"color_temp":370,"linkquality":99,"update":{"state":"idle"},"update_available":false}), + stringify({"state":"ON","brightness":50,"color_temp":370,"linkquality":99}), { retain: true, qos: 0 }, expect.any(Function) ); expect(MQTT.publish).toHaveBeenCalledWith( 'zigbee2mqtt/remote', - stringify({"action":null,"battery":null,"brightness":255,"linkquality":null,"update":{"state":"idle"},"update_available":false}), + stringify({"action":null,"battery":null,"brightness":255,"linkquality":null}), { retain: true, qos: 0 }, expect.any(Function) ); @@ -860,13 +860,13 @@ describe('HomeAssistant extension', () => { await flushPromises(); expect(MQTT.publish).toHaveBeenCalledWith( 'zigbee2mqtt/bulb', - stringify({"state":"ON","brightness":50,"color_temp":370,"linkquality":99,"update_available":false,"update":{"state":"idle"}}), + stringify({"state":"ON","brightness":50,"color_temp":370,"linkquality":99}), { retain: true, qos: 0 }, expect.any(Function) ); expect(MQTT.publish).toHaveBeenCalledWith( 'zigbee2mqtt/remote', - stringify({"action":null,"battery":null,"brightness":255,"linkquality":null,"update":{"state":"idle"},"update_available":false}), + stringify({"action":null,"battery":null,"brightness":255,"linkquality":null}), { retain: true, qos: 0 }, expect.any(Function) );