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

Function changeEntityOptions

lib/util/settings.ts:640–673  ·  view source on GitHub ↗
(IDorName: string, newOptions: KeyValue)

Source from the content-addressed store, hash-verified

638}
639
640export 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
675export function changeFriendlyName(IDorName: string, newName: string): void {
676 utils.validateFriendlyName(newName, true);

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected