Get control labels, status working

This gets everything working in the module except the ability to turn circuits on and off and set heat temperatures.
This commit is contained in:
2025-01-05 17:49:38 -06:00
parent c07685bb91
commit f479ecec79
2 changed files with 44 additions and 20 deletions

View File

@ -158,24 +158,11 @@ Module.register("MMM-IntelliCenter", {
if (controlObj.type === "circuit") {
let { name } = controlObj;
// todo: rework how controls are specified
// for (const circuit in poolData.controllerConfig.bodyArray) {
// if (
// poolData.controllerConfig.bodyArray[circuit].circuitId ===
// controlObj.id
// ) {
// if (!name) {
// name = poolData.controllerConfig.bodyArray[circuit].name;
// }
// }
// }
let on = false;
// for (const circuit in poolData.status.circuitArray) {
// if (poolData.status.circuitArray[circuit].id === controlObj.id) {
// on = poolData.status.circuitArray[circuit].state !== 0;
// }
// }
if (poolData.circuits[controlObj.id]) {
name = poolData.circuits[controlObj.id].name ?? controlObj.name;
on = poolData.circuits[controlObj.id].status;
}
let cls = "";
if (this.config.colored) {
@ -191,6 +178,7 @@ Module.register("MMM-IntelliCenter", {
class: this.config.contentClass,
});
} else if (controlObj.type === "heatpoint") {
// todo: if "body" isn't defined in the user's config correctly, this will error out
const body = controlObj.body.toLowerCase();
if (body !== "pool" && body !== "spa") {
Log.warn(
@ -214,6 +202,7 @@ Module.register("MMM-IntelliCenter", {
class: this.config.contentClass,
});
} else if (controlObj.type === "heatmode") {
// todo: if "body" isn't defined in the user's config correctly, this will error out
const body = controlObj.body.toLowerCase();
if (body !== "pool" && body !== "spa") {
Log.warn(

View File

@ -26,6 +26,7 @@ const poolData = {
saltPPM: 0,
saturation: 0,
freezeMode: false,
circuits: {},
};
let poolObjnam = "B1101";
let spaObjnam = "B1202";
@ -222,6 +223,14 @@ module.exports = NodeHelper.create({
if (obj.params.STATUS) {
poolData.freezeMode = obj.params.STATUS === "ON";
}
} else if (Object.keys(poolData.circuits).includes(obj.objnam)) {
Log.info(
`[MMM-IntelliCenter] received update for circuit ${obj.objnam}`,
);
if (obj.params.STATUS) {
poolData.circuits[obj.objnam].status = obj.params.STATUS === "ON";
}
} else {
Log.info(
`[MMM-IntelliCenter] received update for untracked object: ${obj.objnam}`,
@ -267,11 +276,37 @@ module.exports = NodeHelper.create({
Log.info("[MMM-IntelliCenter] getting circuit information...");
const circuits = await foundUnit.send(messages.GetCircuitStatus());
const freezeCirc = circuits.objectList?.find((obj) => obj.params?.SUBTYP === "FRZ");
const freezeCirc = circuits.objectList?.find(
(obj) => obj.params?.SUBTYP === "FRZ",
);
if (freezeCirc) {
freezeObjnam = freezeCirc.objnam;
Log.info(`[MMM-IntelliCenter] registering for freeze-protection updates...`);
await foundUnit.send(messages.SubscribeToUpdates(freezeObjnam, "STATUS"));
Log.info(
`[MMM-IntelliCenter] registering for freeze-protection updates...`,
);
await foundUnit.send(
messages.SubscribeToUpdates(freezeObjnam, "STATUS"),
);
}
if (this.config.controls?.length > 0) {
for (const circuit of circuits.objectList) {
const wantedControl = this.config.controls.find(
(c) => c.id === circuit.objnam,
);
if (!wantedControl) {
continue;
}
poolData.circuits[circuit.objnam] = {
status: false,
name: circuit.params.SNAME,
};
}
}
for (const circuit of Object.keys(poolData.circuits)) {
Log.info(`[MMM-IntelliCenter] registering for ${circuit} updates...`);
await foundUnit.send(messages.SubscribeToUpdates(circuit, "STATUS"));
}
if (bodyUpdates.length > 0) {