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

Function read

lib/util/settings.ts:330–381  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

328}
329
330function read(): Partial<Settings> {
331 const s = yaml.read(CONFIG_FILE_PATH) as Partial<Settings>;
332
333 // Read !secret MQTT username and password if set
334 const interpretValue = <T>(value: T): T => {
335 if (typeof value === "string") {
336 const ref = parseValueRef(value);
337 if (ref) {
338 return yaml.read(data.joinPath(ref.filename))[ref.key];
339 }
340 }
341 return value;
342 };
343
344 if (s.mqtt?.user) {
345 s.mqtt.user = interpretValue(s.mqtt.user);
346 }
347
348 if (s.mqtt?.password) {
349 s.mqtt.password = interpretValue(s.mqtt.password);
350 }
351
352 if (s.mqtt?.server) {
353 s.mqtt.server = interpretValue(s.mqtt.server);
354 }
355
356 if (s.advanced?.network_key) {
357 s.advanced.network_key = interpretValue(s.advanced.network_key);
358 }
359
360 if (s.frontend?.auth_token) {
361 s.frontend.auth_token = interpretValue(s.frontend.auth_token);
362 }
363
364 // Read devices/groups configuration from separate file if specified.
365 const readDevicesOrGroups = (type: "devices" | "groups"): void => {
366 if (typeof s[type] === "string" || (Array.isArray(s[type]) && Array(s[type]).length > 0)) {
367 const files: string[] = Array.isArray(s[type]) ? s[type] : [s[type]];
368 s[type] = {};
369 for (const file of files) {
370 const content = yaml.readIfExists(data.joinPath(file));
371 // @ts-expect-error noMutate not typed properly
372 s[type] = objectAssignDeep.noMutate(s[type], content);
373 }
374 }
375 };
376
377 readDevicesOrGroups("devices");
378 readDevicesOrGroups("groups");
379
380 return s;
381}
382
383function applyEnvironmentVariables(settings: Partial<Settings>): void {
384 const iterate = (obj: KeyValue, path: string[]): void => {

Callers 4

loadSettingsWithDefaultsFunction · 0.70
writeMinimalDefaultsFunction · 0.70
writeFunction · 0.70
getPersistedSettingsFunction · 0.70

Calls 2

interpretValueFunction · 0.85
readDevicesOrGroupsFunction · 0.85

Tested by

no test coverage detected