let poolData = {}; let moduleObj; Module.register('MMM-ScreenLogic',{ defaults: { showPoolTemp: true, showSpaTemp: true, showPH: true, showOrp: true, showSaltLevel: true, showSaturation: true, showFreezeMode: true, showControls: false, controls: [], colored: true, coldTemp: 84, hotTemp: 90, columns: 3, contentClass: 'light', updateInterval: 30 * 60 * 1000 }, start: function() { // this isn't a great solution...is there a better one? needed to do stuff with buttons moduleObj = this; if (this.config.showControls && (!this.config.controls || this.config.controls.length === 0)) { Log.warn('Controls are enabled, but no controls are configured. See README for info on setting up controls.'); this.config.showControls = false; } this.sendSocketNotification('SCREENLOGIC_CONFIG', this.config); this.sendSocketNotification('SCREENLOGIC_UPDATE'); }, getStyles: function() { return ['screenlogic.css']; }, getDom: function() { if (!poolData.status) { let wrapper = document.createElement('div'); wrapper.innerHTML = 'Loading...'; wrapper.className += 'dimmed light small'; return wrapper; } else { let table = document.createElement('table'); table.className = 'small'; if (this.config.colored) { table.className += ' colored'; } let contents = []; if (this.config.showPoolTemp) { let className = ''; if (poolData.status.currentTemp[0] <= this.config.coldTemp) { className += ' cold-temp'; } else if (poolData.status.currentTemp[0] >= this.config.hotTemp) { className += ' hot-temp'; } contents.push({ header: 'Pool temp', data: poolData.status.currentTemp[0] + '°' + (!isPoolActive(poolData.status) ? ' (last)' : ''), class: this.config.contentClass + className }); } if (this.config.showSpaTemp) { let className = ''; if (poolData.status.currentTemp[1] <= this.config.coldTemp) { className = ' cold-temp'; } else if (poolData.status.currentTemp[1] >= this.config.hotTemp) { className = ' hot-temp'; } contents.push({ header: 'Spa temp', data: poolData.status.currentTemp[1] + '°' + (!isSpaActive(poolData.status) ? ' (last)' : ''), class: this.config.contentClass + className }); } if (this.config.showPH) { contents.push({ header: 'pH', data: poolData.status.pH, class: this.config.contentClass }); } if (this.config.showOrp) { contents.push({ header: 'ORP', data: poolData.status.orp, class: this.config.contentClass }); } if (this.config.showSaltLevel) { contents.push({ header: 'Salt PPM', data: poolData.status.saltPPM, class: this.config.contentClass }); } if (this.config.showSaturation) { contents.push({ header: 'Saturation', data: poolData.status.saturation, class: this.config.contentClass }); } if (this.config.showControls) { for (let control in this.config.controls) { let controlObj = this.config.controls[control]; if (controlObj.type === 'circuit') { let name = controlObj.name; for (let 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 (let circuit in poolData.status.circuitArray) { if (poolData.status.circuitArray[circuit].id === controlObj.id) { on = poolData.status.circuitArray[circuit].state !== 0; } } let cls = ''; if (this.config.colored) { cls = on ? 'control-on' : 'control-off'; } contents.push({ data: '', class: this.config.contentClass }); } else if (controlObj.type === 'heatpoint') { if (controlObj.body < 0 || controlObj.body > poolData.status.setPoint.length) { Log.warn('Invalid body specified for heatpoint'); continue; } let temperature = poolData.status.setPoint[controlObj.body]; let dataHtml = '