diff --git a/lib/extension/homeassistant.ts b/lib/extension/homeassistant.ts index 975fb0f96..2936542c7 100644 --- a/lib/extension/homeassistant.ts +++ b/lib/extension/homeassistant.ts @@ -127,7 +127,11 @@ export default class HomeAssistant extends Extension { const hasBrightness = exposes.find((expose) => expose.features.find((e) => e.name === 'brightness')); const hasColorTemp = exposes.find((expose) => expose.features.find((e) => e.name === 'color_temp')); const state = firstExpose.features.find((f) => f.name === 'state'); - const preferHS = !!exposes.find((expose) => expose.preferredColorMode === 'hs'); + // Prefer HS over XY when at least one of the lights in the group prefers HS over XY. + // A light prefers HS over XY when HS is earlier in the feature array than HS. + const preferHS = exposes.map((e) => [e.features.findIndex((ee) => ee.name === 'color_xy'), + e.features.findIndex((ee) => ee.name === 'color_hs')]) + .filter((d) => d[0] !== -1 && d[1] !== -1 && d[1] < d[0]).length !== 0; const discoveryEntry: DiscoveryEntry = { type: 'light', diff --git a/lib/types/types.d.ts b/lib/types/types.d.ts index fcbc8aef9..7b7b87463 100644 --- a/lib/types/types.d.ts +++ b/lib/types/types.d.ts @@ -101,7 +101,7 @@ declare global { interface DefinitionExpose { type: string, name?: string, features?: DefinitionExposeFeature[], endpoint?: string, values?: string[], value_off?: string, value_on?: string, - access: number, property: string, unit?: string, preferredColorMode?: 'xy' | 'hs', + access: number, property: string, unit?: string, value_min?: number, value_max?: number} interface Definition {