mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-14 06:40:05 +00:00
fix: Home Assistant: avoid duplicate door names (#32752)
Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
This commit is contained in:
co-authored by
Koen Kanters
parent
06290da5be
commit
f06673506f
@@ -401,6 +401,10 @@ const applyHomeAssistantExposeMetadata = (payload: DiscoveryEntry, homeAssistant
|
||||
payload.discovery_payload.icon = homeAssistant.icon;
|
||||
}
|
||||
|
||||
if (homeAssistant.name !== undefined) {
|
||||
payload.discovery_payload.name = homeAssistant.name;
|
||||
}
|
||||
|
||||
if (homeAssistant.valueTemplate !== undefined) {
|
||||
if (homeAssistant.valueTemplate === null) {
|
||||
delete payload.discovery_payload.value_template;
|
||||
@@ -1443,7 +1447,11 @@ export class HomeAssistant extends Extension {
|
||||
|
||||
// Let Home Assistant generate entity name when device_class is present.
|
||||
// preserve_name allows device_class and explicit name to coexist (e.g. derived sensors).
|
||||
if (entry.discovery_payload.device_class && !NUMERIC_DISCOVERY_LOOKUP[firstExpose.name]?.preserve_name) {
|
||||
if (
|
||||
entry.discovery_payload.device_class &&
|
||||
entry.discovery_payload.name !== null &&
|
||||
!NUMERIC_DISCOVERY_LOOKUP[firstExpose.name]?.preserve_name
|
||||
) {
|
||||
delete entry.discovery_payload.name;
|
||||
}
|
||||
|
||||
|
||||
@@ -281,6 +281,25 @@ describe("Extension: HomeAssistant", () => {
|
||||
expect(configs.find((config) => config.object_id === "voltage")?.discovery_payload).not.toHaveProperty("type");
|
||||
});
|
||||
|
||||
it("Should set discovery name to null when expose specifies homeassistant name null", () => {
|
||||
const createDevice = (exposes: zhc.Expose[]): Device =>
|
||||
({
|
||||
definition: {},
|
||||
isDevice: (): boolean => true,
|
||||
isGroup: (): boolean => false,
|
||||
endpoint: () => undefined,
|
||||
options: {},
|
||||
exposes: (): zhc.Expose[] => exposes,
|
||||
zh: {endpoints: []},
|
||||
}) as Device;
|
||||
|
||||
const contactExpose = new zhc.Binary("contact", zhc.access.STATE, false, true).withHomeAssistant({name: null});
|
||||
|
||||
// @ts-expect-error private
|
||||
const configs = extension.getConfigs(createDevice([contactExpose]));
|
||||
expect(configs.find((config) => config.object_id === "contact")?.discovery_payload.name).toBeNull();
|
||||
});
|
||||
|
||||
it("Should discover devices and groups", async () => {
|
||||
settings.set(["homeassistant", "experimental_event_entities"], true);
|
||||
settings.set(["groups", "9", "homeassistant"], {name: "HA Discovery Group", icon: "mdi:lightbulb-group"});
|
||||
|
||||
Reference in New Issue
Block a user