mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-10-22 22:11:22 +00:00
Fix Home Assistant "KeyError: 'color_mode'" for brightness only lights. https://github.com/Koenkk/zigbee2mqtt/issues/7220
This commit is contained in:
1 parent
7eeaeafbd0
commit
f27e5efe0f
1 file changed
+12
-20
@@ -86,32 +86,12 @@ class HomeAssistant extends Extension {
|
||||
const colorHS = expose.features.find((e) => e.name === 'color_hs');
|
||||
const brightness = expose.features.find((e) => e.name === 'brightness');
|
||||
const colorTemp = expose.features.find((e) => e.name === 'color_temp');
|
||||
const colorModes = [];
|
||||
// Ignore else, all bulbs support atleast brightness
|
||||
/* istanbul ignore else */
|
||||
if (colorTemp || colorHS || colorXY) {
|
||||
if (colorXY) {
|
||||
colorModes.push('xy');
|
||||
} else if (colorHS) {
|
||||
colorModes.push('hs');
|
||||
}
|
||||
|
||||
if (colorTemp) {
|
||||
colorModes.push('color_temp');
|
||||
}
|
||||
} else if (brightness) {
|
||||
colorModes.push('brightness');
|
||||
} else {
|
||||
colorModes.push('onoff');
|
||||
}
|
||||
|
||||
discoveryEntry = {
|
||||
type: 'light',
|
||||
object_id: expose.endpoint ? `light_${expose.endpoint}` : 'light',
|
||||
discovery_payload: {
|
||||
brightness: !!brightness,
|
||||
color_mode: true,
|
||||
supported_color_modes: colorModes,
|
||||
schema: 'json',
|
||||
command_topic: true,
|
||||
brightness_scale: 254,
|
||||
@@ -120,6 +100,18 @@ class HomeAssistant extends Extension {
|
||||
},
|
||||
};
|
||||
|
||||
const colorModes = [
|
||||
colorXY ? 'xy' : null,
|
||||
!colorXY && colorHS ? 'hs' : null,
|
||||
colorTemp ? 'color_temp' : null,
|
||||
].filter((c) => c);
|
||||
|
||||
if (colorModes.length) {
|
||||
discoveryEntry.discovery_payload.color_mode = true;
|
||||
discoveryEntry.discovery_payload.supported_color_modes = colorModes;
|
||||
}
|
||||
|
||||
|
||||
if (colorTemp) {
|
||||
discoveryEntry.discovery_payload.max_mireds = colorTemp.value_max;
|
||||
discoveryEntry.discovery_payload.min_mireds = colorTemp.value_min;
|
||||
|
||||
Reference in new issue
Block a user