-
-
${It.required.name}
+
+
${xt.required.name}
-
${It.required.secondary}
+
${xt.required.secondary}
- ${It.required.show?M`
+ ${xt.required.show?P`
e=>"function"==typeof e?((t,e)=>(customElements.define(t,e),e))(t,e)
.configValue=${"entity"}
>
- ${t.map((t=>M` ${t} `))}
+ ${t.map((t=>P` ${t} `))}
`:""}
-
-
${It.actions.name}
+
+
${xt.actions.name}
-
${It.actions.secondary}
+
${xt.actions.secondary}
- ${It.actions.show?M`
+ ${xt.actions.show?P`
-
-
${It.actions.options.tap.name}
+
+
${xt.actions.options.tap.name}
-
${It.actions.options.tap.secondary}
+
${xt.actions.options.tap.secondary}
- ${It.actions.options.tap.show?M`
+ ${xt.actions.options.tap.show?P`
Action Editors Coming Soon
`:""}
-
-
${It.actions.options.hold.name}
+
+
${xt.actions.options.hold.name}
-
${It.actions.options.hold.secondary}
+
${xt.actions.options.hold.secondary}
- ${It.actions.options.hold.show?M`
+ ${xt.actions.options.hold.show?P`
Action Editors Coming Soon
`:""}
-
-
${It.actions.options.double_tap.name}
+
+
${xt.actions.options.double_tap.name}
-
${It.actions.options.double_tap.secondary}
+
${xt.actions.options.double_tap.secondary}
- ${It.actions.options.double_tap.show?M`
+ ${xt.actions.options.double_tap.show?P`
Action Editors Coming Soon
@@ -126,12 +126,12 @@ const et=t=>e=>"function"==typeof e?((t,e)=>(customElements.define(t,e),e))(t,e)
`:""}
-
-
${It.appearance.name}
+
+
${xt.appearance.name}
-
${It.appearance.secondary}
+
${xt.appearance.secondary}
- ${It.appearance.show?M`
+ ${xt.appearance.show?P`
e=>"function"==typeof e?((t,e)=>(customElements.define(t,e),e))(t,e)
`:""}
- `}_initialize(){void 0!==this.hass&&void 0!==this._config&&void 0!==this._helpers&&(this._initialized=!0)}async loadCardHelpers(){this._helpers=await window.loadCardHelpers()}_toggleAction(t){this._toggleThing(t,It.actions.options)}_toggleOption(t){this._toggleThing(t,It)}_toggleThing(t,e){const i=!e[t.target.option].show;for(const[t]of Object.entries(e))e[t].show=!1;e[t.target.option].show=i,this._toggle=!this._toggle}_valueChanged(t){if(!this._config||!this.hass)return;const e=t.target;if(this[`_${e.configValue}`]!==e.value){if(e.configValue)if(""===e.value){const t=Object.assign({},this._config);delete t[e.configValue],this._config=t}else this._config=Object.assign(Object.assign({},this._config),{[e.configValue]:void 0!==e.checked?e.checked:e.value});$t(this,"config-changed",{config:this._config})}}static get styles(){return r`
+ `}_initialize(){void 0!==this.hass&&void 0!==this._config&&void 0!==this._helpers&&(this._initialized=!0)}async loadCardHelpers(){this._helpers=await window.loadCardHelpers()}_toggleAction(t){this._toggleThing(t,xt.actions.options)}_toggleOption(t){this._toggleThing(t,xt)}_toggleThing(t,e){const i=!e[t.target.option].show;for(const[t]of Object.entries(e))e[t].show=!1;e[t.target.option].show=i,this._toggle=!this._toggle}_valueChanged(t){if(!this._config||!this.hass)return;const e=t.target;if(this[`_${e.configValue}`]!==e.value){if(e.configValue)if(""===e.value){const t=Object.assign({},this._config);delete t[e.configValue],this._config=t}else this._config=Object.assign(Object.assign({},this._config),{[e.configValue]:void 0!==e.checked?e.checked:e.value});$t(this,"config-changed",{config:this._config})}}static get styles(){return r`
.option {
padding: 4px 0px;
cursor: pointer;
@@ -185,35 +185,37 @@ const et=t=>e=>"function"==typeof e?((t,e)=>(customElements.define(t,e),e))(t,e)
ha-formfield {
padding-bottom: 8px;
}
- `}};t([ot({attribute:!1})],xt.prototype,"hass",void 0),t([st()],xt.prototype,"_config",void 0),t([st()],xt.prototype,"_toggle",void 0),t([st()],xt.prototype,"_helpers",void 0),xt=t([et("rpi-monitor-card-editor")],xt);class Et{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}const kt="ontouchstart"in window||navigator.maxTouchPoints>0||navigator.maxTouchPoints>0;class Tt extends HTMLElement{constructor(){super(),this.holdTime=500,this.held=!1,this.ripple=document.createElement("mwc-ripple")}connectedCallback(){Object.assign(this.style,{position:"absolute",width:kt?"100px":"50px",height:kt?"100px":"50px",transform:"translate(-50%, -50%)",pointerEvents:"none",zIndex:"999"}),this.appendChild(this.ripple),this.ripple.primary=!0,["touchcancel","mouseout","mouseup","touchmove","mousewheel","wheel","scroll"].forEach((t=>{document.addEventListener(t,(()=>{clearTimeout(this.timer),this.stopAnimation(),this.timer=void 0}),{passive:!0})}))}bind(t,e){if(t.actionHandler)return;t.actionHandler=!0,t.addEventListener("contextmenu",(t=>{const e=t||window.event;return e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0,e.returnValue=!1,!1}));const i=t=>{let e,i;this.held=!1,t.touches?(e=t.touches[0].pageX,i=t.touches[0].pageY):(e=t.pageX,i=t.pageY),this.timer=window.setTimeout((()=>{this.startAnimation(e,i),this.held=!0}),this.holdTime)},o=i=>{i.preventDefault(),["touchend","touchcancel"].includes(i.type)&&void 0===this.timer||(clearTimeout(this.timer),this.stopAnimation(),this.timer=void 0,this.held?$t(t,"action",{action:"hold"}):e.hasDoubleClick?"click"===i.type&&i.detail<2||!this.dblClickTimeout?this.dblClickTimeout=window.setTimeout((()=>{this.dblClickTimeout=void 0,$t(t,"action",{action:"tap"})}),250):(clearTimeout(this.dblClickTimeout),this.dblClickTimeout=void 0,$t(t,"action",{action:"double_tap"})):$t(t,"action",{action:"tap"}))};t.addEventListener("touchstart",i,{passive:!0}),t.addEventListener("touchend",o),t.addEventListener("touchcancel",o),t.addEventListener("mousedown",i,{passive:!0}),t.addEventListener("click",o),t.addEventListener("keyup",(t=>{13===t.keyCode&&o(t)}))}startAnimation(t,e){Object.assign(this.style,{left:`${t}px`,top:`${e}px`,display:null}),this.ripple.disabled=!1,this.ripple.active=!0,this.ripple.unbounded=!0}stopAnimation(){this.ripple.active=!1,this.ripple.disabled=!0,this.style.display="none"}}customElements.define("action-handler-rpi-monitor",Tt);const Ut=(t,e)=>{const i=(()=>{const t=document.body;if(t.querySelector("action-handler-rpi-monitor"))return t.querySelector("action-handler-rpi-monitor");const e=document.createElement("action-handler-rpi-monitor");return t.appendChild(e),e})();i&&i.bind(t,e)},Dt=(t=>(...e)=>({_$litDirective$:t,values:e}))(class extends Et{update(t,[e]){return Ut(t.element,e),N}render(t){}}),Ft="ifaces",Pt="ux_release",Mt="last_update",Nt="up_time",Ot="fs_total_gb",Rt="fs_free_prcnt",Vt="temperature_c",Ht="show-os-parts",Lt="memory_percent";var jt={version:"Version",invalid_configuration:"Invalid configuration",show_warning:"Show Warning",show_error:"Show Error"},zt={common:jt},Bt=Object.freeze({__proto__:null,common:jt,default:zt}),Gt={version:"Versjon",invalid_configuration:"Ikke gyldig konfiguration",show_warning:"Vis advarsel",show_error:"Vis feil"},Kt={common:Gt},qt=Object.freeze({__proto__:null,common:Gt,default:Kt}),Wt={version:"Version",invalid_configuration:"configuración no válida",show_warning:"Mostrar advertencia",show_error:"Mostrar error"},Yt={common:Wt};const Zt={en:Bt,es:Object.freeze({__proto__:null,common:Wt,default:Yt}),nb:qt};function Jt(t,e="",i=""){const o=(localStorage.getItem("selectedLanguage")||"en").replace(/['"]+/g,"").replace("-","_");let s;try{s=t.split(".").reduce(((t,e)=>t[e]),Zt[o])}catch(e){s=t.split(".").reduce(((t,e)=>t[e]),Zt.en)}return void 0===s&&(s=t.split(".").reduce(((t,e)=>t[e]),Zt.en)),""!==e&&""!==i&&(s=s.replace(e,i)),s}console.info(`%c RPI-MONITOR-CARD \n%c ${Jt("common.version")} 1.2.8 `,"color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: dimgray"),window.customCards=window.customCards||[],window.customCards.push({type:"rpi-monitor-card",name:"RPi Monitor Card",description:"A template custom card for you to create something awesome"});let Xt=class extends Q{constructor(){super(...arguments),this._firstTime=!0,this._sensorAvailable=!1,this._hostname="",this.kREPLACE_WITH_TEMP_UNITS="replace-with-temp-units",this._show_debug=!1,this._cardFullElements={"Storage Use":Rt,Storage:Ot,"Memory Use":Lt,Temperature:Vt,"Up-time":Nt,Updated:Mt,OS:Ht,Model:"rpi_model",Interfaces:Ft},this._cardFullIconNames={Storage:"sd","Storage Use":"file-percent","Memory Use":"memory",Temperature:"thermometer","Up-time":"clock-check-outline",Updated:"update",OS:"linux",Model:"raspberry-pi",Interfaces:""},this.kClassIdIconFSAvail="ico-fs-percent",this.kClassIdIconFSTotal="ico-fs-total",this.kClassIdIconSysTemp="ico-sys-temp",this.kClassIdIconUptime="ico-up-time",this.kClassIdIconUpdated="ico-last-update",this.kClassIdIconOS="ico-*nix",this.kClassIdIconRPiModel="ico-rpi-model",this.kClassIdIconInterfaces="ico-rpi-ifaces",this.kClassIdIconMemoryUsage="ico-memory-percent",this.kClassIdFSAvail="fs-percent",this.kClassIdFSTotal="fs-total",this.kClassIdSysTemp="sys-temp",this.kClassIdUptime="up-time",this.kClassIdUpdated="last-update",this.kClassIdOS="*nix",this.kClassIdRPiModel="rpi-model",this.kClassIdInterfaces="rpi-ifaces",this.kClassIdMemoryUsage="memory-percent",this.kClassIdTempScale="sys-temp-scale",this._cardFullCssIDs={"Storage Use":this.kClassIdFSAvail,Storage:this.kClassIdFSTotal,"Memory Use":this.kClassIdMemoryUsage,Temperature:this.kClassIdSysTemp,"Up-time":this.kClassIdUptime,Updated:this.kClassIdUpdated,OS:this.kClassIdOS,Model:this.kClassIdRPiModel,Interfaces:this.kClassIdInterfaces},this._cardFullIconCssIDs={"Storage Use":this.kClassIdIconFSAvail,Storage:this.kClassIdIconFSTotal,"Memory Use":this.kClassIdIconMemoryUsage,"Up-time":this.kClassIdIconUptime,Updated:this.kClassIdIconUpdated,Temperature:this.kClassIdIconSysTemp,OS:this.kClassIdIconOS,Model:this.kClassIdIconRPiModel,Interfaces:this.kClassIdIconInterfaces},this._cardGlanceElements={"%":Rt,GB:Ot,Mem:Lt,"replace-with-temp-units":Vt,UpTime:Nt,Upd:Mt},this._cardGlanceIconNames={"%":"file-percent",GB:"sd",Mem:"memory","replace-with-temp-units":"thermometer",UpTime:"clock-check-outline",Upd:"update"},this._cardGlanceCssIDs={"%":this.kClassIdFSAvail,GB:this.kClassIdFSTotal,Mem:this.kClassIdMemoryUsage,"replace-with-temp-units":this.kClassIdSysTemp,UpTime:this.kClassIdUptime,Upd:this.kClassIdUpdated},this._cardGlanceIconCssIDs={"%":this.kClassIdIconFSAvail,GB:this.kClassIdIconFSTotal,Mem:this.kClassIdIconMemoryUsage,"replace-with-temp-units":this.kClassIdIconSysTemp,UpTime:this.kClassIdIconUptime,Upd:this.kClassIdIconUpdated},this._circleIconsValueByName={"circle-outline":0,"circle-slice-1":13,"circle-slice-2":25,"circle-slice-3":38,"circle-slice-4":50,"circle-slice-5":63,"circle-slice-6":75,"circle-slice-7":88,"circle-slice-8":100},this._colorUsedSpaceDefault=[{color:"undefined",from:0,to:59},{color:"yellow",from:60,to:84},{color:"red",from:85,to:100}],this._colorTemperatureDefault=[{color:"undefined",from:0,to:59},{color:"yellow",from:60,to:79},{color:"red",from:85,to:100}],this._colorReportPeriodsAgoDefault=[{color:"white",from:0,to:3},{color:"yellow",from:4,to:4},{color:"red",from:5,to:100}],this._colorUsedMemoryDefault=[{color:"red",from:75,to:100},{color:"yellow",from:61,to:74},{color:"",from:0,to:60}],this._colorReleaseDefault=[{color:"red",os:"stretch"},{color:"red",os:"jessie"},{color:"red",os:"wheezy"}]}static async getConfigElement(){return document.createElement("rpi-monitor-card-editor")}static getStubConfig(){return{}}setConfig(t){if(this._showDebug()&&console.log("- setConfig()"),!t||t.show_error)throw new Error(Jt("common.invalid_configuration"));if(null!=t.card_style){const e=t.card_style.toLocaleLowerCase();if("full"!=e&&"glance"!=e)throw console.log("Invalid configuration. INVALID card_style = ["+t.card_style+"]"),new Error("Illegal card_style: value (card_style: "+t.card_style+") must be [full or glance]")}if(null!=t.temp_scale){const e=t.temp_scale.toLocaleLowerCase();if("c"!=e&&"f"!=e)throw console.log("Invalid configuration. INVALID temp_scale = ["+t.temp_scale+"]"),new Error("Illegal temp_scale: value (temp_scale: "+t.temp_scale+") must be [F or C]")}if(!t.entity)throw console.log("Invalid configuration. If no entity provided, you'll need to provide a remote entity"),new Error("You need to associate an entity");t.test_gui&&function(){var t=document.querySelector("home-assistant");if(t=(t=(t=(t=(t=(t=(t=(t=t&&t.shadowRoot)&&t.querySelector("home-assistant-main"))&&t.shadowRoot)&&t.querySelector("app-drawer-layout partial-panel-resolver"))&&t.shadowRoot||t)&&t.querySelector("ha-panel-lovelace"))&&t.shadowRoot)&&t.querySelector("hui-root")){var e=t.lovelace;return e.current_view=t.___curView,e}return null}().setEditMode(!0),this._config=Object.assign({},t),this._updateSensorAvailability()}shouldUpdate(t){if(this._updateSensorAvailability(),t.has("_config"))return!0;if(this.hass&&this._config){const e=t.get("hass");if(e)return e.states[this._config.entity]!==this.hass.states[this._config.entity]}return!0}render(){if(this._showDebug()&&console.log("- render()"),this._config.show_warning)return this.showWarning(Jt("common.show_warning"));if(this._config.show_error)return this.showError(Jt("common.show_error"));const t=this._config.entity?this._config.entity:void 0;if(t&&!this._sensorAvailable){const e="Entity Unavailable: "+t;return this.showWarning(e)}const e=this._config.entity?this.hass.states[this._config.entity]:void 0;if(!t&&!e)return this.showWarning("Entity Unavailable");this._firstTime&&(this._showDebug()&&(console.log("- stateObj:"),console.log(e)),this._startCardRefreshTimer(),this._showDebug()&&(console.log("- 1st-time _config:"),console.log(this._config)),this._firstTime=!1);const i=null==this._config.show_os_age||this._config.show_os_age,o=null==this._config.show_update_age||this._config.show_update_age,s=this._getAttributeValueForKey("fqdn");let n="RPi monitor "+s;const r=1==i?this._getAttributeValueForKey(Pt):"";n=null!=this._config.name_prefix?this._config.name_prefix+" "+s:n,n=null!=this._config.name?this._config.name:n;const a=null==this._config.show_title||this._config.show_title;0==a&&(n="");const l=0==a?"last-heard-full-notitle":"last-heard-full",c=0==a?"last-heard-notitle":"last-heard",h=0==a?"os-name-full-notitle":"os-name-full",d=0==a?"os-name-notitle":"os-name",[u,p]=this._getRelativeTimeSinceUpdate(),m=1==o?u:"";if(this._useFullCard()){const t=this._generateFullsizeCardRows();return M`
+ `}};t([ot({attribute:!1})],It.prototype,"hass",void 0),t([st()],It.prototype,"_config",void 0),t([st()],It.prototype,"_toggle",void 0),t([st()],It.prototype,"_helpers",void 0),It=t([et("rpi-monitor-card-editor")],It);class Et{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}const Tt="ontouchstart"in window||navigator.maxTouchPoints>0||navigator.maxTouchPoints>0;class kt extends HTMLElement{constructor(){super(),this.holdTime=500,this.held=!1,this.ripple=document.createElement("mwc-ripple")}connectedCallback(){Object.assign(this.style,{position:"absolute",width:Tt?"100px":"50px",height:Tt?"100px":"50px",transform:"translate(-50%, -50%)",pointerEvents:"none",zIndex:"999"}),this.appendChild(this.ripple),this.ripple.primary=!0,["touchcancel","mouseout","mouseup","touchmove","mousewheel","wheel","scroll"].forEach((t=>{document.addEventListener(t,(()=>{clearTimeout(this.timer),this.stopAnimation(),this.timer=void 0}),{passive:!0})}))}bind(t,e){if(t.actionHandler)return;t.actionHandler=!0,t.addEventListener("contextmenu",(t=>{const e=t||window.event;return e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0,e.returnValue=!1,!1}));const i=t=>{let e,i;this.held=!1,t.touches?(e=t.touches[0].pageX,i=t.touches[0].pageY):(e=t.pageX,i=t.pageY),this.timer=window.setTimeout((()=>{this.startAnimation(e,i),this.held=!0}),this.holdTime)},o=i=>{i.preventDefault(),["touchend","touchcancel"].includes(i.type)&&void 0===this.timer||(clearTimeout(this.timer),this.stopAnimation(),this.timer=void 0,this.held?$t(t,"action",{action:"hold"}):e.hasDoubleClick?"click"===i.type&&i.detail<2||!this.dblClickTimeout?this.dblClickTimeout=window.setTimeout((()=>{this.dblClickTimeout=void 0,$t(t,"action",{action:"tap"})}),250):(clearTimeout(this.dblClickTimeout),this.dblClickTimeout=void 0,$t(t,"action",{action:"double_tap"})):$t(t,"action",{action:"tap"}))};t.addEventListener("touchstart",i,{passive:!0}),t.addEventListener("touchend",o),t.addEventListener("touchcancel",o),t.addEventListener("mousedown",i,{passive:!0}),t.addEventListener("click",o),t.addEventListener("keyup",(t=>{13===t.keyCode&&o(t)}))}startAnimation(t,e){Object.assign(this.style,{left:`${t}px`,top:`${e}px`,display:null}),this.ripple.disabled=!1,this.ripple.active=!0,this.ripple.unbounded=!0}stopAnimation(){this.ripple.active=!1,this.ripple.disabled=!0,this.style.display="none"}}customElements.define("action-handler-rpi-monitor",kt);const Dt=(t,e)=>{const i=(()=>{const t=document.body;if(t.querySelector("action-handler-rpi-monitor"))return t.querySelector("action-handler-rpi-monitor");const e=document.createElement("action-handler-rpi-monitor");return t.appendChild(e),e})();i&&i.bind(t,e)},Ut=(t=>(...e)=>({_$litDirective$:t,values:e}))(class extends Et{update(t,[e]){return Dt(t.element,e),F}render(t){}}),Rt="ifaces",Mt="ux_release",Pt="last_update",Ft="up_time",Ot="fs_total_gb",Nt="fs_free_prcnt",Vt="temperature_c",Ht="show-os-parts",Lt="memory_percent";var zt={version:"Version",invalid_configuration:"Invalid configuration",show_warning:"Show Warning",show_error:"Show Error"},jt={common:zt},Bt=Object.freeze({__proto__:null,common:zt,default:jt}),Gt={version:"Versjon",invalid_configuration:"Ikke gyldig konfiguration",show_warning:"Vis advarsel",show_error:"Vis feil"},Kt={common:Gt},qt=Object.freeze({__proto__:null,common:Gt,default:Kt}),Wt={version:"Version",invalid_configuration:"configuración no válida",show_warning:"Mostrar advertencia",show_error:"Mostrar error"},Yt={common:Wt};const Qt={en:Bt,es:Object.freeze({__proto__:null,common:Wt,default:Yt}),nb:qt};function Zt(t,e="",i=""){const o=(localStorage.getItem("selectedLanguage")||"en").replace(/['"]+/g,"").replace("-","_");let s;try{s=t.split(".").reduce(((t,e)=>t[e]),Qt[o])}catch(e){s=t.split(".").reduce(((t,e)=>t[e]),Qt.en)}return void 0===s&&(s=t.split(".").reduce(((t,e)=>t[e]),Qt.en)),""!==e&&""!==i&&(s=s.replace(e,i)),s}console.info(`%c RPI-MONITOR-CARD \n%c ${Zt("common.version")} 1.2.9 `,"color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: dimgray"),window.customCards=window.customCards||[],window.customCards.push({type:"rpi-monitor-card",name:"RPi Monitor Card",description:"A template custom card for you to create something awesome"});let Jt=class extends X{constructor(){super(...arguments),this._cardSecondsSinceUpdate=0,this._cardUpdateString="",this._firstTime=!0,this._sensorAvailable=!1,this._hostname="",this.kREPLACE_WITH_TEMP_UNITS="replace-with-temp-units",this.kMQTT_DAEMON_RELEASE_URL="https://raw.githubusercontent.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon/master/Release",this.latestDaemonVersions=["v1.6.2","v1.6.1"],this.currentDaemonVersion="",this._show_debug=!1,this._cardFullElements={"Storage Use":Nt,Storage:Ot,"Memory Use":Lt,Temperature:Vt,"Up-time":Ft,Updated:Pt,OS:Ht,Model:"rpi_model",Interfaces:Rt},this._cardFullIconNames={Storage:"sd","Storage Use":"file-percent","Memory Use":"memory",Temperature:"thermometer","Up-time":"clock-check-outline",Updated:"update",OS:"linux",Model:"raspberry-pi",Interfaces:""},this.kClassIdIconFSAvail="ico-fs-percent",this.kClassIdIconFSTotal="ico-fs-total",this.kClassIdIconSysTemp="ico-sys-temp",this.kClassIdIconUptime="ico-up-time",this.kClassIdIconUpdated="ico-last-update",this.kClassIdIconOS="ico-*nix",this.kClassIdIconRPiModel="ico-rpi-model",this.kClassIdIconInterfaces="ico-rpi-ifaces",this.kClassIdIconMemoryUsage="ico-memory-percent",this.kClassIdFSAvail="fs-percent",this.kClassIdFSTotal="fs-total",this.kClassIdSysTemp="sys-temp",this.kClassIdUptime="up-time",this.kClassIdUpdated="last-update",this.kClassIdOS="*nix",this.kClassIdRPiModel="rpi-model",this.kClassIdInterfaces="rpi-ifaces",this.kClassIdMemoryUsage="memory-percent",this.kClassIdTempScale="sys-temp-scale",this._cardFullCssIDs={"Storage Use":this.kClassIdFSAvail,Storage:this.kClassIdFSTotal,"Memory Use":this.kClassIdMemoryUsage,Temperature:this.kClassIdSysTemp,"Up-time":this.kClassIdUptime,Updated:this.kClassIdUpdated,OS:this.kClassIdOS,Model:this.kClassIdRPiModel,Interfaces:this.kClassIdInterfaces},this._cardFullIconCssIDs={"Storage Use":this.kClassIdIconFSAvail,Storage:this.kClassIdIconFSTotal,"Memory Use":this.kClassIdIconMemoryUsage,"Up-time":this.kClassIdIconUptime,Updated:this.kClassIdIconUpdated,Temperature:this.kClassIdIconSysTemp,OS:this.kClassIdIconOS,Model:this.kClassIdIconRPiModel,Interfaces:this.kClassIdIconInterfaces},this._cardGlanceElements={"%":Nt,GB:Ot,Mem:Lt,"replace-with-temp-units":Vt,UpTime:Ft,Upd:Pt},this._cardGlanceIconNames={"%":"file-percent",GB:"sd",Mem:"memory","replace-with-temp-units":"thermometer",UpTime:"clock-check-outline",Upd:"update"},this._cardGlanceCssIDs={"%":this.kClassIdFSAvail,GB:this.kClassIdFSTotal,Mem:this.kClassIdMemoryUsage,"replace-with-temp-units":this.kClassIdSysTemp,UpTime:this.kClassIdUptime,Upd:this.kClassIdUpdated},this._cardGlanceIconCssIDs={"%":this.kClassIdIconFSAvail,GB:this.kClassIdIconFSTotal,Mem:this.kClassIdIconMemoryUsage,"replace-with-temp-units":this.kClassIdIconSysTemp,UpTime:this.kClassIdIconUptime,Upd:this.kClassIdIconUpdated},this._circleIconsValueByName={"circle-outline":0,"circle-slice-1":13,"circle-slice-2":25,"circle-slice-3":38,"circle-slice-4":50,"circle-slice-5":63,"circle-slice-6":75,"circle-slice-7":88,"circle-slice-8":100},this._colorUsedSpaceDefault=[{color:"default",from:0,to:59},{color:"yellow",from:60,to:84},{color:"red",from:85,to:100}],this._colorTemperatureDefault=[{color:"default",from:0,to:59},{color:"yellow",from:60,to:79},{color:"red",from:85,to:100}],this._colorReportPeriodsAgoDefault=[{color:"default",from:0,to:3},{color:"yellow",from:4,to:4},{color:"red",from:5,to:100}],this._colorUsedMemoryDefault=[{color:"red",from:75,to:100},{color:"yellow",from:61,to:74},{color:"default",from:0,to:60}],this._colorReleaseDefault=[{color:"red",os:"stretch"},{color:"red",os:"jessie"},{color:"red",os:"wheezy"}]}static async getConfigElement(){return document.createElement("rpi-monitor-card-editor")}static getStubConfig(){return{}}setConfig(t){if(this._showDebug()&&console.log("- setConfig()"),!t||t.show_error)throw new Error(Zt("common.invalid_configuration"));if(null!=t.card_style){const e=t.card_style.toLocaleLowerCase();if("full"!=e&&"glance"!=e)throw console.log("Invalid configuration. INVALID card_style = ["+t.card_style+"]"),new Error("Illegal card_style: value (card_style: "+t.card_style+") must be [full or glance]")}if(null!=t.temp_scale){const e=t.temp_scale.toLocaleLowerCase();if("c"!=e&&"f"!=e)throw console.log("Invalid configuration. INVALID temp_scale = ["+t.temp_scale+"]"),new Error("Illegal temp_scale: value (temp_scale: "+t.temp_scale+") must be [F or C]")}if(!t.entity)throw console.log("Invalid configuration. If no entity provided, you'll need to provide a remote entity"),new Error("You need to associate an entity");t.test_gui&&function(){var t=document.querySelector("home-assistant");if(t=(t=(t=(t=(t=(t=(t=(t=t&&t.shadowRoot)&&t.querySelector("home-assistant-main"))&&t.shadowRoot)&&t.querySelector("app-drawer-layout partial-panel-resolver"))&&t.shadowRoot||t)&&t.querySelector("ha-panel-lovelace"))&&t.shadowRoot)&&t.querySelector("hui-root")){var e=t.lovelace;return e.current_view=t.___curView,e}return null}().setEditMode(!0),this._config=Object.assign({},t),console.log("- config=["+this._config+"]"),this._updateSensorAvailability()}async loadDaemonReleases(){this.latestDaemonVersions=await fetch(this.kMQTT_DAEMON_RELEASE_URL).then((t=>t.text().then(this._loadDaemonReleaseInfo))),console.log("LDR ("+this._hostname+") latestDaemonVersions=["+this.latestDaemonVersions+"]("+this.latestDaemonVersions.length+")")}shouldUpdate(t){if(this._updateSensorAvailability(),t.has("_config"))return!0;if(this.hass&&this._config){const e=t.get("hass");if(e){return e.states[this._config.entity]!==this.hass.states[this._config.entity]}}return!0}render(){if(this._showDebug()&&console.log("- render("+this._hostname+")"),this._config.show_warning)return this.showWarning(Zt("common.show_warning"));if(this._config.show_error)return this.showError(Zt("common.show_error"));const t=this._config.entity?this._config.entity:void 0;if(t&&!this._sensorAvailable){const e="Entity Unavailable: "+t;return this.showWarning(e)}const e=this._config.entity?this.hass.states[this._config.entity]:void 0;if(!t&&!e)return this.showWarning("Entity Unavailable");if(0==this._sensorAvailable)return void console.log("?? Render w/o sensor!! ("+this._hostname+")");if(this._firstTime){this._showDebug()&&console.log("- stateObj: ["+e+"]");const t=this._getAttributeValueForKey("reporter").split(" ");this.currentDaemonVersion=t.length>1?t[1]:"",this._startCardRefreshTimer(),this._showDebug()&&console.log("- 1st-time _config: ["+this._config+"]"),this._firstTime=!1}const i=null==this._config.show_os_age||this._config.show_os_age,o=null==this._config.show_update_age||this._config.show_update_age,s=this._getAttributeValueForKey("fqdn");let n="RPi monitor "+s;const r=1==i?this._getAttributeValueForKey(Mt):"";let a="";n=null!=this._config.name_prefix?this._config.name_prefix+" "+s:n,n=null!=this._config.name?this._config.name:n;const l=null==this._config.show_title||this._config.show_title;0==l&&(n=""),this._showDebug()&&(console.log("- RNDR currentDaemonVersion=["+this.currentDaemonVersion+"]"),console.log("- RNDR latestDaemonVersions=["+this.latestDaemonVersions+"]")),this.latestDaemonVersions.length>0&&""!=this.currentDaemonVersion?this.currentDaemonVersion!=this.latestDaemonVersions[0]&&(a=this.currentDaemonVersion+" -- ("+this.latestDaemonVersions[0]+" avail.)"):a=""!=this.currentDaemonVersion?this.currentDaemonVersion+" {no info avail.}":"v?.?.? {no info avail.}";const c=0==l?"last-heard-full-notitle":"last-heard-full",h=0==l?"last-heard-notitle":"last-heard",d=0==l?"os-name-full-notitle":"os-name-full",u=0==l?"os-name-notitle":"os-name",p=0==l?"daemon-update-full-notitle":"daemon-update-full",m=0==l?"daemon-update-notitle":"daemon-update",_=1==o?this._cardUpdateString:"";if(this._useFullCard()){const t=this._generateFullsizeCardRows();return 0!=t.length&&t?P`
${t}
-
${m}
-
${r}
+
${_}
+
${r}
+
${a}
- `}{const t=this._generateGlanceCardRows();return M`
+ `:void console.log("ERROR: failed to generate full rows!")}{const t=this._generateGlanceCardRows();return 0!=t.length&&t?P`
${t}
-
${m}
-
${r}
+
${_}
+
${r}
+
${a}
- `}}_getRelativeTimeSinceUpdate(){var t;const e=this._config.entity?this.hass.states[this._config.entity]:void 0;let i="",o=0;if(null!=this.hass.locale&&null!=e){const s=yt(null===(t=this.hass)||void 0===t?void 0:t.localize,e,this.hass.locale),n=void 0===s?"{unknown}":this.prettyDate(s);i=this._sensorAvailable?n:"{unknown}";const r=n.split(" ")[0];o=r.includes("just")||r.includes("unknown")?0:Number(r)}return[i,o]}prettyDate(t){const e=new Date((t||"").replace(/-/g,"/").replace(/[TZ]/g," ")),i=((new Date).getTime()-e.getTime())/1e3,o=Math.floor(i/86400),s=e.getFullYear(),n=e.getMonth()+1,r=e.getDate();if(isNaN(o)||o<0||o>=31)return s.toString()+"-"+(n<10?"0"+n.toString():n.toString())+"-"+(r<10?"0"+r.toString():r.toString());let a="{unknown}";return 0==o?i<60?a="just now":i<120?a="1 minute ago":i<3600?a=Math.floor(i/60)+" minutes ago":i<7200?a="1 hour ago":i<86400&&(a=Math.floor(i/3600)+" hours ago"):1==o?a="Yesterday":o<7?a=o+" days ago":o<31&&(a=Math.ceil(o/7)+" weeks ago"),a}updated(t){if(this._showDebug()&&console.log("- updated()"),!this._config)return;if(this.hass){const e=t.get("hass");(!e||e&&e.themes!==this.hass.themes)&&function(t,e,i,o){void 0===o&&(o=!1),t._themes||(t._themes={});var s=e.default_theme;("default"===i||i&&e.themes[i])&&(s=i);var n=_t({},t._themes);if("default"!==s){var r=e.themes[s];Object.keys(r).forEach((function(e){var i="--"+e;t._themes[i]="",n[i]=r[e]}))}if(t.updateStyles?t.updateStyles(n):window.ShadyCSS&&window.ShadyCSS.styleSubtree(t,n),o){var a=document.querySelector("meta[name=theme-color]");if(a){a.hasAttribute("default-content")||a.setAttribute("default-content",a.getAttribute("content"));var l=n["--primary-color"]||a.getAttribute("default-content");a.setAttribute("content",l)}}}(this,this.hass.themes,this._config.theme)}this.hass.states[this._config.entity]||this._stopCardRefreshTimer();const e=this.shadowRoot;if(this._sensorAvailable){const t=this._getAttributeValueForKey(Pt),i=this._computeOsReleaseColor(t);if(""!=i){e.getElementById("os-name").style.setProperty("color",i)}if(this._useFullCard())for(const t in this._cardFullCssIDs){const i=this._cardFullCssIDs[t],o=this._cardFullElements[t],s=this._getAttributeValueForKey(o),n=this._getFullCardValueForAttributeKey(o);o==Lt&&console.log("- FULL memory latestValue=["+n+"]");const r=e.getElementById(i);r.textContent=n;const a=this._cardFullIconCssIDs[t],l=e.getElementById(a);if(o==Rt){const t=this._computeFileSystemUsageColor(s);""!=t&&(r.style.setProperty("color",t),l.style.setProperty("color",t))}if(o==Lt){const t=this._computeMemoryUsageColor(n.replace(" %",""));""!=t&&(r.style.setProperty("color",t),l.style.setProperty("color",t))}if(o==Vt){const t=this._computeTemperatureColor(s);""!=t&&(r.style.setProperty("color",t),l.style.setProperty("color",t))}}else for(const t in this._cardGlanceCssIDs){const i=this._cardGlanceCssIDs[t],o=this._cardGlanceElements[t],s=this._getAttributeValueForKey(o),n=this._getGlanceCardValueForAttributeKey(o);o==Lt&&console.log("- GLNC memory latestValue=["+n+"]");const r=e.getElementById(i);r.textContent=n;const a=this._cardGlanceIconCssIDs[t],l=e.getElementById(a);if(o==Rt){const t=this._computeFileSystemUsageColor(s);""!=t&&(r.style.setProperty("color",t),l.style.setProperty("color",t))}if(o==Lt){const t=this._computeMemoryUsageColor(n);""!=t&&(r.style.setProperty("color",t),l.style.setProperty("color",t))}if(o==Vt&&"n/a"!=n){const t=this._computeTemperatureColor(s);""!=t&&(r.style.setProperty("color",t),l.style.setProperty("color",t));e.getElementById(this.kClassIdTempScale).textContent=this._getTemperatureScale()}}}}_handleAction(t){this.hass&&this._config&&t.detail.action&&function(t,e,i,o){var s;"double_tap"===o&&i.double_tap_action?s=i.double_tap_action:"hold"===o&&i.hold_action?s=i.hold_action:"tap"===o&&i.tap_action&&(s=i.tap_action),At(t,e,i,s)}(this,this.hass,this._config,t.detail.action)}showWarning(t){return M`
${t} `}showError(t){const e=document.createElement("hui-error-card");return e.setConfig({type:"error",error:t,origConfig:this._config}),M` ${e} `}_startCardRefreshTimer(){this._updateTimerID=setInterval((()=>this._handleCardUpdateTimerExpiration()),1e3)}_stopCardRefreshTimer(){null!=this._updateTimerID&&(clearInterval(this._updateTimerID),this._updateTimerID=void 0)}_handleCardUpdateTimerExpiration(){const t=this.shadowRoot;let e=!1;if(null!=(this._config.entity?this.hass.states[this._config.entity]:void 0)){const i=t.getElementById("card-timestamp");if(i){const t=null==this._config.show_update_age||this._config.show_update_age,[o,s]=this._getRelativeTimeSinceUpdate();if(o){let n=o;o.includes("NaN")&&(n="waiting for report...",e=!0),i.textContent=1==t?n:"";const r=this._computeReporterAgeColor(s);""!=r&&null!=r&&i.style.setProperty("color",r)}e&&this._emptyCardValuesWhileWaitingForSensor()}}}_useFullCard(){let t=!0;return this._config&&null!=this._config.card_style&&(t="full"==this._config.card_style.toLocaleLowerCase()),t}_useTempsInC(){let t=!0;return this._config&&null!=this._config.temp_scale&&(t="c"==this._config.temp_scale.toLocaleLowerCase()),t}_logChangeMessage(t){""==this._hostname&&(this._hostname=this._getAttributeValueForKey("host_name"));const e="("+this._hostname+"): "+t;this._showDebug()&&console.log(e)}_updateSensorAvailability(){let t=!1;if(this.hass&&this._config){const e=this._config.entity?this._config.entity:void 0,i=this._config.entity?this.hass.states[this._config.entity]:void 0;if(e||i)try{const e="unavailable"!=this.hass.states[this._config.entity].state;t=this._sensorAvailable!=e,this._sensorAvailable=e}catch(e){this._sensorAvailable=!1,t=!0}else this._sensorAvailable=!1,t=!0}else this._sensorAvailable=!1,t=!0;t&&this._logChangeMessage("* SENSOR available: "+this._sensorAvailable)}_getIconNameForPercent(t){let e="";for(const i in this._circleIconsValueByName){if(t<=this._circleIconsValueByName[i]){e=i;break}}return e}_computeReporterAgeColor(t){let e;return this._colorReportPeriodsAgoDefault.forEach((i=>{t>=i.from&&t<=i.to&&(e=i.color)})),void 0===e&&(e=""),e}_computeTemperatureColor(t){const e=this._config,i=Number(t),o=e.temp_severity?e.temp_severity:this._colorTemperatureDefault;let s;isNaN(i)||o.forEach((e=>{if(i>=e.from&&i<=e.to){s=e.color;const i="_computeTemperatureColor() - value=["+t+"] matched(from="+e.from+", to="+e.to+", color="+s+")";this._showDebug()&&console.log(i)}}));const n="_computeTemperatureColor() - value=["+t+"] returns(color="+s+")";return this._showDebug()&&console.log(n),null==s&&(s=""),s}_computeFileSystemUsageColor(t){const e=this._config,i=Number(t),o=e.fs_severity?e.fs_severity:this._colorUsedSpaceDefault;let s;isNaN(i)||o.forEach((e=>{if(i>=e.from&&i<=e.to){s=e.color;const i="_computeFileSystemUsageColor() - value=["+t+"] matched(from="+e.from+", to="+e.to+", color="+s+")";this._showDebug()&&console.log(i)}}));const n="_computeFileSystemUsageColor() - value=["+t+"] returns(color="+s+")";return this._showDebug()&&console.log(n),null==s&&(s=""),s}_computeMemoryUsageColor(t){const e=this._config,i=Number(t),o=e.memory_severity?e.memory_severity:this._colorUsedMemoryDefault;let s;isNaN(i)||o.forEach((e=>{if(i>=e.from&&i<=e.to){s=e.color;const i="_computeMemoryUsageColor() - value=["+t+"] matched(from="+e.from+", to="+e.to+", color="+s+")";this._showDebug()&&console.log(i)}}));const n="_computeMemoryUsageColor() - value=["+t+"] returns(color="+s+")";return this._showDebug()&&console.log(n),null==s&&(s=""),s}_computeOsReleaseColor(t){const e=this._config;let i;(e.os_age?e.os_age:this._colorReleaseDefault).forEach((e=>{if(t===e.os){i=e.color;const o="_computeOsReleaseColor() - value=["+t+"] matched(os="+e.os+", color="+i+")";this._showDebug()&&console.log(o)}}));const o="_computeTemperatureColor() - value=["+t+"] returns(color="+i+")";return this._showDebug()&&console.log(o),null==i&&(i=""),i}_filterUptime(t){const e=t.split(" ");let i=t;if(i.includes(":")){for(let t=0;t
=31)return s.toString()+"-"+(n<10?"0"+n.toString():n.toString())+"-"+(r<10?"0"+r.toString():r.toString());let a="{unknown}";return 0==o?i<60?a="just now":i<120?a="1 minute ago":i<3600?a=Math.floor(i/60)+" minutes ago":i<7200?a="1 hour ago":i<86400&&(a=Math.floor(i/3600)+" hours ago"):1==o?a="Yesterday":o<7?a=o+" days ago":o<31&&(a=Math.ceil(o/7)+" weeks ago"),a}updated(t){if(this._showDebug()&&console.log("- updated("+this._hostname+")"),!this._config)return;if(this.hass){const e=t.get("hass");(!e||e&&e.themes!==this.hass.themes)&&function(t,e,i,o){void 0===o&&(o=!1),t._themes||(t._themes={});var s=e.default_theme;("default"===i||i&&e.themes[i])&&(s=i);var n=_t({},t._themes);if("default"!==s){var r=e.themes[s];Object.keys(r).forEach((function(e){var i="--"+e;t._themes[i]="",n[i]=r[e]}))}if(t.updateStyles?t.updateStyles(n):window.ShadyCSS&&window.ShadyCSS.styleSubtree(t,n),o){var a=document.querySelector("meta[name=theme-color]");if(a){a.hasAttribute("default-content")||a.setAttribute("default-content",a.getAttribute("content"));var l=n["--primary-color"]||a.getAttribute("default-content");a.setAttribute("content",l)}}}(this,this.hass.themes,this._config.theme)}this.hass.states[this._config.entity]||this._stopCardRefreshTimer();const e=this.shadowRoot;if(this._sensorAvailable){const t=this._getAttributeValueForKey(Mt),i=this._computeOsReleaseColor(t);if(""!=i){e.getElementById("os-name").style.setProperty("color",i)}const o=this._computeDaemonUpdateVersionColor(this.currentDaemonVersion);if(""!=o){e.getElementById("daemon-update").style.setProperty("color",o)}const s=this._computeReporterAgeColor(this._cardSecondsSinceUpdate);if(""!=s&&null!=s){e.getElementById("card-timestamp").style.setProperty("color",s)}if(this._useFullCard())for(const t in this._cardFullCssIDs){const i=this._cardFullCssIDs[t],o=this._cardFullElements[t],s=this._getAttributeValueForKey(o),n=this._getFullCardValueForAttributeKey(o),r=e.getElementById(i);r.textContent=n;const a=this._cardFullIconCssIDs[t],l=e.getElementById(a);if(o==Nt){const t=this._computeFileSystemUsageColor(s);""!=t&&(r.style.setProperty("color",t),l.style.setProperty("color",t))}if(o==Lt){const t=this._computeMemoryUsageColor(n.replace(" %",""));""!=t&&(r.style.setProperty("color",t),l.style.setProperty("color",t))}if(o==Vt){const t=this._computeTemperatureColor(s);""!=t&&(r.style.setProperty("color",t),l.style.setProperty("color",t))}}else for(const t in this._cardGlanceCssIDs){const i=this._cardGlanceCssIDs[t],o=this._cardGlanceElements[t],s=this._getAttributeValueForKey(o),n=this._getGlanceCardValueForAttributeKey(o),r=e.getElementById(i);r.textContent=n;const a=this._cardGlanceIconCssIDs[t],l=e.getElementById(a);if(o==Nt){const t=this._computeFileSystemUsageColor(s);""!=t&&(r.style.setProperty("color",t),l.style.setProperty("color",t))}if(o==Lt){const t=this._computeMemoryUsageColor(n);""!=t&&(r.style.setProperty("color",t),l.style.setProperty("color",t))}if(o==Vt&&"n/a"!=n){const t=this._computeTemperatureColor(s);""!=t&&(r.style.setProperty("color",t),l.style.setProperty("color",t));e.getElementById(this.kClassIdTempScale).textContent=this._getTemperatureScale()}}}}_handleAction(t){this.hass&&this._config&&t.detail.action&&function(t,e,i,o){var s;"double_tap"===o&&i.double_tap_action?s=i.double_tap_action:"hold"===o&&i.hold_action?s=i.hold_action:"tap"===o&&i.tap_action&&(s=i.tap_action),At(t,e,i,s)}(this,this.hass,this._config,t.detail.action)}showWarning(t){return P` ${t} `}showError(t){const e=document.createElement("hui-error-card");return e.setConfig({type:"error",error:t,origConfig:this._config}),P` ${e} `}_startCardRefreshTimer(){this._updateTimerID=setInterval((()=>this._handleCardUpdateTimerExpiration()),1e3),console.log("TIMER: ("+this._hostname+") started")}_stopCardRefreshTimer(){null!=this._updateTimerID&&(clearInterval(this._updateTimerID),this._updateTimerID=void 0,console.log("TIMER: ("+this._hostname+") STOPPED"))}_handleCardUpdateTimerExpiration(){const[t,e]=this._getRelativeTimeSinceUpdate();if(this._cardSecondsSinceUpdate!=e&&(this._cardSecondsSinceUpdate=e),t){let e=t;t.includes("NaN")&&(console.log(" HCUTE (DBG) ("+this._hostname+") card_timestamp_value=["+t+"]"),e="{unexpected value}..."),this._cardUpdateString!=e&&(this._cardUpdateString=e)}}_useFullCard(){let t=!0;return this._config&&null!=this._config.card_style&&(t="full"==this._config.card_style.toLocaleLowerCase()),t}_useTempsInC(){let t=!0;return this._config&&null!=this._config.temp_scale&&(t="c"==this._config.temp_scale.toLocaleLowerCase()),t}_logChangeMessage(t){""==this._hostname&&(this._hostname=this._getAttributeValueForKey("host_name"));const e="("+this._hostname+"): "+t;this._showDebug()&&console.log(e)}_updateSensorAvailability(){let t=!1;if(this.hass&&this._config){const e=this._config.entity?this._config.entity:void 0,i=this._config.entity?this.hass.states[this._config.entity]:void 0;if(e||i)try{const e="unavailable"!=this.hass.states[this._config.entity].state;t=this._sensorAvailable!=e,this._sensorAvailable=e}catch(e){this._sensorAvailable=!1,t=!0}else this._sensorAvailable=!1,t=!0}else this._sensorAvailable=!1,t=!0;t&&this._logChangeMessage("* SENSOR available: "+this._sensorAvailable)}_loadDaemonReleaseInfo(t){let e=[];if(t){const i=t.split("\n");for(let t=0;t0){const t=o.split(" ");t.length>0&&(e.includes(t[0])||e.push(t[0]))}}}return e}_getRelativeTimeSinceUpdate(){var t;const e=this._config.entity?this.hass.states[this._config.entity]:void 0;let i="",o=0,s="";if(null!=this.hass.locale&&null!=e){try{const o=yt(null===(t=this.hass)||void 0===t?void 0:t.localize,e,this.hass.locale),n=void 0===o?"{unknown}":this.prettyDate(o);i=this._sensorAvailable?n:"{unknown}";s=n.split(" ")[0]}catch(t){console.log("GRTSU - exception:"),console.error(t)}o=s.includes("just")||s.includes("unknown")?0:Number(s)}return[i,o]}_getIconNameForPercent(t){let e="";for(const i in this._circleIconsValueByName){if(t<=this._circleIconsValueByName[i]){e=i;break}}return e}_computeReporterAgeColor(t){let e;return this._colorReportPeriodsAgoDefault.forEach((i=>{t>=i.from&&t<=i.to&&(e=i.color)})),null!=e&&"default"!=e||(e=""),e}_computeTemperatureColor(t){const e=this._config,i=Number(t),o=e.temp_severity?e.temp_severity:this._colorTemperatureDefault;let s;if(isNaN(i)||o.forEach((e=>{if(i>=e.from&&i<=e.to&&(s=e.color,this._showDebug())){const i="_computeTemperatureColor() - value=["+t+"] matched(from="+e.from+", to="+e.to+", color="+s+")";console.log(i)}})),this._showDebug()){const e="_computeTemperatureColor() - value=["+t+"] returns(color="+s+")";console.log(e)}return null!=s&&"default"!=s||(s=""),s}_computeFileSystemUsageColor(t){const e=this._config,i=Number(t),o=e.fs_severity?e.fs_severity:this._colorUsedSpaceDefault;let s;if(isNaN(i)||o.forEach((e=>{if(i>=e.from&&i<=e.to&&(s=e.color,this._showDebug())){const i="_computeFileSystemUsageColor() - value=["+t+"] matched(from="+e.from+", to="+e.to+", color="+s+")";console.log(i)}})),this._showDebug()){const e="_computeFileSystemUsageColor() - value=["+t+"] returns(color="+s+")";console.log(e)}return null!=s&&"default"!=s||(s=""),s}_computeMemoryUsageColor(t){const e=this._config,i=Number(t),o=e.memory_severity?e.memory_severity:this._colorUsedMemoryDefault;let s;if(isNaN(i)||o.forEach((e=>{if(i>=e.from&&i<=e.to&&(s=e.color,this._showDebug())){const i="_computeMemoryUsageColor() - value=["+t+"] matched(from="+e.from+", to="+e.to+", color="+s+")";console.log(i)}})),this._showDebug()){const e="_computeMemoryUsageColor() - value=["+t+"] returns(color="+s+")";console.log(e)}return null!=s&&"default"!=s||(s=""),s}_computeOsReleaseColor(t){const e=this._config,i=e.os_age?e.os_age:this._colorReleaseDefault;let o="default";if(i.forEach((e=>{if(t===e.os&&(o=e.color,this._showDebug())){const i="_computeOsReleaseColor() - value=["+t+"] matched(os="+e.os+", color="+o+")";console.log(i)}})),this._showDebug()){const e="_computeOsReleaseColor() - value=["+t+"] returns(color="+o+")";console.log(e)}return null!=o&&"default"!=o||(o=""),o}_computeDaemonUpdateVersionColor(t){let e;if(e=this.latestDaemonVersions.length>0&&""!=t?this.latestDaemonVersions[0]==t?"default":this.latestDaemonVersions.includes(t)?"yellow":"red":"orange",this._showDebug()){const i="_computeDaemonUpdateVersionColor() - value=["+t+"] returns(color="+e+")";console.log(i)}return null!=e&&"default"!=e||(e=""),e}_filterUptime(t){const e=t.split(" ");let i=t;if(i.includes(":")){for(let t=0;t
@@ -223,7 +225,7 @@ const et=t=>e=>"function"==typeof e?((t,e)=>(customElements.define(t,e),e))(t,e)
${o}
- `)}return t}_generateGlanceCardRows(){const t=[];for(const e in this._cardGlanceElements){const i=this._cardGlanceElements[e],o=this._getGlanceCardValueForAttributeKey(i);let s=e;s==this.kREPLACE_WITH_TEMP_UNITS&&(s="n/a"!=o?this._getTemperatureScale():""),i==Lt&&(s="% Mem");let n=this._cardGlanceIconNames[e];i==Rt&&(n=this._getIconNameForPercent(o));const r=this._cardGlanceCssIDs[e],a=this._cardGlanceIconCssIDs[e];let l="units";i==Vt&&(l=this.kClassIdTempScale),t.push(M`
+ `)}return t}_generateGlanceCardRows(){const t=[];for(const e in this._cardGlanceElements){const i=this._cardGlanceElements[e],o=this._getGlanceCardValueForAttributeKey(i);let s=e;s==this.kREPLACE_WITH_TEMP_UNITS&&(s="n/a"!=o?this._getTemperatureScale():""),i==Lt&&(s="% Mem");let n=this._cardGlanceIconNames[e];i==Nt&&(n=this._getIconNameForPercent(o));const r=this._cardGlanceCssIDs[e],a=this._cardGlanceIconCssIDs[e];let l="units";i==Vt&&(l=this.kClassIdTempScale),t.push(P`
@@ -231,7 +233,7 @@ const et=t=>e=>"function"==typeof e?((t,e)=>(customElements.define(t,e),e))(t,e)
${o}
${s}
- `)}return t}_getTemperatureScale(){const t=1==this._useTempsInC()?"ºC":"ºF",e="_getTemperatureScale() scaleInterp=("+t+")";return this._showDebug()&&console.log(e),t}_getScaledTemperatureValue(t){let e=t;"n/a"!=e&&0==this._useTempsInC()&&(e=(9*parseFloat(t)/5+32).toFixed(1));const i="_getScaledTemperatureValue("+t+") scaleInterp=("+e+")";return this._showDebug()&&console.log(i),e}_getFullCardValueForAttributeKey(t){const e=this._getAttributeValueForKey(t);let i=e;if(t==Lt)i=this._getPercentMemoryUsed()+" %";else if(t==Mt)i=this._getUIDateForTimestamp(e);else if(t==Vt){if(i=this._getScaledTemperatureValue(e),"n/a"!=i){i=i+" "+this._getTemperatureScale()}}else if(t==Ot)i=e+" GB";else if(t==Rt)i=e+" %";else if(t==Nt)i=this._filterUptime(i);else if(t==Ht){i=this._getAttributeValueForKey(Pt)+" v"+this._getAttributeValueForKey("ux_version")}else if(t==Ft){const t=[];e.includes("e")&&t.push("Ether"),e.includes("w")&&t.push("WiFi"),e.includes("b")&&t.push("Bluetooth"),i=t.join(", ")}return i}_getGlanceCardValueForAttributeKey(t){const e=this._getAttributeValueForKey(t);let i=e;return t==Lt?i=this._getPercentMemoryUsed():t==Mt?i=this._getUIDateForTimestamp(e):t==Vt?i=this._getScaledTemperatureValue(e):t==Nt&&(i=this._filterUptime(i)),i}_getUIDateForTimestamp(t){return new Date(t).toLocaleDateString("en-us")}_getPercentMemoryUsed(){const t=this._getAttributeValueForKey("memory"),e=t.size_mb,i=t.free_mb,o=Number(e);return((e-Number(i))/o*100).toFixed(0).toString()}_showDebug(){let t=this._show_debug;return this._config&&null!=this._config.show_debug&&(t=1==t||1==this._config.show_debug),t}static get styles(){return r`
+ `)}return t}_getTemperatureScale(){return 1==this._useTempsInC()?"ºC":"ºF"}_getScaledTemperatureValue(t){let e=t;return"n/a"!=e&&0==this._useTempsInC()&&(e=(9*parseFloat(t)/5+32).toFixed(1)),e}_getFullCardValueForAttributeKey(t){const e=this._getAttributeValueForKey(t);let i=e;if(t==Lt)i=this._getPercentMemoryUsed()+" %";else if(t==Pt)i=this._getUIDateForTimestamp(e);else if(t==Vt){if(i=this._getScaledTemperatureValue(e),"n/a"!=i){i=i+" "+this._getTemperatureScale()}}else if(t==Ot)i=e+" GB";else if(t==Nt)i=e+" %";else if(t==Ft)i=this._filterUptime(i);else if(t==Ht){i=this._getAttributeValueForKey(Mt)+" v"+this._getAttributeValueForKey("ux_version")}else if(t==Rt){const t=[];e.includes("e")&&t.push("Ether"),e.includes("w")&&t.push("WiFi"),e.includes("b")&&t.push("Bluetooth"),i=t.join(", ")}return i}_getGlanceCardValueForAttributeKey(t){const e=this._getAttributeValueForKey(t);let i=e;return t==Lt?i=this._getPercentMemoryUsed():t==Pt?i=this._getUIDateForTimestamp(e):t==Vt?i=this._getScaledTemperatureValue(e):t==Ft&&(i=this._filterUptime(i)),i}_getUIDateForTimestamp(t){return new Date(t).toLocaleDateString("en-us")}_getPercentMemoryUsed(){const t=this._getAttributeValueForKey("memory"),e=t.size_mb,i=t.free_mb,o=Number(e);return((e-Number(i))/o*100).toFixed(0).toString()}_showDebug(){let t=this._show_debug;return this._config&&null!=this._config.show_debug&&(t=1==t||1==this._config.show_debug),t}static get styles(){return r`
ha-card {
height: 100%;
display: flex;
@@ -371,4 +373,32 @@ const et=t=>e=>"function"==typeof e?((t,e)=>(customElements.define(t,e),e))(t,e)
font-size: 12px;
color: var(--primary-text-color);
}
- `}};t([ot({attribute:!1})],Xt.prototype,"hass",void 0),t([st()],Xt.prototype,"_config",void 0),Xt=t([et("rpi-monitor-card")],Xt);export{Xt as RPiMonitorCard};
+ .daemon-update-full {
+ position: absolute;
+ top: 45px;
+ right: 150px;
+ font-size: 12px;
+ color: var(--primary-text-color);
+ }
+ .daemon-update {
+ position: absolute;
+ top: 55px;
+ right: 150px;
+ font-size: 12px;
+ color: var(--primary-text-color);
+ }
+ .daemon-update-full-notitle {
+ position: absolute;
+ top: 3px;
+ right: 150px;
+ font-size: 12px;
+ color: var(--primary-text-color);
+ }
+ .daemon-update-notitle {
+ position: absolute;
+ bottom: 5px;
+ right: 210px;
+ font-size: 12px;
+ color: var(--primary-text-color);
+ }
+ `}};t([ot({attribute:!1})],Jt.prototype,"hass",void 0),t([st()],Jt.prototype,"_config",void 0),t([st()],Jt.prototype,"_cardSecondsSinceUpdate",void 0),t([st()],Jt.prototype,"_cardUpdateString",void 0),Jt=t([et("rpi-monitor-card")],Jt);export{Jt as RPiMonitorCard};
diff --git a/package.json b/package.json
index 8094593..0c7936b 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "rpi-monitor-card",
- "version": "1.2.8",
+ "version": "1.2.9",
"description": "Lovelace RPi Monitor Card",
"keywords": [
"home-assistant",
@@ -24,7 +24,7 @@
"@material/mwc-select": "^0.25.3",
"@material/mwc-switch": "^0.25.3",
"@material/mwc-textfield": "^0.25.3",
- "custom-card-helpers": "^1.7.2",
+ "custom-card-helpers": "^1.9.0",
"home-assistant-js-websocket": "^5.11.1",
"lit": "^2.6.1",
"tslib": "2.3.1"
diff --git a/src/const.ts b/src/const.ts
index 1ebedc7..a6f428a 100644
--- a/src/const.ts
+++ b/src/const.ts
@@ -1,4 +1,4 @@
-export const CARD_VERSION = '1.2.8';
+export const CARD_VERSION = '1.2.9';
/*
* EXAMPLE attributes ISP-RPi-mqtt-daemon.py v1.5.4
diff --git a/src/rpi-monitor-card.ts b/src/rpi-monitor-card.ts
index 339534d..36b2cff 100644
--- a/src/rpi-monitor-card.ts
+++ b/src/rpi-monitor-card.ts
@@ -54,6 +54,8 @@ export class RPiMonitorCard extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@state() private _config!: RPiMonitorCardConfig;
+ @state() private _cardSecondsSinceUpdate: number = 0;
+ @state() private _cardUpdateString: string = '';
// and those that don't cause a re-render
private _firstTime: boolean = true;
@@ -61,10 +63,13 @@ export class RPiMonitorCard extends LitElement {
private _updateTimerID: NodeJS.Timeout | undefined;
private _hostname: string = '';
private kREPLACE_WITH_TEMP_UNITS: string = 'replace-with-temp-units';
+ private kMQTT_DAEMON_RELEASE_URL: string =
+ 'https://raw.githubusercontent.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon/master/Release';
+ private latestDaemonVersions: string[] = ['v1.6.2', 'v1.6.1']; // REMOVE BEFORE FLIGHT (TEST DATA)
+ private currentDaemonVersion: string = '';
// WARNING set following to false before commit!
- private _show_debug: boolean = false;
- //private _show_debug: boolean = true;
+ private _show_debug: boolean = false; // REMOVE BEFORE FLIGHT (set to false!)
//
// FULL-SIZE CARD tables
@@ -81,6 +86,7 @@ export class RPiMonitorCard extends LitElement {
Model: Constants.RPI_MODEL_KEY,
Interfaces: Constants.RPI_INTERFACES_KEY,
};
+
private _cardFullIconNames = {
// top to bottom
Storage: 'sd',
@@ -208,7 +214,7 @@ export class RPiMonitorCard extends LitElement {
// user sets 'fs_severity' to override
private _colorUsedSpaceDefault = [
{
- color: 'undefined',
+ color: 'default',
from: 0,
to: 59,
},
@@ -228,7 +234,7 @@ export class RPiMonitorCard extends LitElement {
// user sets 'temp_severity' to override
private _colorTemperatureDefault = [
{
- color: 'undefined',
+ color: 'default',
from: 0,
to: 59,
},
@@ -248,7 +254,7 @@ export class RPiMonitorCard extends LitElement {
// no user override for now
private _colorReportPeriodsAgoDefault = [
{
- color: 'white',
+ color: 'default',
from: 0,
to: 3,
},
@@ -278,7 +284,7 @@ export class RPiMonitorCard extends LitElement {
to: 74,
},
{
- color: '',
+ color: 'default',
from: 0,
to: 60,
},
@@ -350,10 +356,27 @@ export class RPiMonitorCard extends LitElement {
...config,
};
- //console.log('- config:');
- //console.log(this._config);
+ console.log('- config=[' + this._config + ']');
this._updateSensorAvailability();
+
+ // request the release info from the DAEMON repository
+ //this.loadDaemonReleases();
+ }
+
+ private async loadDaemonReleases(): Promise
{
+ this.latestDaemonVersions = await fetch(this.kMQTT_DAEMON_RELEASE_URL).then((response) =>
+ response.text().then(this._loadDaemonReleaseInfo),
+ );
+ console.log(
+ 'LDR (' +
+ this._hostname +
+ ') latestDaemonVersions=[' +
+ this.latestDaemonVersions +
+ '](' +
+ this.latestDaemonVersions.length +
+ ')',
+ );
}
/*
@@ -366,10 +389,12 @@ export class RPiMonitorCard extends LitElement {
// https://lit.dev/docs/components/lifecycle/#reactive-update-cycle-performing
protected shouldUpdate(changedProps: PropertyValues): boolean {
//return hasConfigOrEntityChanged(this, changedProps, false);
+ //console.log('shouldUpdate(' + this._hostname + ') changedProps= [' + changedProps.keys() + ']');
this._updateSensorAvailability();
if (changedProps.has('_config')) {
+ //console.log('shouldUpdate(' + this._hostname + ') = [' + true + '] - CONFIG');
return true;
}
@@ -378,10 +403,13 @@ export class RPiMonitorCard extends LitElement {
if (oldHass) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- return oldHass.states[this._config.entity!] !== this.hass.states[this._config.entity!];
+ const bShouldStatus: boolean = oldHass.states[this._config.entity!] !== this.hass.states[this._config.entity!];
+ //console.log('shouldUpdate(' + this._hostname + ') = [' + bShouldStatus + '] HASS');
+ return bShouldStatus;
}
}
+ //console.log('shouldUpdate(' + this._hostname + ') = [' + true + '] other');
return true;
}
@@ -389,7 +417,7 @@ export class RPiMonitorCard extends LitElement {
protected render(): TemplateResult | void {
// Check for stateObj or other necessary things and render a warning if missing
if (this._showDebug()) {
- console.log('- render()');
+ console.log('- render(' + this._hostname + ')');
}
if (this._config.show_warning) {
return this.showWarning(localize('common.show_warning'));
@@ -412,19 +440,28 @@ export class RPiMonitorCard extends LitElement {
return this.showWarning('Entity Unavailable');
}
+ // don't let render happen on no-sensor!
+ if (this._sensorAvailable == false) {
+ console.log('?? Render w/o sensor!! (' + this._hostname + ')');
+ return;
+ }
+
if (this._firstTime) {
if (this._showDebug()) {
- console.log('- stateObj:');
- console.log(stateObj);
+ console.log('- stateObj: [' + stateObj + ']');
}
+ const reporter_version: string = this._getAttributeValueForKey(Constants.RPI_SCRIPT_VER_KEY);
+ const reportParts: string[] = reporter_version.split(' ');
+ this.currentDaemonVersion = reportParts.length > 1 ? reportParts[1] : '';
+ //console.log('- 1st-time currentDaemonVersion=[' + this.currentDaemonVersion + ']');
+
// set timer so our card updates timestamp every 5 seconds : 5000 (1 second: 1000)
// FIXME: UNDONE remember to clear this interval when entity NOT avail. and restore when comes avail again...
this._startCardRefreshTimer();
if (this._showDebug()) {
- console.log('- 1st-time _config:');
- console.log(this._config);
+ console.log('- 1st-time _config: [' + this._config + ']');
}
this._firstTime = false;
}
@@ -437,6 +474,7 @@ export class RPiMonitorCard extends LitElement {
const rpi_fqdn: string = this._getAttributeValueForKey(Constants.RPI_FQDN_KEY);
let cardName: string = 'RPi monitor ' + rpi_fqdn;
const ux_release: string = showOsAge == true ? this._getAttributeValueForKey(Constants.RPI_NIX_RELEASE_KEY) : '';
+ let daemon_update_status: string = '';
cardName = this._config.name_prefix != undefined ? this._config.name_prefix + ' ' + rpi_fqdn : cardName;
cardName = this._config.name != undefined ? this._config.name : cardName;
@@ -446,22 +484,41 @@ export class RPiMonitorCard extends LitElement {
cardName = '';
}
- const last_heard_full_class = showCardName == false ? 'last-heard-full-notitle' : 'last-heard-full';
+ if (this._showDebug()) {
+ console.log('- RNDR currentDaemonVersion=[' + this.currentDaemonVersion + ']');
+ console.log('- RNDR latestDaemonVersions=[' + this.latestDaemonVersions + ']');
+ }
+ if (this.latestDaemonVersions.length > 0 && this.currentDaemonVersion != '') {
+ if (this.currentDaemonVersion != this.latestDaemonVersions[0]) {
+ // reporter version is not latest
+ daemon_update_status = this.currentDaemonVersion + ' -- (' + this.latestDaemonVersions[0] + ' avail.)';
+ }
+ } else {
+ if (this.currentDaemonVersion != '') {
+ daemon_update_status = this.currentDaemonVersion + ' {no info avail.}';
+ } else {
+ daemon_update_status = 'v?.?.? {no info avail.}';
+ }
+ }
+ const last_heard_full_class = showCardName == false ? 'last-heard-full-notitle' : 'last-heard-full';
const last_heard_class = showCardName == false ? 'last-heard-notitle' : 'last-heard';
const os_name_full_class = showCardName == false ? 'os-name-full-notitle' : 'os-name-full';
-
const os_name_class = showCardName == false ? 'os-name-notitle' : 'os-name';
- const [card_timestamp_value, minsSinceUpdate] = this._getRelativeTimeSinceUpdate();
- if (minsSinceUpdate) {
- } // kill compiler warning
- const card_timestamp = showCardAge == true ? card_timestamp_value : '';
+ const daemon_update_full_class = showCardName == false ? 'daemon-update-full-notitle' : 'daemon-update-full';
+ const daemon_update_class = showCardName == false ? 'daemon-update-notitle' : 'daemon-update';
+
+ const card_timestamp = showCardAge == true ? this._cardUpdateString : '';
if (this._useFullCard()) {
// our FULL card
const fullRows = this._generateFullsizeCardRows();
+ if (fullRows.length == 0 || !fullRows) {
+ console.log('ERROR: failed to generate full rows!');
+ return;
+ }
return html`
${card_timestamp}
${ux_release}
+ ${daemon_update_status}
`;
} else {
// our GLANCE card
const glanceRows = this._generateGlanceCardRows();
+ if (glanceRows.length == 0 || !glanceRows) {
+ console.log('ERROR: failed to generate glance rows!');
+ return;
+ }
return html`