Fix disabling discovery of specific Home Assistant sensor not working. #5597

This commit is contained in:
Koen Kanters 2021-01-07 18:56:39 +01:00
parent 4c95265d5e
commit 2cf9657bd4
2 changed files with 21 additions and 1 deletions

View File

@ -586,8 +586,10 @@ class HomeAssistant extends Extension {
configs = JSON.parse(JSON.stringify(configs));
if (resolvedEntity.settings.homeassistant) {
const s = resolvedEntity.settings.homeassistant;
configs = configs.filter((config) => !s.hasOwnProperty(config.object_id) || s[config.object_id] != null);
configs.forEach((config) => {
const configOverride = resolvedEntity.settings.homeassistant[config.object_id];
const configOverride = s[config.object_id];
if (configOverride) {
config.object_id = configOverride.object_id || config.object_id;
config.type = configOverride.type || config.type;

View File

@ -529,6 +529,24 @@ describe('HomeAssistant extension', () => {
expect(topics).not.toContain('homeassistant/sensor/0x0017880104e45522/temperature/config')
});
it('Shouldnt discover sensor when set to null', async () => {
logger.error.mockClear();
settings.set(['devices', '0x0017880104e45522'], {
homeassistant: {humidity: null},
friendly_name: 'weather_sensor',
retain: false,
})
controller = new Controller(false);
await controller.start();
await flushPromises();
const topics = MQTT.publish.mock.calls.map((c) => c[0]);
expect(topics).not.toContain('homeassistant/sensor/0x0017880104e45522/humidity/config')
expect(topics).toContain('homeassistant/sensor/0x0017880104e45522/temperature/config')
});
it('Should discover devices with fan', async () => {
controller = new Controller(false);
await controller.start();