diff --git a/configuration.yaml b/configuration.yaml index f73524e..9d7c6c5 100644 --- a/configuration.yaml +++ b/configuration.yaml @@ -18,6 +18,9 @@ group: !include groups.yaml automation: !include_dir_merge_list automation script: !include scripts.yaml +hacs: + token: 5bb7e3904cd0c2928a78ac11c92ff6ac00c5d107 + plant: salon: sensors: diff --git a/www/community/lovelace-fold-entity-row/fold-entity-row.js b/www/community/lovelace-fold-entity-row/fold-entity-row.js new file mode 100644 index 0000000..447a16a --- /dev/null +++ b/www/community/lovelace-fold-entity-row/fold-entity-row.js @@ -0,0 +1,56 @@ +!function(e){var t={};function n(i){if(t[i])return t[i].exports;var o=t[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(i,o,function(t){return e[t]}.bind(null,o));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);const i=Object.getPrototypeOf(customElements.get("home-assistant-main")),o=i.prototype.html,s=i.prototype.css;function r(e,t,n=null){if((e=new Event(e,{bubbles:!0,cancelable:!1,composed:!0})).detail=t||{},n)n.dispatchEvent(e);else{var i=document.querySelector("home-assistant");(i=(i=(i=(i=(i=(i=(i=(i=(i=(i=(i=i&&i.shadowRoot)&&i.querySelector("home-assistant-main"))&&i.shadowRoot)&&i.querySelector("app-drawer-layout partial-panel-resolver"))&&i.shadowRoot||i)&&i.querySelector("ha-panel-lovelace"))&&i.shadowRoot)&&i.querySelector("hui-root"))&&i.shadowRoot)&&i.querySelector("ha-app-layout #view"))&&i.firstElementChild)&&i.dispatchEvent(e)}}const a="custom:",c=["input_number","input_select","input_text","input_datetime","scene","weblink"];function l(e,t){const n=document.createElement("hui-error-card");return n.setConfig({type:"error",error:e,config:t}),n}function u(e,t){if(!t||"object"!=typeof t||!t.type)return l(`No ${e} type configured`,t);let n=t.type;if(n=n.startsWith(a)?n.substr(a.length):`hui-${n}-${e}`,customElements.get(n))return function(e,t){const n=document.createElement(e);try{n.setConfig(t)}catch(e){return l(e,t)}return n}(n,t);const i=l(`Custom element doesn't exist: ${n}.`,t);i.style.display="None";const o=setTimeout(()=>{i.style.display=""},2e3);return customElements.whenDefined(n).then(()=>{clearTimeout(o),r("ll-rebuild",{},i)}),i}class h extends i{static get properties(){return{hass:{},config:{}}}setConfig(e){var t;this._config=e,this.el?this.el.setConfig(e):this.el=this.create(e),this._hass&&(this.el.hass=this._hass),this.noHass&&(t=this,document.querySelector("home-assistant").provideHass(t))}set config(e){this.setConfig(e)}set hass(e){this._hass=e,this.el&&(this.el.hass=e)}createRenderRoot(){return this}render(){return o`${this.el}`}}if(!customElements.get("card-maker")){class e extends h{create(e){return function(e){return u("card",e)}(e)}}customElements.define("card-maker",e)}if(!customElements.get("element-maker")){class e extends h{create(e){return function(e){return u("element",e)}(e)}}customElements.define("element-maker",e)}if(!customElements.get("entity-row-maker")){class e extends h{create(e){return function(e){const t=new Set(["call-service","divider","section","weblink"]);if(!e)return l("Invalid configuration given.",e);if("string"==typeof e&&(e={entity:e}),"object"!=typeof e||!e.entity&&!e.type)return l("Invalid configuration given.",e);const n=e.type||"default";if(t.has(n)||n.startsWith(a))return u("row",e);const i=e.entity.split(".",1)[0];return Object.assign(e,{type:{alert:"toggle",automation:"toggle",climate:"climate",cover:"cover",fan:"toggle",group:"group",input_boolean:"toggle",input_number:"input-number",input_select:"input-select",input_text:"input-text",light:"toggle",lock:"lock",media_player:"media-player",remote:"toggle",scene:"scene",script:"script",sensor:"sensor",timer:"timer",switch:"toggle",vacuum:"toggle",water_heater:"climate",input_datetime:"input-datetime"}[i]||"text"}),u("entity-row",e)}(e)}}customElements.define("entity-row-maker",e)}customElements.define("fold-entity-row",class extends i{static get properties(){return{hass:{},open:Boolean,items:{}}}setConfig(e){this._config=Object.assign({},{open:!1,padding:20,group_config:{}},e),this.open=this.open||this._config.open,this.items=this._config.items,this._config.entities&&(this.items=this._config.entities),"string"==typeof this._config.head&&this._config.head.startsWith("group.")&&(this.items=document.querySelector("home-assistant").hass.states[this._config.head].attributes.entity_id)}clickRow(e){const t=e.target.parentElement._config,n=t.entity||("string"==typeof t?t:null);e.stopPropagation(),this.hasMoreInfo(t)?function(e,t=!1){r("hass-more-info",{entityId:e},document.querySelector("home-assistant"));const n=document.querySelector("home-assistant")._moreInfoEl;n.large=t}(n):e.target.parentElement.hasAttribute("head")&&this.toggle(e)}toggle(e){e&&e.stopPropagation(),this.open=!this.open}hasMoreInfo(e){const t=e.entity||("string"==typeof e?e:null);return!(!t||c.includes(t.split(".",1)[0]))}firstUpdated(){const e=this.shadowRoot.querySelector("#head > entity-row-maker");e.updateComplete.then(()=>{const t=e.querySelector("hui-section-row");t&&t.updateComplete.then(()=>{t.shadowRoot.querySelector(".divider").style.marginRight="-56px"})})}render(){this._entities&&this._entities.forEach(e=>e.hass=this.hass);const e=e=>("string"==typeof e&&(e={entity:e}),Object.assign({},this._config.group_config,e));return o` + + +
+ ${this.items.map(t=>o` + + `)} +
+ `}static get styles(){return s` + #head { + display: flex; + cursor: pointer; + align-items: center; + } + #head entity-row-maker { + flex-grow: 1; + } + #head ha-icon { + width: 40px; + cursor: pointer + } + + #items { + padding: 0; + margin: 0; + overflow: hidden; + max-height: 0; + } + #items[open] { + overflow: visible; + max-height: none; + } + .state-card-dialog { + cursor: pointer; + } + `}})}]); \ No newline at end of file diff --git a/www/community/lovelace-fold-entity-row/fold-entity-row.js.gz b/www/community/lovelace-fold-entity-row/fold-entity-row.js.gz new file mode 100644 index 0000000..ff0b80c Binary files /dev/null and b/www/community/lovelace-fold-entity-row/fold-entity-row.js.gz differ diff --git a/www/community/monster-card/monster-card.js b/www/community/monster-card/monster-card.js new file mode 100644 index 0000000..3964b09 --- /dev/null +++ b/www/community/monster-card/monster-card.js @@ -0,0 +1,122 @@ +class MonsterCard extends HTMLElement { + + _getEntities(hass, filters) { + function _filterEntityId(stateObj, pattern) { + if (pattern.indexOf('*') === -1) { + return stateObj.entity_id === pattern; + } + const regEx = new RegExp(`^${pattern.replace(/\*/g, '.*')}$`, 'i'); + return stateObj.entity_id.search(regEx) === 0; + } + function _filterName(stateObj, pattern) { + let compareEntity = stateObj.attributes.title ? stateObj.attributes.title : stateObj.attributes.friendly_name; + if (!compareEntity) compareEntity = stateObj.entity_id; + if (pattern.indexOf('*') === -1) { + return compareEntity === pattern; + } + const regEx = new RegExp(`^${pattern.replace(/\*/g, '.*')}$`, 'i'); + return compareEntity.search(regEx) === 0; + } + // Allows '< 300' in b + function _complexCompare(a, b) { + const _compare = { + '>': (x, y) => x > y, + '<': (x, y) => x < y, + '<=': (x, y) => x <= y, + '>=': (x, y) => x >= y, + '=': (x, y) => x === y, + }; + let operator = '='; + let y = b; + let x = a; + if (!isNaN(a) && typeof (b) == 'string' + && b.split(" ").length > 1) { + [operator, y] = b.split(' ', 2); + x = parseFloat(a); + } + return _compare[operator](x, y); + } + const entities = new Map(); + filters.forEach((filter) => { + const filters = []; + if (filter.domain) { + filters.push(stateObj => stateObj.entity_id.split('.', 1)[0] === filter.domain); + } + if (filter.attributes) { + Object.keys(filter.attributes).forEach(key => { + filters.push(stateObj => _complexCompare(stateObj.attributes[key], filter.attributes[key])); + }); + } + if (filter.entity_id) { + filters.push(stateObj => _filterEntityId(stateObj, filter.entity_id)); + } + if (filter.name) { + filters.push(stateObj => _filterName(stateObj, filter.name)); + } + if (filter.state) { + filters.push(stateObj => _complexCompare(stateObj.state, filter.state)); + } + + const options = filter.options ? filter.options : {} + + Object.keys(hass.states).sort().forEach(key => { + if (filters.every(filterFunc => filterFunc(hass.states[key]))) { + entities.set(hass.states[key].entity_id, Object.assign({ "entity": hass.states[key].entity_id }, options)); + } + }); + }); + return Array.from(entities.values()); + } + + setConfig(config) { + if (!config.filter.include || !Array.isArray(config.filter.include)) { + throw new Error('Please define filters'); + } + + if (this.lastChild) this.removeChild(this.lastChild); + + const cardConfig = Object.assign({}, config); + if (!cardConfig.card) cardConfig.card = {}; + if (config.card.entities) delete config.card.entities; + if (!cardConfig.card.type) cardConfig.card.type = 'entities'; + + const element = document.createElement(`hui-${cardConfig.card.type}-card`); + this.appendChild(element); + + this._config = cardConfig; + } + + set hass(hass) { + const config = this._config; + let entities = this._getEntities(hass, config.filter.include); + if (config.filter.exclude) { + const excludeEntities = this._getEntities(hass, config.filter.exclude).map(entity => entity.entity); + entities = entities.filter(entity => !excludeEntities.includes(entity.entity)); + } + + + + if (entities.length === 0 && config.show_empty === false) { + this.style.display = 'none'; + } else { + if (config.when && (hass.states[config.when.entity].state == config.when.state) || !config.when) { + this.style.display = 'block'; + } else { + this.style.display = 'none'; + } + } + + if (!config.card.entities || config.card.entities.length !== entities.length || + !config.card.entities.every((value, index) => value.entity === entities[index].entity)) { + config.card.entities = entities; + this.lastChild.setConfig(config.card); + } + this.lastChild.hass = hass; + } + + getCardSize() { + return 'getCardSize' in this.lastChild ? this.lastChild.getCardSize() : 1; + } +} + +customElements.define('monster-card', MonsterCard); diff --git a/www/community/monster-card/monster-card.js.gz b/www/community/monster-card/monster-card.js.gz new file mode 100644 index 0000000..7e3d017 Binary files /dev/null and b/www/community/monster-card/monster-card.js.gz differ