MCPcopy
hub / github.com/Koenkk/zigbee2mqtt / addGroup

Function addGroup

lib/util/settings.ts:596–629  ·  view source on GitHub ↗
(name: string, id?: string)

Source from the content-addressed store, hash-verified

594}
595
596export function addGroup(name: string, id?: string): GroupOptions {
597 utils.validateFriendlyName(name, true);
598
599 if (getGroup(name) || getDevice(name)) {
600 throw new Error(`friendly_name '${name}' is already in use`);
601 }
602
603 const settings = getPersistedSettings();
604 if (!settings.groups) {
605 settings.groups = {};
606 }
607
608 if (id == null || (typeof id === "string" && id.trim() === "")) {
609 // look for free ID
610 id = "1";
611
612 while (settings.groups[id]) {
613 id = (Number.parseInt(id, 10) + 1).toString();
614 }
615 } else {
616 // ensure provided ID is not in use
617 id = id.toString();
618
619 if (settings.groups[id]) {
620 throw new Error(`Group ID '${id}' is already in use`);
621 }
622 }
623
624 settings.groups[id] = {friendly_name: name};
625 write();
626
627 // biome-ignore lint/style/noNonNullAssertion: valid from creation above
628 return getGroup(id)!;
629}
630
631export function removeGroup(IDorName: string | number): void {
632 const groupID = getGroupThrowIfNotExists(IDorName.toString()).ID;

Callers

nothing calls this directly

Calls 4

getGroupFunction · 0.85
getDeviceFunction · 0.85
getPersistedSettingsFunction · 0.85
writeFunction · 0.70

Tested by

no test coverage detected