(IDorName: string, newOptions: KeyValue)
| 638 | } |
| 639 | |
| 640 | export function changeEntityOptions(IDorName: string, newOptions: KeyValue): boolean { |
| 641 | const settings = getPersistedSettings(); |
| 642 | delete newOptions.friendly_name; |
| 643 | delete newOptions.devices; |
| 644 | let validator: ValidateFunction; |
| 645 | const device = getDevice(IDorName); |
| 646 | |
| 647 | if (device) { |
| 648 | // biome-ignore lint/style/noNonNullAssertion: valid from above |
| 649 | const settingsDevice = settings.devices![device.ID]; |
| 650 | objectAssignDeep(settingsDevice, newOptions); |
| 651 | utils.removeNullPropertiesFromObject(settingsDevice, NULLABLE_SETTINGS); |
| 652 | validator = ajvRestartRequiredDeviceOptions; |
| 653 | } else { |
| 654 | const group = getGroup(IDorName); |
| 655 | |
| 656 | if (group) { |
| 657 | // biome-ignore lint/style/noNonNullAssertion: valid from above |
| 658 | const settingsGroup = settings.groups![group.ID]; |
| 659 | objectAssignDeep(settingsGroup, newOptions); |
| 660 | utils.removeNullPropertiesFromObject(settingsGroup, NULLABLE_SETTINGS); |
| 661 | validator = ajvRestartRequiredGroupOptions; |
| 662 | } else { |
| 663 | throw new Error(`Device or group '${IDorName}' does not exist`); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | write(); |
| 668 | validator(newOptions); |
| 669 | |
| 670 | const restartRequired = Boolean(validator.errors && !!validator.errors.find((e) => e.keyword === "requiresRestart")); |
| 671 | |
| 672 | return restartRequired; |
| 673 | } |
| 674 | |
| 675 | export function changeFriendlyName(IDorName: string, newName: string): void { |
| 676 | utils.validateFriendlyName(newName, true); |
nothing calls this directly
no test coverage detected