From 515599ad139c27ddf9a776a5023f9916f1273456 Mon Sep 17 00:00:00 2001 From: Koen Kanters Date: Wed, 14 Jul 2021 19:47:02 +0200 Subject: [PATCH] Discover color temperature range for Home Assistant groups. https://github.com/Koenkk/zigbee2mqtt/issues/8032 --- lib/extension/homeassistant.js | 11 +++++++---- test/homeassistant.test.js | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/extension/homeassistant.js b/lib/extension/homeassistant.js index de51510621..7aa97dc93d 100644 --- a/lib/extension/homeassistant.js +++ b/lib/extension/homeassistant.js @@ -108,10 +108,13 @@ class HomeAssistant extends Extension { discoveryEntry.discovery_payload.supported_color_modes = colorModes; } - if (entityType === 'device' && hasColorTemp) { - const colorTemp = firstExpose.features.find((e) => e.name === 'color_temp'); - discoveryEntry.discovery_payload.max_mireds = colorTemp.value_max; - discoveryEntry.discovery_payload.min_mireds = colorTemp.value_min; + if (hasColorTemp) { + const colorTemps = exposes.map((expose) => expose.features.find((e) => e.name === 'color_temp')) + .filter((e) => e); + const max = Math.max(...colorTemps.map((e) => e.value_max)); + const min = Math.min(...colorTemps.map((e) => e.value_min)); + discoveryEntry.discovery_payload.max_mireds = max; + discoveryEntry.discovery_payload.min_mireds = min; } const effect = definition && definition.exposes.find((e) => e.type === 'enum' && e.name === 'effect'); diff --git a/test/homeassistant.test.js b/test/homeassistant.test.js index 2bf37af44c..8f92f28228 100644 --- a/test/homeassistant.test.js +++ b/test/homeassistant.test.js @@ -69,6 +69,8 @@ describe('HomeAssistant extension', () => { "name":"ha_discovery_group", "sw_version":this.version, }, + "max_mireds": 500, + "min_mireds": 150, "json_attributes_topic":"zigbee2mqtt/ha_discovery_group", "name":"ha_discovery_group", "schema":"json", @@ -1713,6 +1715,8 @@ describe('HomeAssistant extension', () => { "sw_version":this.version, }, "json_attributes_topic":"zigbee2mqtt/ha_discovery_group", + "max_mireds": 500, + "min_mireds": 150, "name":"ha_discovery_group", "schema":"json", "state_topic":"zigbee2mqtt/ha_discovery_group",