Skip to content

Commit 83f963b

Browse files
committed
Preserve composite child HA entity categories
1 parent 5f6341a commit 83f963b

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/extension/homeassistant.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,9 @@ export class HomeAssistant extends Extension {
13581358
optimistic: !allowsState,
13591359
}),
13601360
};
1361+
if (feature.category === "config" || feature.category === "diagnostic") {
1362+
discoveryPayload.entity_category = feature.category;
1363+
}
13611364

13621365
if (isNumericExpose(feature)) {
13631366
if (allowsSet) discoveryPayload.command_template = compositePathCommandTemplate(path, "{{ value }}");
@@ -1468,7 +1471,7 @@ export class HomeAssistant extends Extension {
14681471
// This takes precedence over definitions in this file.
14691472
if (firstExpose.category === "config" || firstExpose.category === "diagnostic") {
14701473
for (const entry of discoveryEntries) {
1471-
entry.discovery_payload.entity_category = firstExpose.category;
1474+
entry.discovery_payload.entity_category ??= firstExpose.category;
14721475
}
14731476
}
14741477

test/extensions/homeassistant.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,13 +1008,15 @@ describe("Extension: HomeAssistant", () => {
10081008
property: "network",
10091009
label: "Network",
10101010
access: 3,
1011+
category: "config",
10111012
features: [
10121013
{
10131014
type: "numeric",
10141015
name: "timeout",
10151016
property: "timeout",
10161017
label: "Timeout",
10171018
access: 3,
1019+
category: "config",
10181020
unit: "min",
10191021
value_min: 1,
10201022
value_max: 60,
@@ -1026,6 +1028,7 @@ describe("Extension: HomeAssistant", () => {
10261028
property: "temperature",
10271029
label: "Temperature",
10281030
access: 1,
1031+
category: "diagnostic",
10291032
unit: "°C",
10301033
},
10311034
{
@@ -1091,24 +1094,28 @@ describe("Extension: HomeAssistant", () => {
10911094
value_template:
10921095
'{% if value_json["network"] is defined and value_json["network"]["timeout"] is defined %}{{ value_json["network"]["timeout"] }}{% endif %}',
10931096
command_template: '{"network": {"timeout": {{ value }}}}',
1097+
entity_category: "config",
10941098
unit_of_measurement: "min",
10951099
min: 1,
10961100
max: 60,
10971101
step: 1,
10981102
});
10991103
expect(configs.find((config) => config.object_id === "network_temperature")?.discovery_payload).toMatchObject({
1104+
entity_category: "diagnostic",
11001105
unit_of_measurement: "°C",
11011106
device_class: "temperature",
11021107
state_class: "measurement",
11031108
});
11041109
expect(configs.find((config) => config.object_id === "network_mode")?.discovery_payload).toMatchObject({
11051110
command_template: '{"network": {"mode": {{ value | tojson }}}}',
1111+
entity_category: "config",
11061112
options: ["auto", "manual"],
11071113
});
11081114
expect(configs.find((config) => config.object_id === "network_advanced_enabled")?.discovery_payload).toMatchObject({
11091115
value_template:
11101116
'{% if value_json["network"] is defined and value_json["network"]["advanced"] is defined and value_json["network"]["advanced"]["enabled"] is defined %}{{ value_json["network"]["advanced"]["enabled"] | string | lower }}{% endif %}',
11111117
command_template: '{"network": {"advanced": {"enabled": {{ value }}}}}',
1118+
entity_category: "config",
11121119
payload_on: "true",
11131120
payload_off: "false",
11141121
});

0 commit comments

Comments
 (0)