(name: string, id?: string)
| 594 | } |
| 595 | |
| 596 | export 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 | |
| 631 | export function removeGroup(IDorName: string | number): void { |
| 632 | const groupID = getGroupThrowIfNotExists(IDorName.toString()).ID; |
nothing calls this directly
no test coverage detected