Skip to content

Commit

Permalink
fix: Fix expose category ignored by HA discovery (#23494)
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk authored Aug 3, 2024
1 parent a25ef81 commit 3217332
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/extension/homeassistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ export default class HomeAssistant extends Extension {
ballast_minimum_level: {entity_category: 'config'},
ballast_physical_maximum_level: {entity_category: 'diagnostic'},
ballast_physical_minimum_level: {entity_category: 'diagnostic'},
battery: {device_class: 'battery', entity_category: 'diagnostic', state_class: 'measurement'},
battery: {device_class: 'battery', state_class: 'measurement'},
battery2: {device_class: 'battery', entity_category: 'diagnostic', state_class: 'measurement'},
battery_voltage: {device_class: 'voltage', entity_category: 'diagnostic', state_class: 'measurement', enabled_by_default: true},
boost_heating_countdown: {device_class: 'duration'},
Expand Down Expand Up @@ -1175,6 +1175,14 @@ export default class HomeAssistant extends Extension {
throw new Error(`Unsupported exposes type: '${firstExpose.type}'`);
}

// Exposes with category 'config' or 'diagnostic' are always added to the respective category.
// This takes precedence over definitions in this file.
if (firstExpose.category === 'config') {
discoveryEntries.forEach((d) => (d.discovery_payload.entity_category = 'config'));
} else if (firstExpose.category === 'diagnostic') {
discoveryEntries.forEach((d) => (d.discovery_payload.entity_category = 'diagnostic'));
}

discoveryEntries.forEach((d) => {
// If a sensor has entity category `config`, then change
// it to `diagnostic`. Sensors have no input, so can't be configured.
Expand Down

0 comments on commit 3217332

Please sign in to comment.