Skip to content

Commit

Permalink
fix: Home Assistant: fix brightness only lights (#26560)
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk authored Mar 2, 2025
1 parent cd19900 commit fb89ef6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
14 changes: 12 additions & 2 deletions lib/extension/homeassistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,23 @@ export default class HomeAssistant extends Extension {
},
};

discoveryEntry.discovery_payload.supported_color_modes = [
'brightness',
const colorModes = [
hasColorXY && !preferHS ? 'xy' : null,
(!hasColorXY || preferHS) && hasColorHS ? 'hs' : null,
hasColorTemp ? 'color_temp' : null,
].filter((c) => c);

if (colorModes.length) {
discoveryEntry.discovery_payload.supported_color_modes = colorModes;
} else {
/**
* All bulbs support brightness, note that `brightness` cannot be combined
* with other color modes.
* https://github.com/Koenkk/zigbee2mqtt/issues/26520#issuecomment-2692432058
*/
discoveryEntry.discovery_payload.supported_color_modes = ['brightness'];
}

if (hasColorTemp) {
const colorTemps = (exposes as zhc.Light[])
.map((expose) => expose.features.find((e) => e.name === 'color_temp'))
Expand Down
39 changes: 33 additions & 6 deletions test/extensions/homeassistant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('Extension: HomeAssistant', () => {
name: null,
schema: 'json',
state_topic: 'zigbee2mqtt/ha_discovery_group',
supported_color_modes: ['brightness', 'xy', 'color_temp'],
supported_color_modes: ['xy', 'color_temp'],
effect: true,
effect_list: [
'blink',
Expand All @@ -165,6 +165,33 @@ describe('Extension: HomeAssistant', () => {
qos: 1,
});

payload = {
availability: [{topic: 'zigbee2mqtt/bridge/state', value_template: '{{ value_json.state }}'}],
brightness: true,
brightness_scale: 254,
command_topic: 'zigbee2mqtt/bulb_enddevice/set',
device: {
identifiers: ['zigbee2mqtt_0x0017880104e45553'],
manufacturer: 'Sengled',
model: 'Element classic (A19)',
model_id: 'E11-G13',
name: 'bulb_enddevice',
via_device: 'zigbee2mqtt_bridge_0x00124b00120144ae',
},
name: null,
object_id: 'bulb_enddevice',
origin: origin,
schema: 'json',
state_topic: 'zigbee2mqtt/bulb_enddevice',
supported_color_modes: ['brightness'],
unique_id: '0x0017880104e45553_light_zigbee2mqtt',
};

expect(mockMQTTPublishAsync).toHaveBeenCalledWith('homeassistant/light/0x0017880104e45553/light/config', stringify(payload), {
retain: true,
qos: 1,
});

payload = {
availability: [{topic: 'zigbee2mqtt/bridge/state', value_template: '{{ value_json.state }}'}],
command_topic: 'zigbee2mqtt/ha_discovery_group/set',
Expand Down Expand Up @@ -381,7 +408,7 @@ describe('Extension: HomeAssistant', () => {
availability: [{topic: 'zigbee2mqtt/bridge/state', value_template: '{{ value_json.state }}'}],
brightness: true,
brightness_scale: 254,
supported_color_modes: ['brightness', 'color_temp'],
supported_color_modes: ['color_temp'],
min_mireds: 250,
max_mireds: 454,
command_topic: 'zigbee2mqtt/bulb/set',
Expand Down Expand Up @@ -1633,7 +1660,7 @@ describe('Extension: HomeAssistant', () => {
name: null,
schema: 'json',
state_topic: 'zigbee2mqtt/ha_discovery_group_new',
supported_color_modes: ['brightness', 'xy', 'color_temp'],
supported_color_modes: ['xy', 'color_temp'],
effect: true,
effect_list: [
'blink',
Expand Down Expand Up @@ -2101,7 +2128,7 @@ describe('Extension: HomeAssistant', () => {
name: null,
schema: 'json',
state_topic: 'zigbee2mqtt/ha_discovery_group',
supported_color_modes: ['brightness', 'xy', 'color_temp'],
supported_color_modes: ['xy', 'color_temp'],
effect: true,
effect_list: [
'blink',
Expand Down Expand Up @@ -2145,7 +2172,7 @@ describe('Extension: HomeAssistant', () => {
name: null,
schema: 'json',
state_topic: 'zigbee2mqtt/ha_discovery_group',
supported_color_modes: ['brightness', 'xy', 'color_temp'],
supported_color_modes: ['xy', 'color_temp'],
effect: true,
effect_list: [
'blink',
Expand Down Expand Up @@ -2200,7 +2227,7 @@ describe('Extension: HomeAssistant', () => {
name: null,
schema: 'json',
state_topic: 'zigbee2mqtt/bulb',
supported_color_modes: ['brightness', 'color_temp'],
supported_color_modes: ['color_temp'],
object_id: 'bulb',
unique_id: '0x000b57fffec6a5b2_light_zigbee2mqtt',
origin: origin,
Expand Down

0 comments on commit fb89ef6

Please sign in to comment.