home-assistant-javascript-templates 5.3.0 → 5.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t,e,n){if(n||2===arguments.length)for(var i,s=0,r=e.length;s<r;s++)!i&&s in e||(i||(i=Array.prototype.slice.call(e,0,s)),i[s]=e[s]);return t.concat(i||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var e,n,i,s,r="[home-assistant-javascript-templates]",a=/^([a-z_]+)\.(\w+)$/;!function(t){t.UNKNOWN="unknown",t.UNAVAILABLE="unavailable"}(e||(e={})),function(t){t.AREA_ID="area_id",t.NAME="name"}(n||(n={})),function(t){t.PANEL_URL="panel_url"}(i||(i={})),function(t){t.LOCATION_CHANGED="location-changed",t.POPSTATE="popstate",t.SUBSCRIBE_EVENTS="subscribe_events",t.STATE_CHANGE_EVENT="state_changed"}(s||(s={}));var o=function(t){return t.reduce((function(t,e){var n=e[0],i=e[1];return t[n.replace(a,"$2")]=i,t}),{})},c=function(t){return t.includes(".")};function u(t,s){var a=function(){return Object.entries(t.hass.areas)},u=function(){return Object.entries(t.hass.entities)},d=new Set,_=function(t,e){s&&console.warn("".concat(t," ").concat(e," used in a JavaScript template doesn't exist"))},p=function(t){return _("Entity",t)},h=function(t){return _("Domain",t)},v=function(e){t.hass.states[e]?d.add(e):p(e)};return{get hass(){return t.hass},states:new Proxy((function(e){var n;if(c(e))return v(e),null===(n=t.hass.states[e])||void 0===n?void 0:n.state;throw SyntaxError("".concat(r,": states method cannot be used with a domain, use it as an object instead."))}),{get:function(e,n){if(c(n))return v(n),t.hass.states[n];var i=Object.entries(t.hass.states).filter((function(t){return t[0].startsWith(n)}));return i.length||h(n),new Proxy(o(i),{get:function(t,e){return v("".concat(n,".").concat(e)),t[e]}})}}),is_state:function(e,n){var i;return v(e),(null===(i=t.hass.states[e])||void 0===i?void 0:i.state)===n},state_attr:function(e,n){var i,s;return v(e),null===(s=null===(i=t.hass.states[e])||void 0===i?void 0:i.attributes)||void 0===s?void 0:s[n]},is_state_attr:function(t,e,n){return this.state_attr(t,e)===n},has_value:function(t){return this.states(t)?!(this.is_state(t,e.UNKNOWN)||this.is_state(t,e.UNAVAILABLE)):(p(t),!1)},entities:new Proxy((function(e){if(void 0===e)return t.hass.entities;if(c(e))return v(e),t.hass.entities[e];var n=u().filter((function(t){return t[0].startsWith(e)}));return n.length||h(e),new Proxy(o(n),{get:function(t,n){return v("".concat(e,".").concat(n)),t[n]}})}),{get:function(t,e){return t(e)}}),entity_prop:function(e,n){var i;return v(e),null===(i=t.hass.entities[e])||void 0===i?void 0:i[n]},is_entity_prop:function(t,e,n){return this.entity_prop(t,e)===n},devices:new Proxy((function(e){if(void 0===e)return t.hass.devices;if(c(e))throw SyntaxError("".concat(r,": devices method cannot be used with an entity id, you should use a device id instead."));return t.hass.devices[e]}),{get:function(e,n){if(c(n))throw SyntaxError("".concat(r,": devices cannot be accesed using an entity id, you should use a device id instead."));return t.hass.devices[n]}}),device_attr:function(e,n){var i;return null===(i=t.hass.devices[e])||void 0===i?void 0:i[n]},is_device_attr:function(t,e,n){return this.device_attr(t,e)===n},device_id:function(e){var n;return v(e),null===(n=t.hass.entities[e])||void 0===n?void 0:n.device_id},areas:function(){return a().map((function(t){return t[1].area_id}))},area_id:function(e){var i,s;if(e in t.hass.devices)return this.device_attr(e,n.AREA_ID);var r=null===(i=t.hass.entities[e])||void 0===i?void 0:i.device_id;if(r)return this.device_attr(r,n.AREA_ID);var o=a().find((function(t){return t[1].name===e}));return null===(s=null==o?void 0:o[1])||void 0===s?void 0:s.area_id},area_name:function(e){var i,s,r;e in t.hass.devices&&(r=this.device_attr(e,n.AREA_ID));var o=null===(i=t.hass.entities[e])||void 0===i?void 0:i.device_id;o&&(r=this.device_attr(o,n.AREA_ID));var c=a().find((function(t){var n=t[1];return n.area_id===e||n.area_id===r}));return null===(s=null==c?void 0:c[1])||void 0===s?void 0:s.name},area_entities:function(t){var e=a().find((function(e){var n=e[1];return n.area_id===t||n.name===t}));return e?u().filter((function(t){return t[1].area_id===e[1].area_id})).map((function(t){return t[0]})):[]},area_devices:function(e){var n=a().find((function(t){var n=t[1];return n.area_id===e||n.name===e}));return n?Object.entries(t.hass.devices).filter((function(t){return t[1].area_id===n[1].area_id})).map((function(t){return t[1].id})):[]},get user_name(){return t.hass.user.name},get user_is_admin(){return t.hass.user.is_admin},get user_is_owner(){return t.hass.user.is_owner},get user_agent(){return window.navigator.userAgent},get panel_url(){var t;return t=i.PANEL_URL,d.add(t),location.pathname},get tracked(){return d},cleanTracked:function(){d.clear()}}}var d=function(){function e(t,e){var n=e.throwErrors,i=void 0!==n&&n,s=e.throwWarnings,r=void 0===s||s,a=e.variables,o=void 0===a?{}:a;this._throwErrors=i,this._throwWarnings=r,this._variables=
|
|
1
|
+
function t(t,e,n){if(n||2===arguments.length)for(var i,s=0,r=e.length;s<r;s++)!i&&s in e||(i||(i=Array.prototype.slice.call(e,0,s)),i[s]=e[s]);return t.concat(i||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var e,n,i,s,r="[home-assistant-javascript-templates]",a=/^([a-z_]+)\.(\w+)$/;!function(t){t.UNKNOWN="unknown",t.UNAVAILABLE="unavailable"}(e||(e={})),function(t){t.AREA_ID="area_id",t.NAME="name"}(n||(n={})),function(t){t.PANEL_URL="panel_url"}(i||(i={})),function(t){t.LOCATION_CHANGED="location-changed",t.POPSTATE="popstate",t.SUBSCRIBE_EVENTS="subscribe_events",t.STATE_CHANGE_EVENT="state_changed"}(s||(s={}));var o=function(t){return t.reduce((function(t,e){var n=e[0],i=e[1];return t[n.replace(a,"$2")]=i,t}),{})},c=function(t){return t.includes(".")};function u(t,s){var a=function(){return Object.entries(t.hass.areas)},u=function(){return Object.entries(t.hass.entities)},d=new Set,_=function(t,e){s&&console.warn("".concat(t," ").concat(e," used in a JavaScript template doesn't exist"))},p=function(t){return _("Entity",t)},h=function(t){return _("Domain",t)},v=function(e){t.hass.states[e]?d.add(e):p(e)};return{get hass(){return t.hass},states:new Proxy((function(e){var n;if(c(e))return v(e),null===(n=t.hass.states[e])||void 0===n?void 0:n.state;throw SyntaxError("".concat(r,": states method cannot be used with a domain, use it as an object instead."))}),{get:function(e,n){if(c(n))return v(n),t.hass.states[n];var i=Object.entries(t.hass.states).filter((function(t){return t[0].startsWith(n)}));return i.length||h(n),new Proxy(o(i),{get:function(t,e){return v("".concat(n,".").concat(e)),t[e]}})}}),is_state:function(e,n){var i;return v(e),(null===(i=t.hass.states[e])||void 0===i?void 0:i.state)===n},state_attr:function(e,n){var i,s;return v(e),null===(s=null===(i=t.hass.states[e])||void 0===i?void 0:i.attributes)||void 0===s?void 0:s[n]},is_state_attr:function(t,e,n){return this.state_attr(t,e)===n},has_value:function(t){return this.states(t)?!(this.is_state(t,e.UNKNOWN)||this.is_state(t,e.UNAVAILABLE)):(p(t),!1)},entities:new Proxy((function(e){if(void 0===e)return t.hass.entities;if(c(e))return v(e),t.hass.entities[e];var n=u().filter((function(t){return t[0].startsWith(e)}));return n.length||h(e),new Proxy(o(n),{get:function(t,n){return v("".concat(e,".").concat(n)),t[n]}})}),{get:function(t,e){return t(e)}}),entity_prop:function(e,n){var i;return v(e),null===(i=t.hass.entities[e])||void 0===i?void 0:i[n]},is_entity_prop:function(t,e,n){return this.entity_prop(t,e)===n},devices:new Proxy((function(e){if(void 0===e)return t.hass.devices;if(c(e))throw SyntaxError("".concat(r,": devices method cannot be used with an entity id, you should use a device id instead."));return t.hass.devices[e]}),{get:function(e,n){if(c(n))throw SyntaxError("".concat(r,": devices cannot be accesed using an entity id, you should use a device id instead."));return t.hass.devices[n]}}),device_attr:function(e,n){var i;return null===(i=t.hass.devices[e])||void 0===i?void 0:i[n]},is_device_attr:function(t,e,n){return this.device_attr(t,e)===n},device_id:function(e){var n;return v(e),null===(n=t.hass.entities[e])||void 0===n?void 0:n.device_id},areas:function(){return a().map((function(t){return t[1].area_id}))},area_id:function(e){var i,s;if(e in t.hass.devices)return this.device_attr(e,n.AREA_ID);var r=null===(i=t.hass.entities[e])||void 0===i?void 0:i.device_id;if(r)return this.device_attr(r,n.AREA_ID);var o=a().find((function(t){return t[1].name===e}));return null===(s=null==o?void 0:o[1])||void 0===s?void 0:s.area_id},area_name:function(e){var i,s,r;e in t.hass.devices&&(r=this.device_attr(e,n.AREA_ID));var o=null===(i=t.hass.entities[e])||void 0===i?void 0:i.device_id;o&&(r=this.device_attr(o,n.AREA_ID));var c=a().find((function(t){var n=t[1];return n.area_id===e||n.area_id===r}));return null===(s=null==c?void 0:c[1])||void 0===s?void 0:s.name},area_entities:function(t){var e=a().find((function(e){var n=e[1];return n.area_id===t||n.name===t}));return e?u().filter((function(t){return t[1].area_id===e[1].area_id})).map((function(t){return t[0]})):[]},area_devices:function(e){var n=a().find((function(t){var n=t[1];return n.area_id===e||n.name===e}));return n?Object.entries(t.hass.devices).filter((function(t){return t[1].area_id===n[1].area_id})).map((function(t){return t[1].id})):[]},get user_name(){return t.hass.user.name},get user_is_admin(){return t.hass.user.is_admin},get user_is_owner(){return t.hass.user.is_owner},get user_agent(){return window.navigator.userAgent},get panel_url(){var t;return t=i.PANEL_URL,d.add(t),location.pathname},get tracked(){return d},cleanTracked:function(){d.clear()}}}var d=function(){function e(t,e){var n=e.throwErrors,i=void 0!==n&&n,s=e.throwWarnings,r=void 0===s||s,a=e.variables,o=void 0===a?{}:a;this._throwErrors=i,this._throwWarnings=r,this._variables=o,this._subscriptions=new Map,this._scopped=u(t,r),this._watchForPanelUrlChange(),this._watchForEntitiesChange()}return e.prototype._executeRenderingFunctions=function(t){var e=this;this._subscriptions.get(t).forEach((function(t,n){t.forEach((function(t){e.trackTemplate(n,t)}))}))},e.prototype._watchForPanelUrlChange=function(){var t=this;window.addEventListener(s.LOCATION_CHANGED,(function(e){t._panelUrlWatchCallback()})),window.addEventListener(s.POPSTATE,(function(){t._panelUrlWatchCallback()}))},e.prototype._panelUrlWatchCallback=function(){this._subscriptions.has(i.PANEL_URL)&&this._executeRenderingFunctions(i.PANEL_URL)},e.prototype._watchForEntitiesChange=function(){var t=this;window.hassConnection.then((function(e){e.conn.subscribeMessage((function(e){return t._entityWatchCallback(e)}),{type:s.SUBSCRIBE_EVENTS,event_type:s.STATE_CHANGE_EVENT})}))},e.prototype._entityWatchCallback=function(t){if(this._subscriptions.size){var e=t.data.entity_id;this._subscriptions.has(e)&&this._executeRenderingFunctions(e)}},e.prototype._storeTracked=function(t,e){var n=this;this._scopped.tracked.forEach((function(i){if(n._subscriptions.has(i)){var s=n._subscriptions.get(i);if(s.has(t)){var r=s.get(t);r.has(e)||r.add(e)}else s.set(t,new Set([e]))}else n._subscriptions.set(i,new Map([[t,new Set([e])]]))}))},e.prototype._untrackTemplate=function(t,e){var n=this;this._subscriptions.forEach((function(i,s){if(i.has(t)){var r=i.get(t);r.has(e)&&r.delete(e),0===r.size&&(i.delete(t),0===i.size&&n._subscriptions.delete(s))}}))},e.prototype.renderTemplate=function(e){try{var n=new Map(Object.entries(this._variables)),i=e.trim(),s=i.includes("return")?i:"return ".concat(i);return(new(Function.bind.apply(Function,t(t([void 0,"hass","states","is_state","state_attr","is_state_attr","has_value","entities","entity_prop","is_entity_prop","devices","device_attr","is_device_attr","device_id","areas","area_id","area_name","area_entities","area_devices","user_name","user_is_admin","user_is_owner","panel_url","user_agent"],Array.from(n.keys()),!1),["".concat('"use strict";'," ").concat(s)],!1)))).apply(void 0,t([this._scopped.hass,this._scopped.states,this._scopped.is_state.bind(this._scopped),this._scopped.state_attr.bind(this._scopped),this._scopped.is_state_attr.bind(this._scopped),this._scopped.has_value.bind(this._scopped),this._scopped.entities,this._scopped.entity_prop,this._scopped.is_entity_prop.bind(this._scopped),this._scopped.devices,this._scopped.device_attr.bind(this._scopped),this._scopped.is_device_attr.bind(this._scopped),this._scopped.device_id.bind(this._scopped),this._scopped.areas.bind(this._scopped),this._scopped.area_id.bind(this._scopped),this._scopped.area_name.bind(this._scopped),this._scopped.area_entities.bind(this._scopped),this._scopped.area_devices.bind(this._scopped),this._scopped.user_name,this._scopped.user_is_admin,this._scopped.user_is_owner,this._scopped.panel_url,this._scopped.user_agent],Array.from(n.values()),!1))}catch(t){if(this._throwErrors)throw t;return void(this._throwWarnings&&console.warn(t))}},e.prototype.trackTemplate=function(t,e){var n=this;this._scopped.cleanTracked();var i=this.renderTemplate(t);return this._storeTracked(t,e),e(i),function(){return n._untrackTemplate(t,e)}},e.prototype.cleanTracked=function(t){t?this._subscriptions.has(t)&&this._subscriptions.delete(t):this._subscriptions.clear()},e}(),_=function(){function t(t,e){var n,i;void 0===e&&(e={}),this._renderer=(n=function(){return t.hass},i=function(t){return!!(t&&t.areas&&t.devices&&t.entities&&t.states&&t.user)},new Promise((function(t,e){var s=0,r=function(){var a=n();i(a)?t(a):++s<100?setTimeout(r,50):e()};r()}))).then((function(){return new d(t,e)})).catch((function(){throw new Error("The provided element doesn't contain a proper or initialised hass object")}))}return t.prototype.getRenderer=function(){return this._renderer},t}();export{_ as default};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function t(t,e,n){if(n||2===arguments.length)for(var i,s=0,r=e.length;s<r;s++)!i&&s in e||(i||(i=Array.prototype.slice.call(e,0,s)),i[s]=e[s]);return t.concat(i||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var e,n,i,s,r="[home-assistant-javascript-templates]",a=/^([a-z_]+)\.(\w+)$/;!function(t){t.UNKNOWN="unknown",t.UNAVAILABLE="unavailable"}(e||(e={})),function(t){t.AREA_ID="area_id",t.NAME="name"}(n||(n={})),function(t){t.PANEL_URL="panel_url"}(i||(i={})),function(t){t.LOCATION_CHANGED="location-changed",t.POPSTATE="popstate",t.SUBSCRIBE_EVENTS="subscribe_events",t.STATE_CHANGE_EVENT="state_changed"}(s||(s={}));var o=function(t){return t.reduce((function(t,e){var n=e[0],i=e[1];return t[n.replace(a,"$2")]=i,t}),{})},c=function(t){return t.includes(".")};function u(t,s){var a=function(){return Object.entries(t.hass.areas)},u=function(){return Object.entries(t.hass.entities)},d=new Set,_=function(t,e){s&&console.warn("".concat(t," ").concat(e," used in a JavaScript template doesn't exist"))},p=function(t){return _("Entity",t)},h=function(t){return _("Domain",t)},v=function(e){t.hass.states[e]?d.add(e):p(e)};return{get hass(){return t.hass},states:new Proxy((function(e){var n;if(c(e))return v(e),null===(n=t.hass.states[e])||void 0===n?void 0:n.state;throw SyntaxError("".concat(r,": states method cannot be used with a domain, use it as an object instead."))}),{get:function(e,n){if(c(n))return v(n),t.hass.states[n];var i=Object.entries(t.hass.states).filter((function(t){return t[0].startsWith(n)}));return i.length||h(n),new Proxy(o(i),{get:function(t,e){return v("".concat(n,".").concat(e)),t[e]}})}}),is_state:function(e,n){var i;return v(e),(null===(i=t.hass.states[e])||void 0===i?void 0:i.state)===n},state_attr:function(e,n){var i,s;return v(e),null===(s=null===(i=t.hass.states[e])||void 0===i?void 0:i.attributes)||void 0===s?void 0:s[n]},is_state_attr:function(t,e,n){return this.state_attr(t,e)===n},has_value:function(t){return this.states(t)?!(this.is_state(t,e.UNKNOWN)||this.is_state(t,e.UNAVAILABLE)):(p(t),!1)},entities:new Proxy((function(e){if(void 0===e)return t.hass.entities;if(c(e))return v(e),t.hass.entities[e];var n=u().filter((function(t){return t[0].startsWith(e)}));return n.length||h(e),new Proxy(o(n),{get:function(t,n){return v("".concat(e,".").concat(n)),t[n]}})}),{get:function(t,e){return t(e)}}),entity_prop:function(e,n){var i;return v(e),null===(i=t.hass.entities[e])||void 0===i?void 0:i[n]},is_entity_prop:function(t,e,n){return this.entity_prop(t,e)===n},devices:new Proxy((function(e){if(void 0===e)return t.hass.devices;if(c(e))throw SyntaxError("".concat(r,": devices method cannot be used with an entity id, you should use a device id instead."));return t.hass.devices[e]}),{get:function(e,n){if(c(n))throw SyntaxError("".concat(r,": devices cannot be accesed using an entity id, you should use a device id instead."));return t.hass.devices[n]}}),device_attr:function(e,n){var i;return null===(i=t.hass.devices[e])||void 0===i?void 0:i[n]},is_device_attr:function(t,e,n){return this.device_attr(t,e)===n},device_id:function(e){var n;return v(e),null===(n=t.hass.entities[e])||void 0===n?void 0:n.device_id},areas:function(){return a().map((function(t){return t[1].area_id}))},area_id:function(e){var i,s;if(e in t.hass.devices)return this.device_attr(e,n.AREA_ID);var r=null===(i=t.hass.entities[e])||void 0===i?void 0:i.device_id;if(r)return this.device_attr(r,n.AREA_ID);var o=a().find((function(t){return t[1].name===e}));return null===(s=null==o?void 0:o[1])||void 0===s?void 0:s.area_id},area_name:function(e){var i,s,r;e in t.hass.devices&&(r=this.device_attr(e,n.AREA_ID));var o=null===(i=t.hass.entities[e])||void 0===i?void 0:i.device_id;o&&(r=this.device_attr(o,n.AREA_ID));var c=a().find((function(t){var n=t[1];return n.area_id===e||n.area_id===r}));return null===(s=null==c?void 0:c[1])||void 0===s?void 0:s.name},area_entities:function(t){var e=a().find((function(e){var n=e[1];return n.area_id===t||n.name===t}));return e?u().filter((function(t){return t[1].area_id===e[1].area_id})).map((function(t){return t[0]})):[]},area_devices:function(e){var n=a().find((function(t){var n=t[1];return n.area_id===e||n.name===e}));return n?Object.entries(t.hass.devices).filter((function(t){return t[1].area_id===n[1].area_id})).map((function(t){return t[1].id})):[]},get user_name(){return t.hass.user.name},get user_is_admin(){return t.hass.user.is_admin},get user_is_owner(){return t.hass.user.is_owner},get user_agent(){return window.navigator.userAgent},get panel_url(){var t;return t=i.PANEL_URL,d.add(t),location.pathname},get tracked(){return d},cleanTracked:function(){d.clear()}}}var d=function(){function e(t,e){var n=e.throwErrors,i=void 0!==n&&n,s=e.throwWarnings,r=void 0===s||s,a=e.variables,o=void 0===a?{}:a;this._throwErrors=i,this._throwWarnings=r,this._variables=
|
|
1
|
+
"use strict";function t(t,e,n){if(n||2===arguments.length)for(var i,s=0,r=e.length;s<r;s++)!i&&s in e||(i||(i=Array.prototype.slice.call(e,0,s)),i[s]=e[s]);return t.concat(i||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var e,n,i,s,r="[home-assistant-javascript-templates]",a=/^([a-z_]+)\.(\w+)$/;!function(t){t.UNKNOWN="unknown",t.UNAVAILABLE="unavailable"}(e||(e={})),function(t){t.AREA_ID="area_id",t.NAME="name"}(n||(n={})),function(t){t.PANEL_URL="panel_url"}(i||(i={})),function(t){t.LOCATION_CHANGED="location-changed",t.POPSTATE="popstate",t.SUBSCRIBE_EVENTS="subscribe_events",t.STATE_CHANGE_EVENT="state_changed"}(s||(s={}));var o=function(t){return t.reduce((function(t,e){var n=e[0],i=e[1];return t[n.replace(a,"$2")]=i,t}),{})},c=function(t){return t.includes(".")};function u(t,s){var a=function(){return Object.entries(t.hass.areas)},u=function(){return Object.entries(t.hass.entities)},d=new Set,_=function(t,e){s&&console.warn("".concat(t," ").concat(e," used in a JavaScript template doesn't exist"))},p=function(t){return _("Entity",t)},h=function(t){return _("Domain",t)},v=function(e){t.hass.states[e]?d.add(e):p(e)};return{get hass(){return t.hass},states:new Proxy((function(e){var n;if(c(e))return v(e),null===(n=t.hass.states[e])||void 0===n?void 0:n.state;throw SyntaxError("".concat(r,": states method cannot be used with a domain, use it as an object instead."))}),{get:function(e,n){if(c(n))return v(n),t.hass.states[n];var i=Object.entries(t.hass.states).filter((function(t){return t[0].startsWith(n)}));return i.length||h(n),new Proxy(o(i),{get:function(t,e){return v("".concat(n,".").concat(e)),t[e]}})}}),is_state:function(e,n){var i;return v(e),(null===(i=t.hass.states[e])||void 0===i?void 0:i.state)===n},state_attr:function(e,n){var i,s;return v(e),null===(s=null===(i=t.hass.states[e])||void 0===i?void 0:i.attributes)||void 0===s?void 0:s[n]},is_state_attr:function(t,e,n){return this.state_attr(t,e)===n},has_value:function(t){return this.states(t)?!(this.is_state(t,e.UNKNOWN)||this.is_state(t,e.UNAVAILABLE)):(p(t),!1)},entities:new Proxy((function(e){if(void 0===e)return t.hass.entities;if(c(e))return v(e),t.hass.entities[e];var n=u().filter((function(t){return t[0].startsWith(e)}));return n.length||h(e),new Proxy(o(n),{get:function(t,n){return v("".concat(e,".").concat(n)),t[n]}})}),{get:function(t,e){return t(e)}}),entity_prop:function(e,n){var i;return v(e),null===(i=t.hass.entities[e])||void 0===i?void 0:i[n]},is_entity_prop:function(t,e,n){return this.entity_prop(t,e)===n},devices:new Proxy((function(e){if(void 0===e)return t.hass.devices;if(c(e))throw SyntaxError("".concat(r,": devices method cannot be used with an entity id, you should use a device id instead."));return t.hass.devices[e]}),{get:function(e,n){if(c(n))throw SyntaxError("".concat(r,": devices cannot be accesed using an entity id, you should use a device id instead."));return t.hass.devices[n]}}),device_attr:function(e,n){var i;return null===(i=t.hass.devices[e])||void 0===i?void 0:i[n]},is_device_attr:function(t,e,n){return this.device_attr(t,e)===n},device_id:function(e){var n;return v(e),null===(n=t.hass.entities[e])||void 0===n?void 0:n.device_id},areas:function(){return a().map((function(t){return t[1].area_id}))},area_id:function(e){var i,s;if(e in t.hass.devices)return this.device_attr(e,n.AREA_ID);var r=null===(i=t.hass.entities[e])||void 0===i?void 0:i.device_id;if(r)return this.device_attr(r,n.AREA_ID);var o=a().find((function(t){return t[1].name===e}));return null===(s=null==o?void 0:o[1])||void 0===s?void 0:s.area_id},area_name:function(e){var i,s,r;e in t.hass.devices&&(r=this.device_attr(e,n.AREA_ID));var o=null===(i=t.hass.entities[e])||void 0===i?void 0:i.device_id;o&&(r=this.device_attr(o,n.AREA_ID));var c=a().find((function(t){var n=t[1];return n.area_id===e||n.area_id===r}));return null===(s=null==c?void 0:c[1])||void 0===s?void 0:s.name},area_entities:function(t){var e=a().find((function(e){var n=e[1];return n.area_id===t||n.name===t}));return e?u().filter((function(t){return t[1].area_id===e[1].area_id})).map((function(t){return t[0]})):[]},area_devices:function(e){var n=a().find((function(t){var n=t[1];return n.area_id===e||n.name===e}));return n?Object.entries(t.hass.devices).filter((function(t){return t[1].area_id===n[1].area_id})).map((function(t){return t[1].id})):[]},get user_name(){return t.hass.user.name},get user_is_admin(){return t.hass.user.is_admin},get user_is_owner(){return t.hass.user.is_owner},get user_agent(){return window.navigator.userAgent},get panel_url(){var t;return t=i.PANEL_URL,d.add(t),location.pathname},get tracked(){return d},cleanTracked:function(){d.clear()}}}var d=function(){function e(t,e){var n=e.throwErrors,i=void 0!==n&&n,s=e.throwWarnings,r=void 0===s||s,a=e.variables,o=void 0===a?{}:a;this._throwErrors=i,this._throwWarnings=r,this._variables=o,this._subscriptions=new Map,this._scopped=u(t,r),this._watchForPanelUrlChange(),this._watchForEntitiesChange()}return e.prototype._executeRenderingFunctions=function(t){var e=this;this._subscriptions.get(t).forEach((function(t,n){t.forEach((function(t){e.trackTemplate(n,t)}))}))},e.prototype._watchForPanelUrlChange=function(){var t=this;window.addEventListener(s.LOCATION_CHANGED,(function(e){t._panelUrlWatchCallback()})),window.addEventListener(s.POPSTATE,(function(){t._panelUrlWatchCallback()}))},e.prototype._panelUrlWatchCallback=function(){this._subscriptions.has(i.PANEL_URL)&&this._executeRenderingFunctions(i.PANEL_URL)},e.prototype._watchForEntitiesChange=function(){var t=this;window.hassConnection.then((function(e){e.conn.subscribeMessage((function(e){return t._entityWatchCallback(e)}),{type:s.SUBSCRIBE_EVENTS,event_type:s.STATE_CHANGE_EVENT})}))},e.prototype._entityWatchCallback=function(t){if(this._subscriptions.size){var e=t.data.entity_id;this._subscriptions.has(e)&&this._executeRenderingFunctions(e)}},e.prototype._storeTracked=function(t,e){var n=this;this._scopped.tracked.forEach((function(i){if(n._subscriptions.has(i)){var s=n._subscriptions.get(i);if(s.has(t)){var r=s.get(t);r.has(e)||r.add(e)}else s.set(t,new Set([e]))}else n._subscriptions.set(i,new Map([[t,new Set([e])]]))}))},e.prototype._untrackTemplate=function(t,e){var n=this;this._subscriptions.forEach((function(i,s){if(i.has(t)){var r=i.get(t);r.has(e)&&r.delete(e),0===r.size&&(i.delete(t),0===i.size&&n._subscriptions.delete(s))}}))},e.prototype.renderTemplate=function(e){try{var n=new Map(Object.entries(this._variables)),i=e.trim(),s=i.includes("return")?i:"return ".concat(i);return(new(Function.bind.apply(Function,t(t([void 0,"hass","states","is_state","state_attr","is_state_attr","has_value","entities","entity_prop","is_entity_prop","devices","device_attr","is_device_attr","device_id","areas","area_id","area_name","area_entities","area_devices","user_name","user_is_admin","user_is_owner","panel_url","user_agent"],Array.from(n.keys()),!1),["".concat('"use strict";'," ").concat(s)],!1)))).apply(void 0,t([this._scopped.hass,this._scopped.states,this._scopped.is_state.bind(this._scopped),this._scopped.state_attr.bind(this._scopped),this._scopped.is_state_attr.bind(this._scopped),this._scopped.has_value.bind(this._scopped),this._scopped.entities,this._scopped.entity_prop,this._scopped.is_entity_prop.bind(this._scopped),this._scopped.devices,this._scopped.device_attr.bind(this._scopped),this._scopped.is_device_attr.bind(this._scopped),this._scopped.device_id.bind(this._scopped),this._scopped.areas.bind(this._scopped),this._scopped.area_id.bind(this._scopped),this._scopped.area_name.bind(this._scopped),this._scopped.area_entities.bind(this._scopped),this._scopped.area_devices.bind(this._scopped),this._scopped.user_name,this._scopped.user_is_admin,this._scopped.user_is_owner,this._scopped.panel_url,this._scopped.user_agent],Array.from(n.values()),!1))}catch(t){if(this._throwErrors)throw t;return void(this._throwWarnings&&console.warn(t))}},e.prototype.trackTemplate=function(t,e){var n=this;this._scopped.cleanTracked();var i=this.renderTemplate(t);return this._storeTracked(t,e),e(i),function(){return n._untrackTemplate(t,e)}},e.prototype.cleanTracked=function(t){t?this._subscriptions.has(t)&&this._subscriptions.delete(t):this._subscriptions.clear()},e}(),_=function(){function t(t,e){var n,i;void 0===e&&(e={}),this._renderer=(n=function(){return t.hass},i=function(t){return!!(t&&t.areas&&t.devices&&t.entities&&t.states&&t.user)},new Promise((function(t,e){var s=0,r=function(){var a=n();i(a)?t(a):++s<100?setTimeout(r,50):e()};r()}))).then((function(){return new d(t,e)})).catch((function(){throw new Error("The provided element doesn't contain a proper or initialised hass object")}))}return t.prototype.getRenderer=function(){return this._renderer},t}();module.exports=_;
|