From 024dae54c542d800e3d8e0b936a5205229211dd8 Mon Sep 17 00:00:00 2001 From: Parnic Date: Thu, 9 Jan 2025 10:36:04 -0600 Subject: [PATCH] Minor cleanup, fix errors --- MMM-IntelliCenter.js | 54 ++++++++++++++++++++++++++++---------------- node_helper.js | 6 ++--- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/MMM-IntelliCenter.js b/MMM-IntelliCenter.js index eb602c0..899224d 100644 --- a/MMM-IntelliCenter.js +++ b/MMM-IntelliCenter.js @@ -174,7 +174,7 @@ Module.register("MMM-IntelliCenter", { }, getPHDom() { - let dataStr = this.poolData.lastPHVal; + let dataStr = this.poolData.lastPHVal.toString(); if (this.config.showPHTankLevel) { const percent = Math.round( ((this.poolData.phTank - 1) / this.config.pHTankLevelMax) * 100, @@ -246,8 +246,10 @@ Module.register("MMM-IntelliCenter", { controls.push(circuit); } } else { - Log.warn("circuit with unknown type, unable to display:"); - Log.warn(controlObj); + Log.warn( + "circuit with unknown type, unable to display. supported types: circuit, heatpoint, heatmode. object:", + controlObj, + ); } } @@ -289,29 +291,34 @@ Module.register("MMM-IntelliCenter", { }, getHeatpointDom(controlObj) { - // todo: if "body" isn't defined in the user's config correctly, this will error out - const body = controlObj.body.toLowerCase(); + const body = + typeof controlObj.body === "string" ? controlObj.body.toLowerCase() : ""; if (body !== "pool" && body !== "spa") { - Log.warn("Invalid body specified for heatpoint. Valid bodies: pool, spa"); + Log.warn( + "Invalid body specified for heatpoint. Valid bodies: pool, spa", + controlObj, + ); + return; + } + if (!controlObj.name) { + Log.warn("Invalid name specified for heatpoint.", controlObj); return; } const temperature = - body === "pool" - ? this.poolData.poolSetPoint.toString() - : this.poolData.spaSetPoint.toString(); + body === "pool" ? this.poolData.poolSetPoint : this.poolData.spaSetPoint; const div = document.createElement("div"); div.classList.add("temperature-container"); const buttonUp = document.createElement("button"); - buttonUp.id = `sl-temp-up-${controlObj.body}`; + buttonUp.id = `sl-temp-up-${body}`; buttonUp.classList.add("control-off", "temperature"); buttonUp.onclick = (e) => { this.setHeatpoint(e.currentTarget, 1); }; - buttonUp.dataset.body = controlObj.body; - buttonUp.dataset.temperature = temperature; + buttonUp.dataset.body = body; + buttonUp.dataset.temperature = temperature.toString(); const contentUp = document.createElement("div"); contentUp.classList.add("content"); @@ -326,12 +333,12 @@ Module.register("MMM-IntelliCenter", { div.appendChild(label); const buttonDown = document.createElement("button"); - buttonDown.id = `sl-temp-down-${controlObj.body}`; + buttonDown.id = `sl-temp-down-${body}`; buttonDown.classList.add("control-off", "temperature"); buttonDown.onclick = (e) => { this.setHeatpoint(e.currentTarget, -1); }; - buttonDown.dataset.body = controlObj.body; + buttonDown.dataset.body = body; buttonDown.dataset.temperature = temperature; const contentDown = document.createElement("div"); @@ -348,10 +355,17 @@ Module.register("MMM-IntelliCenter", { }, getHeatmodeDom(controlObj) { - // todo: if "body" isn't defined in the user's config correctly, this will error out - const body = controlObj.body.toLowerCase(); + const body = + typeof controlObj.body === "string" ? controlObj.body.toLowerCase() : ""; if (body !== "pool" && body !== "spa") { - Log.warn("Invalid body specified for heatmode. Valid bodies: pool, spa"); + Log.warn( + "Invalid body specified for heatmode. Valid bodies: pool, spa", + controlObj, + ); + return; + } + if (!controlObj.name) { + Log.warn("Invalid name specified for heatmode.", controlObj); return; } @@ -366,13 +380,13 @@ Module.register("MMM-IntelliCenter", { } const button = document.createElement("button"); - button.id = `sl-heat-${controlObj.body}`; + button.id = `sl-heat-${body}`; button.classList.add("control", cls); button.onclick = (e) => { this.setHeatmode(e.currentTarget); }; - button.dataset.body = controlObj.body; - button.dataset.state = on ? 1 : 0; + button.dataset.body = body; + button.dataset.state = on ? "1" : "0"; const content = document.createElement("div"); content.classList.add("content"); diff --git a/node_helper.js b/node_helper.js index 18966e1..9df2801 100644 --- a/node_helper.js +++ b/node_helper.js @@ -1,4 +1,4 @@ -/* global module require clearInterval clearTimeout setTimeout setInterval config */ +/* global module require clearInterval clearTimeout setTimeout setInterval */ var NodeHelper = require("node_helper"); @@ -259,7 +259,7 @@ module.exports = NodeHelper.create({ } } else if (Object.keys(poolData.circuits).includes(obj.objnam)) { Log.info( - `[MMM-IntelliCenter] received update for circuit ${obj.objnam}`, + `[MMM-IntelliCenter] received update for circuit ${obj.objnam} (${poolData.circuits[obj.objnam].name})`, ); if (obj.params.STATUS) { @@ -431,7 +431,7 @@ module.exports = NodeHelper.create({ connect(cb, reconnectCb) { if ( !foundUnit && - typeof config !== "undefined" && + typeof this.config !== "undefined" && this.config.serverAddress && this.config.serverPort ) {