update
This commit is contained in:
@@ -6,8 +6,18 @@ class ChildRegistrationUtils {
|
||||
}
|
||||
|
||||
async registerChild(child, positionVsParent, distance) {
|
||||
const { softwareType } = child.config.functionality;
|
||||
const { name, id } = child.config.general;
|
||||
if (!child || typeof child !== 'object') {
|
||||
this.logger?.warn('registerChild skipped: invalid child payload');
|
||||
return false;
|
||||
}
|
||||
if (!child.config?.functionality || !child.config?.general) {
|
||||
this.logger?.warn('registerChild skipped: missing child config/functionality/general');
|
||||
return false;
|
||||
}
|
||||
|
||||
const softwareType = child.config.functionality.softwareType;
|
||||
const name = child.config.general.name || child.config.general.id || 'unknown';
|
||||
const id = child.config.general.id || name;
|
||||
|
||||
this.logger.debug(`Registering child: ${name} (${id}) as ${softwareType} at ${positionVsParent}`);
|
||||
|
||||
@@ -43,19 +53,21 @@ class ChildRegistrationUtils {
|
||||
}
|
||||
|
||||
this.logger.info(`✅ Child ${name} registered successfully`);
|
||||
return true;
|
||||
}
|
||||
|
||||
_storeChild(child, softwareType) {
|
||||
// Maintain your existing structure
|
||||
if (!this.mainClass.child) this.mainClass.child = {};
|
||||
if (!this.mainClass.child[softwareType]) this.mainClass.child[softwareType] = {};
|
||||
const typeKey = softwareType || 'unknown';
|
||||
if (!this.mainClass.child[typeKey]) this.mainClass.child[typeKey] = {};
|
||||
|
||||
const { category = "sensor" } = child.config.asset || {};
|
||||
if (!this.mainClass.child[softwareType][category]) {
|
||||
this.mainClass.child[softwareType][category] = [];
|
||||
if (!this.mainClass.child[typeKey][category]) {
|
||||
this.mainClass.child[typeKey][category] = [];
|
||||
}
|
||||
|
||||
this.mainClass.child[softwareType][category].push(child);
|
||||
this.mainClass.child[typeKey][category].push(child);
|
||||
}
|
||||
|
||||
// NEW: Utility methods for parent to use
|
||||
@@ -95,4 +107,4 @@ class ChildRegistrationUtils {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ChildRegistrationUtils;
|
||||
module.exports = ChildRegistrationUtils;
|
||||
|
||||
Reference in New Issue
Block a user