Skip to content

Commit

Permalink
fix: Truncate text of Home Assistant text sensor #23199
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Jul 6, 2024
1 parent 6cb62e5 commit 6b9247c
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions lib/extension/homeassistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,6 @@ export default class HomeAssistant extends Extension {
color_options: {icon: 'mdi:palette'},
level_config: {entity_category: 'diagnostic'},
programming_mode: {icon: 'mdi:calendar-clock'},
program: {value_template: `{{ value_json.${firstExpose.property}|default('',True) ` + `| truncate(254, True, '', 0) }}`},
schedule_settings: {icon: 'mdi:calendar-clock'},
};
if (firstExpose.access & ACCESS_STATE) {
Expand All @@ -1148,7 +1147,9 @@ export default class HomeAssistant extends Extension {
mockProperties: [{property: firstExpose.property, value: null}],
discovery_payload: {
name: endpoint ? `${firstExpose.label} ${endpoint}` : firstExpose.label,
value_template: `{{ value_json.${firstExpose.property} }}`,
// Truncate text if it's too long
// https://github.com/Koenkk/zigbee2mqtt/issues/23199
value_template: `{{ value_json.${firstExpose.property}|default('',True) ` + `| truncate(254, True, '', 0) }}`,
enabled_by_default: !settableText,
...lookup[firstExpose.name],
},
Expand All @@ -1175,13 +1176,6 @@ 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
Expand Down

0 comments on commit 6b9247c

Please sign in to comment.