home-assistant-javascript-templates
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -19,2 +19,7 @@ interface Area { | ||
} | ||
interface User { | ||
name: string; | ||
is_admin: boolean; | ||
is_owner: boolean; | ||
} | ||
interface Hass { | ||
@@ -25,2 +30,3 @@ areas: Record<string, Area>; | ||
states: Record<string, State>; | ||
user: User; | ||
} | ||
@@ -27,0 +33,0 @@ declare class HomeAssistantJavaScriptTemplates { |
@@ -1,1 +0,1 @@ | ||
function t(t,e,i){if(i||2===arguments.length)for(var r,n=0,a=e.length;n<a;n++)!r&&n in e||(r||(r=Array.prototype.slice.call(e,0,n)),r[n]=e[n]);return t.concat(r||Array.prototype.slice.call(e))}var e,i;"function"==typeof SuppressedError&&SuppressedError,function(t){t.UNKNOWN="unknown",t.UNAVAILABLE="unavailable"}(e||(e={})),function(t){t.AREA_ID="area_id",t.NAME="name"}(i||(i={}));var r="None";function n(n){var a=Object.entries(n.areas),s=Object.entries(n.states),d=Object.entries(n.devices),c=Object.entries(n.entities);return{hass:n,states:new Proxy((function(t){var e;return null===(e=n.states[t])||void 0===e?void 0:e.state}),{get:function(e,i){return i.includes(".")?n.states[i]:s.filter((function(t){return t[0].startsWith(i)})).reduce((function(e,i){var r=i[1];return t(t([],e,!0),[r],!1)}),[])}}),is_state:function(t,e){var i;return(null===(i=n.states[t])||void 0===i?void 0:i.state)===e},state_attr:function(t,e){var i,a;return(null===(a=null===(i=n.states[t])||void 0===i?void 0:i.attributes)||void 0===a?void 0:a[e])||r},is_state_attr:function(t,e,i){return this.state_attr(t,e)===i},has_value:function(t){return!!this.states(t)&&!(this.is_state(t,e.UNKNOWN)||this.is_state(t,e.UNAVAILABLE))},device_attr:function(t,e){var i;return(null===(i=n.devices[t])||void 0===i?void 0:i[e])||r},is_device_attr:function(t,e,i){return this.device_attr(t,e)===i},device_id:function(t){var e;return(null===(e=n.entities[t])||void 0===e?void 0:e.device_id)||r},areas:function(){return a.map((function(t){return t[1].area_id}))},area_id:function(t){var e;if(t in n.devices)return this.device_attr(t,i.AREA_ID);var s=this.device_id(t);if(s&&s!==r)return this.device_attr(s,i.AREA_ID);var d=a.find((function(e){return e[1].name===t}));return(null===(e=null==d?void 0:d[1])||void 0===e?void 0:e.area_id)||r},area_name:function(t){var e,s;t in n.devices&&(s=this.device_attr(t,i.AREA_ID));var d=this.device_id(t);d&&d!==r&&(s=this.device_attr(d,i.AREA_ID));var c=a.find((function(e){var i=e[1];return i.area_id===t||i.area_id===s}));return(null===(e=null==c?void 0:c[1])||void 0===e?void 0:e.name)||r},area_entities:function(t){var e=a.find((function(e){var i=e[1];return i.area_id===t||i.name===t}));return e?c.filter((function(t){return t[1].area_id===e[1].area_id})).map((function(t){return t[0]})):[]},area_devices:function(t){var e=a.find((function(e){var i=e[1];return i.area_id===t||i.name===t}));return e?d.filter((function(t){return t[1].area_id===e[1].area_id})).map((function(t){return t[1].id})):[]}}}var a=function(){function t(t,e){void 0===e&&(e=!1),this._scopped=n(t),this._errors=e}return t.prototype.renderTemplate=function(t){var e=t.includes("return")?t:"return ".concat(t),i=new Function("hass","states","is_state","state_attr","is_state_attr","has_value","device_attr","is_device_attr","device_id","areas","area_id","area_name","area_entities","area_devices",e);try{return i(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.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))}catch(t){if(this._errors)throw t;return void console.warn(t)}},t}();export{a as default}; | ||
var e,t;!function(e){e.UNKNOWN="unknown",e.UNAVAILABLE="unavailable"}(e||(e={})),function(e){e.AREA_ID="area_id",e.NAME="name"}(t||(t={}));var i="None";function r(e,t,i){if(i||2===arguments.length)for(var r,s=0,n=t.length;s<n;s++)!r&&s in t||(r||(r=Array.prototype.slice.call(t,0,s)),r[s]=t[s]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;function s(s){var n=Object.entries(s.areas),a=Object.entries(s.states),d=Object.entries(s.devices),_=Object.entries(s.entities);return{hass:s,states:new Proxy((function(e){var t;return null===(t=s.states[e])||void 0===t?void 0:t.state}),{get:function(e,t){return t.includes(".")?s.states[t]:a.filter((function(e){return e[0].startsWith(t)})).reduce((function(e,t){var i=t[1];return r(r([],e,!0),[i],!1)}),[])}}),is_state:function(e,t){var i;return(null===(i=s.states[e])||void 0===i?void 0:i.state)===t},state_attr:function(e,t){var r,n;return(null===(n=null===(r=s.states[e])||void 0===r?void 0:r.attributes)||void 0===n?void 0:n[t])||i},is_state_attr:function(e,t,i){return this.state_attr(e,t)===i},has_value:function(t){return!!this.states(t)&&!(this.is_state(t,e.UNKNOWN)||this.is_state(t,e.UNAVAILABLE))},device_attr:function(e,t){var r;return(null===(r=s.devices[e])||void 0===r?void 0:r[t])||i},is_device_attr:function(e,t,i){return this.device_attr(e,t)===i},device_id:function(e){var t;return(null===(t=s.entities[e])||void 0===t?void 0:t.device_id)||i},areas:function(){return n.map((function(e){return e[1].area_id}))},area_id:function(e){var r;if(e in s.devices)return this.device_attr(e,t.AREA_ID);var a=this.device_id(e);if(a&&a!==i)return this.device_attr(a,t.AREA_ID);var d=n.find((function(t){return t[1].name===e}));return(null===(r=null==d?void 0:d[1])||void 0===r?void 0:r.area_id)||i},area_name:function(e){var r,a;e in s.devices&&(a=this.device_attr(e,t.AREA_ID));var d=this.device_id(e);d&&d!==i&&(a=this.device_attr(d,t.AREA_ID));var _=n.find((function(t){var i=t[1];return i.area_id===e||i.area_id===a}));return(null===(r=null==_?void 0:_[1])||void 0===r?void 0:r.name)||i},area_entities:function(e){var t=n.find((function(t){var i=t[1];return i.area_id===e||i.name===e}));return t?_.filter((function(e){return e[1].area_id===t[1].area_id})).map((function(e){return e[0]})):[]},area_devices:function(e){var t=n.find((function(t){var i=t[1];return i.area_id===e||i.name===e}));return t?d.filter((function(e){return e[1].area_id===t[1].area_id})).map((function(e){return e[1].id})):[]},user_name:s.user.name,user_is_admin:s.user.is_admin,user_is_owner:s.user.is_owner}}var n=function(){function e(e,t){void 0===t&&(t=!1),this._scopped=s(e),this._errors=t}return e.prototype.renderTemplate=function(e){var t=e.includes("return")?e:"return ".concat(e),i=new Function("hass","states","is_state","state_attr","is_state_attr","has_value","device_attr","is_device_attr","device_id","areas","area_id","area_name","area_entities","area_devices","user_name","user_is_admin","user_is_owner","".concat('"use strict";'," ").concat(t));try{return i(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.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)}catch(e){if(this._errors)throw e;return void console.warn(e)}},e}();export{n as default}; |
@@ -19,2 +19,7 @@ interface Area { | ||
} | ||
interface User { | ||
name: string; | ||
is_admin: boolean; | ||
is_owner: boolean; | ||
} | ||
interface Hass { | ||
@@ -25,2 +30,3 @@ areas: Record<string, Area>; | ||
states: Record<string, State>; | ||
user: User; | ||
} | ||
@@ -27,0 +33,0 @@ declare class HomeAssistantJavaScriptTemplates { |
@@ -1,1 +0,1 @@ | ||
"use strict";function t(t,e,i){if(i||2===arguments.length)for(var r,n=0,s=e.length;n<s;n++)!r&&n in e||(r||(r=Array.prototype.slice.call(e,0,n)),r[n]=e[n]);return t.concat(r||Array.prototype.slice.call(e))}var e,i;"function"==typeof SuppressedError&&SuppressedError,function(t){t.UNKNOWN="unknown",t.UNAVAILABLE="unavailable"}(e||(e={})),function(t){t.AREA_ID="area_id",t.NAME="name"}(i||(i={}));var r="None";function n(n){var s=Object.entries(n.areas),a=Object.entries(n.states),d=Object.entries(n.devices),c=Object.entries(n.entities);return{hass:n,states:new Proxy((function(t){var e;return null===(e=n.states[t])||void 0===e?void 0:e.state}),{get:function(e,i){return i.includes(".")?n.states[i]:a.filter((function(t){return t[0].startsWith(i)})).reduce((function(e,i){var r=i[1];return t(t([],e,!0),[r],!1)}),[])}}),is_state:function(t,e){var i;return(null===(i=n.states[t])||void 0===i?void 0:i.state)===e},state_attr:function(t,e){var i,s;return(null===(s=null===(i=n.states[t])||void 0===i?void 0:i.attributes)||void 0===s?void 0:s[e])||r},is_state_attr:function(t,e,i){return this.state_attr(t,e)===i},has_value:function(t){return!!this.states(t)&&!(this.is_state(t,e.UNKNOWN)||this.is_state(t,e.UNAVAILABLE))},device_attr:function(t,e){var i;return(null===(i=n.devices[t])||void 0===i?void 0:i[e])||r},is_device_attr:function(t,e,i){return this.device_attr(t,e)===i},device_id:function(t){var e;return(null===(e=n.entities[t])||void 0===e?void 0:e.device_id)||r},areas:function(){return s.map((function(t){return t[1].area_id}))},area_id:function(t){var e;if(t in n.devices)return this.device_attr(t,i.AREA_ID);var a=this.device_id(t);if(a&&a!==r)return this.device_attr(a,i.AREA_ID);var d=s.find((function(e){return e[1].name===t}));return(null===(e=null==d?void 0:d[1])||void 0===e?void 0:e.area_id)||r},area_name:function(t){var e,a;t in n.devices&&(a=this.device_attr(t,i.AREA_ID));var d=this.device_id(t);d&&d!==r&&(a=this.device_attr(d,i.AREA_ID));var c=s.find((function(e){var i=e[1];return i.area_id===t||i.area_id===a}));return(null===(e=null==c?void 0:c[1])||void 0===e?void 0:e.name)||r},area_entities:function(t){var e=s.find((function(e){var i=e[1];return i.area_id===t||i.name===t}));return e?c.filter((function(t){return t[1].area_id===e[1].area_id})).map((function(t){return t[0]})):[]},area_devices:function(t){var e=s.find((function(e){var i=e[1];return i.area_id===t||i.name===t}));return e?d.filter((function(t){return t[1].area_id===e[1].area_id})).map((function(t){return t[1].id})):[]}}}var s=function(){function t(t,e){void 0===e&&(e=!1),this._scopped=n(t),this._errors=e}return t.prototype.renderTemplate=function(t){var e=t.includes("return")?t:"return ".concat(t),i=new Function("hass","states","is_state","state_attr","is_state_attr","has_value","device_attr","is_device_attr","device_id","areas","area_id","area_name","area_entities","area_devices",e);try{return i(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.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))}catch(t){if(this._errors)throw t;return void console.warn(t)}},t}();module.exports=s; | ||
"use strict";var e,t;!function(e){e.UNKNOWN="unknown",e.UNAVAILABLE="unavailable"}(e||(e={})),function(e){e.AREA_ID="area_id",e.NAME="name"}(t||(t={}));var i="None";function r(e,t,i){if(i||2===arguments.length)for(var r,s=0,n=t.length;s<n;s++)!r&&s in t||(r||(r=Array.prototype.slice.call(t,0,s)),r[s]=t[s]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;function s(s){var n=Object.entries(s.areas),a=Object.entries(s.states),d=Object.entries(s.devices),_=Object.entries(s.entities);return{hass:s,states:new Proxy((function(e){var t;return null===(t=s.states[e])||void 0===t?void 0:t.state}),{get:function(e,t){return t.includes(".")?s.states[t]:a.filter((function(e){return e[0].startsWith(t)})).reduce((function(e,t){var i=t[1];return r(r([],e,!0),[i],!1)}),[])}}),is_state:function(e,t){var i;return(null===(i=s.states[e])||void 0===i?void 0:i.state)===t},state_attr:function(e,t){var r,n;return(null===(n=null===(r=s.states[e])||void 0===r?void 0:r.attributes)||void 0===n?void 0:n[t])||i},is_state_attr:function(e,t,i){return this.state_attr(e,t)===i},has_value:function(t){return!!this.states(t)&&!(this.is_state(t,e.UNKNOWN)||this.is_state(t,e.UNAVAILABLE))},device_attr:function(e,t){var r;return(null===(r=s.devices[e])||void 0===r?void 0:r[t])||i},is_device_attr:function(e,t,i){return this.device_attr(e,t)===i},device_id:function(e){var t;return(null===(t=s.entities[e])||void 0===t?void 0:t.device_id)||i},areas:function(){return n.map((function(e){return e[1].area_id}))},area_id:function(e){var r;if(e in s.devices)return this.device_attr(e,t.AREA_ID);var a=this.device_id(e);if(a&&a!==i)return this.device_attr(a,t.AREA_ID);var d=n.find((function(t){return t[1].name===e}));return(null===(r=null==d?void 0:d[1])||void 0===r?void 0:r.area_id)||i},area_name:function(e){var r,a;e in s.devices&&(a=this.device_attr(e,t.AREA_ID));var d=this.device_id(e);d&&d!==i&&(a=this.device_attr(d,t.AREA_ID));var _=n.find((function(t){var i=t[1];return i.area_id===e||i.area_id===a}));return(null===(r=null==_?void 0:_[1])||void 0===r?void 0:r.name)||i},area_entities:function(e){var t=n.find((function(t){var i=t[1];return i.area_id===e||i.name===e}));return t?_.filter((function(e){return e[1].area_id===t[1].area_id})).map((function(e){return e[0]})):[]},area_devices:function(e){var t=n.find((function(t){var i=t[1];return i.area_id===e||i.name===e}));return t?d.filter((function(e){return e[1].area_id===t[1].area_id})).map((function(e){return e[1].id})):[]},user_name:s.user.name,user_is_admin:s.user.is_admin,user_is_owner:s.user.is_owner}}var n=function(){function e(e,t){void 0===t&&(t=!1),this._scopped=s(e),this._errors=t}return e.prototype.renderTemplate=function(e){var t=e.includes("return")?e:"return ".concat(e),i=new Function("hass","states","is_state","state_attr","is_state_attr","has_value","device_attr","is_device_attr","device_id","areas","area_id","area_name","area_entities","area_devices","user_name","user_is_admin","user_is_owner","".concat('"use strict";'," ").concat(t));try{return i(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.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)}catch(e){if(this._errors)throw e;return void console.warn(e)}},e}();module.exports=n; |
{ | ||
"name": "home-assistant-javascript-templates", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "A JavaScript utility to render Home Assistant JavaScript templates", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -5,3 +5,5 @@ # home-assistant-javascript-templates | ||
[![Deployment Status](https://github.com/elchininet/home-assistant-javascript-templates/actions/workflows/deploy.yaml/badge.svg)](https://github.com/elchininet/home-assistant-javascript-templates/actions/workflows/deploy.yaml) [![Coverage Status](https://coveralls.io/repos/github/elchininet/home-assistant-javascript-templates/badge.svg?branch=master)](https://coveralls.io/github/elchininet/home-assistant-javascript-templates?branch=master) [![npm version](https://badge.fury.io/js/home-assistant-javascript-templates.svg)](https://badge.fury.io/js/home-assistant-javascript-templates) | ||
[![Deployment Status](https://github.com/elchininet/home-assistant-javascript-templates/actions/workflows/deploy.yaml/badge.svg)](https://github.com/elchininet/home-assistant-javascript-templates/actions/workflows/deploy.yaml) | ||
[![Coverage Status](https://coveralls.io/repos/github/elchininet/home-assistant-javascript-templates/badge.svg?branch=master)](https://coveralls.io/github/elchininet/home-assistant-javascript-templates?branch=master) | ||
[![npm version](https://badge.fury.io/js/home-assistant-javascript-templates.svg)](https://badge.fury.io/js/home-assistant-javascript-templates) | ||
@@ -195,5 +197,31 @@ ## Install | ||
## Example | ||
#### user_name | ||
Property to return the name of the user logged in in Home Assistant. It returns a `string`. | ||
```javascript | ||
user_name | ||
``` | ||
#### user_is_admin | ||
Property to return if the user logged in in Home Assistant is admin or not. It returns a `boolean`. | ||
```javascript | ||
user_is_admin | ||
``` | ||
#### user_is_owner | ||
Property to return if the user logged in in Home Assistant is the owner. It returns a `boolean`. | ||
```javascript | ||
user_is_owner | ||
``` | ||
## Examples | ||
#### Get a device attribute and return a formatted text with it | ||
```javascript | ||
import HomeAssistantJavaScriptTemplates from 'home-assistant-javascript-templates'; | ||
@@ -216,2 +244,18 @@ | ||
`); | ||
``` | ||
#### Get all the available updates | ||
```javascript | ||
import HomeAssistantJavaScriptTemplates from 'home-assistant-javascript-templates'; | ||
const renderer = new HomeAssistantJavaScriptTemplates( | ||
document.querySelector('home-assistant').hass | ||
); | ||
renderer.renderTemplate(` | ||
const udatesEntities = states['update']; | ||
const updatesEntitiesOn = udatesEntities?.filter((entity) => entity.state === 'on'); | ||
return updatesEntitiesOn?.length || 0; | ||
`); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29031
104
258