diff --git a/README.md b/README.md
index 74f0c017..abc41b2d 100644
--- a/README.md
+++ b/README.md
@@ -26,17 +26,24 @@ Call any service via a tile button. This custom tile feature will let you do wha
### Button Config
-| Name | Type | Description |
-| -------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
-| service | string | The service call to make, e.g. `light.toggle` or `lock.unlock`. |
-| data.entity_id | string | The entity ID of the device to call the service on. If left blank will use the entity ID assigned to the tile card. |
-| data | object | Additional data to pass to the service call. See the Home Assistant documentation or go to `Developer Tools > Services` to see available options for each service. |
-| color | string | Custom color for the button. Should either be a color name like `red` or an rgb function like `rgb(255 0 0)`. |
-| opacity | float | Opacity of the button background. Should be a number between 0 and 1. Defaults to 0.2. |
-| icon | string | Material design icon to use. |
-| icon_color | string | Custom color for the icon. Should either be a color name like `red` or an rgb function like `rgb(255 0 0)`. |
-| label | string | String label to place underneath the icon, or by itself. |
-| label_color | string | Custom color for the string label. Should either be a color name like `red` or an rgb function like `rgb(255 0 0)`. |
+### Service Call Options
+
+| Name | Type | Description |
+| ------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
+| service | string | The service call to make, e.g. `light.toggle` or `lock.unlock`. |
+| target | object | The entity IDs, device IDs, or area IDs to call the service on. If left blank will use the entity ID assigned to the tile card. |
+| data | object | Additional data to pass to the service call. See the Home Assistant documentation or go to `Developer Tools > Services` to see available options for each service. |
+
+#### Style Options
+
+| Name | Type | Description |
+| ----------- | ------ | ------------------------------------------------------------------------------------------------------------------- |
+| color | string | Custom color for the button. Should either be a color name like `red` or an rgb function like `rgb(255 0 0)`. |
+| opacity | float | Opacity of the button background. Should be a number between 0 and 1. Defaults to 0.2. |
+| icon | string | Material design icon to use. |
+| icon_color | string | Custom color for the icon. Should either be a color name like `red` or an rgb function like `rgb(255 0 0)`. |
+| label | string | String label to place underneath the icon, or by itself. |
+| label_color | string | Custom color for the string label. Should either be a color name like `red` or an rgb function like `rgb(255 0 0)`. |
## Examples
@@ -78,58 +85,54 @@ features:
icon: mdi:lightbulb
icon_color: orange
label: Bulb 1
- data:
+ target:
entity_id: light.chandelier_bulb_1
- service: light.toggle
icon: mdi:lightbulb
icon_color: yellow
label: Bulb 2
- data:
+ target:
entity_id: light.chandelier_bulb_2
- service: light.toggle
icon: mdi:lightbulb
icon_color: green
label: Bulb 3
- data:
+ target:
entity_id: light.chandelier_bulb_3
- service: light.toggle
icon: mdi:lightbulb
icon_color: blue
label: Bulb 4
- data:
+ target:
entity_id: light.chandelier_bulb_4
- service: light.toggle
icon: mdi:lightbulb
icon_color: purple
label: Bulb 5
- data:
+ target:
entity_id: light.chandelier_bulb_5
- type: custom:service-call
buttons:
- service: light.turn_on
color: red
- xicon_color: rgb(255 0 0)
label: Red
label_color: red
data:
color_name: red
- service: light.turn_on
color: green
- icon_color: rgb(0 255 0)
label: Green
label_color: green
data:
color_name: green
- service: light.turn_on
color: blue
- icon_color: rgb(0 0 255)
label: Blue
label_color: blue
data:
color_name: blue
- service: light.turn_on
color: white
- icon_color: rgb(255 255 255)
label: White
label_color: white
data:
diff --git a/dist/service-call-tile-feature.js b/dist/service-call-tile-feature.js
index b6b62700..e52ee2ac 100644
--- a/dist/service-call-tile-feature.js
+++ b/dist/service-call-tile-feature.js
@@ -1,20 +1,18 @@
/*! For license information please see service-call-tile-feature.js.LICENSE.txt */
-(()=>{"use strict";var t={114:function(t,e,i){var s=this&&this.__decorate||function(t,e,i,s){var n,o=arguments.length,r=o<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var l=t.length-1;l>=0;l--)(n=t[l])&&(r=(o<3?n(r):o>3?n(e,i,r):n(e,i))||r);return o>3&&r&&Object.defineProperty(e,i,r),r};Object.defineProperty(e,"__esModule",{value:!0});const n=i(62),o=i(595);class r extends n.LitElement{constructor(){super()}static get properties(){return{hass:{},config:{},stateObj:{}}}static getStubConfig(){return{type:"custom:service-call",buttons:[{service:"",data:{}}]}}setConfig(t){if(!t)throw new Error("Invalid configuration");this.config=t}_press(t){t.stopImmediatePropagation();const e=parseInt(t.currentTarget.getAttribute("itemid")||"-1"),i=this.config.buttons[e],s=JSON.parse(JSON.stringify(i.data||{}));"entity_id"in s&&""!=s.entity_id||(s.entity_id=this.stateObj.entity_id);const[n,o]=i.service.split(".");this.hass.callService(n,o,s)}render(){if(!this.config||!this.hass||!this.stateObj)return null;const t=[];for(const[e,i]of this.config.buttons.entries()){const s=[];let o="",r="";"color"in i&&(o=`background-color: ${i.color};`),"opacity"in i&&(r=`opacity: ${i.opacity};`);const l=`${o}${r}`;if(s.push(n.html` `),"icon"in i){let t="";"icon_color"in i&&(t=`color: ${i.icon_color};`),s.push(n.html` `)}if("label"in i){let t="";"label_color"in i&&(t=`color: ${i.label_color};`),s.push(n.html`
${i.label}
`)}t.push(n.html`${s}
`)}return n.html`${t}
`}static get styles(){return n.css`
+(()=>{"use strict";var t={114:function(t,e,i){var s=this&&this.__decorate||function(t,e,i,s){var n,r=arguments.length,o=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,s);else for(var l=t.length-1;l>=0;l--)(n=t[l])&&(o=(r<3?n(o):r>3?n(e,i,o):n(e,i))||o);return r>3&&o&&Object.defineProperty(e,i,o),o};Object.defineProperty(e,"__esModule",{value:!0});const n=i(147),r=i(62),o=i(595);console.info(`%c SERVICE-CALL-TILE-FEATURE v${n.version}`,"color: white; font-weight: bold; background: cornflowerblue");class l extends r.LitElement{constructor(){super()}static get properties(){return{hass:{},config:{},stateObj:{}}}static getStubConfig(){return{type:"custom:service-call",buttons:[{service:""}]}}setConfig(t){if(!t)throw new Error("Invalid configuration");t=JSON.parse(JSON.stringify(t));for(const e of t.buttons)e.data=Object.assign(Object.assign({},e.data||{}),e.target||{});this.config=t}_press(t){t.stopImmediatePropagation();const e=parseInt(t.currentTarget.getAttribute("itemid")||"-1"),i=this.config.buttons[e],[s,n]=i.service.split("."),r=i.data||{};"entity_id"in r||"device_id"in r||"area_id"in r||(r.entity_id=this.stateObj.entity_id),this.hass.callService(s,n,r)}renderBackground(t,e,i){let s="",n="";e&&(s=`background-color: ${e};`),i&&(n=`opacity: ${i};`);const o=`${s}${n}`;return r.html` `}renderIcon(t,e){let i="";return e&&(i=`color: ${e};`),r.html` `}renderLabel(t,e){let i="";return e&&(i=`color: ${e};`),r.html`${t}
`}render(){if(!this.config||!this.hass||!this.stateObj)return null;const t=[];for(const[e,i]of this.config.buttons.entries()){const s=[];s.push(this.renderBackground(e,i.color,i.opacity)),"icon"in i&&s.push(this.renderIcon(i.icon,i.icon_color)),"label"in i&&s.push(this.renderLabel(i.label,i.label_color)),t.push(r.html`${s}
`)}return r.html`${t}
`}static get styles(){return r.css`
.row {
display: flex;
flex-direction: row;
flex-flow: row;
justify-content: center;
align-items: center;
- padding: 0 12px 12px 12px;
+ padding: 0 12px 12px;
+ gap: 12px;
width: auto;
}
.container {
@@ -27,7 +25,6 @@
width: 100%;
border-radius: 10px;
border: none;
- margin: 0 6px;
padding: 0px;
box-sizing: border-box;
line-height: 0;
@@ -74,6 +71,5 @@
width: inherit;
font-family: inherit;
font-size: 12px;
- bottom: 2px;
}
- `}}s([(0,o.property)({attribute:!1})],r.prototype,"hass",void 0),s([(0,o.property)({attribute:!1})],r.prototype,"config",void 0),s([(0,o.property)({attribute:!1})],r.prototype,"stateObj",void 0),customElements.define("service-call",r),window.customTileFeatures=window.customTileFeatures||[],window.customTileFeatures.push({type:"service-call",name:"Service Call",configurable:!0})},595:(t,e,i)=>{i.r(e),i.d(e,{customElement:()=>s,eventOptions:()=>c,property:()=>r,query:()=>h,queryAll:()=>d,queryAssignedElements:()=>f,queryAssignedNodes:()=>$,queryAsync:()=>u,state:()=>l});const s=t=>e=>"function"==typeof e?((t,e)=>(customElements.define(t,e),e))(t,e):((t,e)=>{const{kind:i,elements:s}=e;return{kind:i,elements:s,finisher(e){customElements.define(t,e)}}})(t,e),n=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(i){i.createProperty(e.key,t)}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:e.key,initializer(){"function"==typeof e.initializer&&(this[e.key]=e.initializer.call(this))},finisher(i){i.createProperty(e.key,t)}},o=(t,e,i)=>{e.constructor.createProperty(i,t)};function r(t){return(e,i)=>void 0!==i?o(t,e,i):n(t,e)}function l(t){return r({...t,state:!0})}const a=({finisher:t,descriptor:e})=>(i,s)=>{var n;if(void 0===s){const s=null!==(n=i.originalKey)&&void 0!==n?n:i.key,o=null!=e?{kind:"method",placement:"prototype",key:s,descriptor:e(i.key)}:{...i,key:s};return null!=t&&(o.finisher=function(e){t(e,s)}),o}{const n=i.constructor;void 0!==e&&Object.defineProperty(i,s,e(s)),null==t||t(n,s)}};function c(t){return a({finisher:(e,i)=>{Object.assign(e.prototype[i],t)}})}function h(t,e){return a({descriptor:i=>{const s={get(){var e,i;return null!==(i=null===(e=this.renderRoot)||void 0===e?void 0:e.querySelector(t))&&void 0!==i?i:null},enumerable:!0,configurable:!0};if(e){const e="symbol"==typeof i?Symbol():"__"+i;s.get=function(){var i,s;return void 0===this[e]&&(this[e]=null!==(s=null===(i=this.renderRoot)||void 0===i?void 0:i.querySelector(t))&&void 0!==s?s:null),this[e]}}return s}})}function d(t){return a({descriptor:e=>({get(){var e,i;return null!==(i=null===(e=this.renderRoot)||void 0===e?void 0:e.querySelectorAll(t))&&void 0!==i?i:[]},enumerable:!0,configurable:!0})})}function u(t){return a({descriptor:e=>({async get(){var e;return await this.updateComplete,null===(e=this.renderRoot)||void 0===e?void 0:e.querySelector(t)},enumerable:!0,configurable:!0})})}var p;const v=null!=(null===(p=window.HTMLSlotElement)||void 0===p?void 0:p.prototype.assignedElements)?(t,e)=>t.assignedElements(e):(t,e)=>t.assignedNodes(e).filter((t=>t.nodeType===Node.ELEMENT_NODE));function f(t){const{slot:e,selector:i}=null!=t?t:{};return a({descriptor:s=>({get(){var s;const n="slot"+(e?`[name=${e}]`:":not([name])"),o=null===(s=this.renderRoot)||void 0===s?void 0:s.querySelector(n),r=null!=o?v(o,t):[];return i?r.filter((t=>t.matches(i))):r},enumerable:!0,configurable:!0})})}function $(t,e,i){let s,n=t;return"object"==typeof t?(n=t.slot,s=t):s={flatten:e},i?f({slot:n,flatten:e,selector:i}):a({descriptor:t=>({get(){var t,e;const i="slot"+(n?`[name=${n}]`:":not([name])"),o=null===(t=this.renderRoot)||void 0===t?void 0:t.querySelector(i);return null!==(e=null==o?void 0:o.assignedNodes(s))&&void 0!==e?e:[]},enumerable:!0,configurable:!0})})}},62:(t,e,i)=>{i.r(e),i.d(e,{CSSResult:()=>l,LitElement:()=>vt,ReactiveElement:()=>A,UpdatingElement:()=>pt,_$LE:()=>$t,_$LH:()=>at,adoptStyles:()=>h,css:()=>c,defaultConverter:()=>_,getCompatibleStyle:()=>d,html:()=>V,isServer:()=>_t,noChange:()=>W,notEqual:()=>y,nothing:()=>F,render:()=>ht,supportsAdoptingStyleSheets:()=>n,svg:()=>K,unsafeCSS:()=>a});const s=window,n=s.ShadowRoot&&(void 0===s.ShadyCSS||s.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,o=Symbol(),r=new WeakMap;class l{constructor(t,e,i){if(this._$cssResult$=!0,i!==o)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(n&&void 0===t){const i=void 0!==e&&1===e.length;i&&(t=r.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),i&&r.set(e,t))}return t}toString(){return this.cssText}}const a=t=>new l("string"==typeof t?t:t+"",void 0,o),c=(t,...e)=>{const i=1===t.length?t[0]:e.reduce(((e,i,s)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+t[s+1]),t[0]);return new l(i,t,o)},h=(t,e)=>{n?t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):e.forEach((e=>{const i=document.createElement("style"),n=s.litNonce;void 0!==n&&i.setAttribute("nonce",n),i.textContent=e.cssText,t.appendChild(i)}))},d=n?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return a(e)})(t):t;var u;const p=window,v=p.trustedTypes,f=v?v.emptyScript:"",$=p.reactiveElementPolyfillSupport,_={toAttribute(t,e){switch(e){case Boolean:t=t?f:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(t){i=null}}return i}},y=(t,e)=>e!==t&&(e==e||t==t),g={attribute:!0,type:String,converter:_,reflect:!1,hasChanged:y},m="finalized";class A extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this._$Eu()}static addInitializer(t){var e;this.finalize(),(null!==(e=this.h)&&void 0!==e?e:this.h=[]).push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,i)=>{const s=this._$Ep(i,e);void 0!==s&&(this._$Ev.set(s,i),t.push(s))})),t}static createProperty(t,e=g){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const i="symbol"==typeof t?Symbol():"__"+t,s=this.getPropertyDescriptor(t,i,e);void 0!==s&&Object.defineProperty(this.prototype,t,s)}}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(s){const n=this[t];this[e]=s,this.requestUpdate(t,n,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||g}static finalize(){if(this.hasOwnProperty(m))return!1;this[m]=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),void 0!==t.h&&(this.h=[...t.h]),this.elementProperties=new Map(t.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const i of e)this.createProperty(i,t[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(d(t))}else void 0!==t&&e.push(d(t));return e}static _$Ep(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}_$Eu(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,i;(null!==(e=this._$ES)&&void 0!==e?e:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(i=t.hostConnected)||void 0===i||i.call(t))}removeController(t){var e;null===(e=this._$ES)||void 0===e||e.splice(this._$ES.indexOf(t)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Ei.set(e,this[e]),delete this[e])}))}createRenderRoot(){var t;const e=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return h(e,this.constructor.elementStyles),e}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$EO(t,e,i=g){var s;const n=this.constructor._$Ep(t,i);if(void 0!==n&&!0===i.reflect){const o=(void 0!==(null===(s=i.converter)||void 0===s?void 0:s.toAttribute)?i.converter:_).toAttribute(e,i.type);this._$El=t,null==o?this.removeAttribute(n):this.setAttribute(n,o),this._$El=null}}_$AK(t,e){var i;const s=this.constructor,n=s._$Ev.get(t);if(void 0!==n&&this._$El!==n){const t=s.getPropertyOptions(n),o="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(i=t.converter)||void 0===i?void 0:i.fromAttribute)?t.converter:_;this._$El=n,this[n]=o.fromAttribute(e,t.type),this._$El=null}}requestUpdate(t,e,i){let s=!0;void 0!==t&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||y)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===i.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,i))):s=!1),!this.isUpdatePending&&s&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach(((t,e)=>this[e]=t)),this._$Ei=void 0);let e=!1;const i=this._$AL;try{e=this.shouldUpdate(i),e?(this.willUpdate(i),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(i)):this._$Ek()}catch(t){throw e=!1,this._$Ek(),t}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;null===(e=this._$ES)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return!0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,e)=>this._$EO(e,this[e],t))),this._$EC=void 0),this._$Ek()}updated(t){}firstUpdated(t){}}var b;A[m]=!0,A.elementProperties=new Map,A.elementStyles=[],A.shadowRootOptions={mode:"open"},null==$||$({ReactiveElement:A}),(null!==(u=p.reactiveElementVersions)&&void 0!==u?u:p.reactiveElementVersions=[]).push("1.6.3");const E=window,S=E.trustedTypes,w=S?S.createPolicy("lit-html",{createHTML:t=>t}):void 0,x="$lit$",C=`lit$${(Math.random()+"").slice(9)}$`,P="?"+C,O=`<${P}>`,U=document,N=()=>U.createComment(""),k=t=>null===t||"object"!=typeof t&&"function"!=typeof t,R=Array.isArray,H=t=>R(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]),T="[ \t\n\f\r]",j=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,M=/-->/g,L=/>/g,z=RegExp(`>|${T}(?:([^\\s"'>=/]+)(${T}*=${T}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),I=/'/g,q=/"/g,D=/^(?:script|style|textarea|title)$/i,B=t=>(e,...i)=>({_$litType$:t,strings:e,values:i}),V=B(1),K=B(2),W=Symbol.for("lit-noChange"),F=Symbol.for("lit-nothing"),J=new WeakMap,Z=U.createTreeWalker(U,129,null,!1);function G(t,e){if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==w?w.createHTML(e):e}const Q=(t,e)=>{const i=t.length-1,s=[];let n,o=2===e?"":"",r=j;for(let e=0;e"===a[0]?(r=null!=n?n:j,c=-1):void 0===a[1]?c=-2:(c=r.lastIndex-a[2].length,l=a[1],r=void 0===a[3]?z:'"'===a[3]?q:I):r===q||r===I?r=z:r===M||r===L?r=j:(r=z,n=void 0);const d=r===z&&t[e+1].startsWith("/>")?" ":"";o+=r===j?i+O:c>=0?(s.push(l),i.slice(0,c)+x+i.slice(c)+C+d):i+C+(-2===c?(s.push(void 0),e):d)}return[G(t,o+(t[i]||">")+(2===e?" ":"")),s]};class X{constructor({strings:t,_$litType$:e},i){let s;this.parts=[];let n=0,o=0;const r=t.length-1,l=this.parts,[a,c]=Q(t,e);if(this.el=X.createElement(a,i),Z.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(s=Z.nextNode())&&l.length0){s.textContent=S?S.emptyScript:"";for(let i=0;i2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=F}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,s){const n=this.strings;let o=!1;if(void 0===n)t=Y(this,t,e,0),o=!k(t)||t!==this._$AH&&t!==W,o&&(this._$AH=t);else{const s=t;let r,l;for(t=n[0],r=0;r{var s,n;const o=null!==(s=null==i?void 0:i.renderBefore)&&void 0!==s?s:e;let r=o._$litPart$;if(void 0===r){const t=null!==(n=null==i?void 0:i.renderBefore)&&void 0!==n?n:null;o._$litPart$=r=new et(e.insertBefore(N(),t),t,void 0,null!=i?i:{})}return r._$AI(t),r};var dt,ut;const pt=A;class vt extends A{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var t,e;const i=super.createRenderRoot();return null!==(t=(e=this.renderOptions).renderBefore)&&void 0!==t||(e.renderBefore=i.firstChild),i}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=ht(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!1)}render(){return W}}vt.finalized=!0,vt._$litElement$=!0,null===(dt=globalThis.litElementHydrateSupport)||void 0===dt||dt.call(globalThis,{LitElement:vt});const ft=globalThis.litElementPolyfillSupport;null==ft||ft({LitElement:vt});const $t={_$AK:(t,e,i)=>{t._$AK(e,i)},_$AL:t=>t._$AL};(null!==(ut=globalThis.litElementVersions)&&void 0!==ut?ut:globalThis.litElementVersions=[]).push("3.3.3");const _t=!1}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var o=e[s]={exports:{}};return t[s].call(o.exports,o,o.exports,i),o.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i(114)})();
\ No newline at end of file
+ `}}s([(0,o.property)({attribute:!1})],l.prototype,"hass",void 0),s([(0,o.property)({attribute:!1})],l.prototype,"config",void 0),s([(0,o.property)({attribute:!1})],l.prototype,"stateObj",void 0),customElements.define("service-call",l),window.customTileFeatures=window.customTileFeatures||[],window.customTileFeatures.push({type:"service-call",name:"Service Call",configurable:!0})},595:(t,e,i)=>{i.r(e),i.d(e,{customElement:()=>s,eventOptions:()=>c,property:()=>o,query:()=>h,queryAll:()=>d,queryAssignedElements:()=>f,queryAssignedNodes:()=>$,queryAsync:()=>u,state:()=>l});const s=t=>e=>"function"==typeof e?((t,e)=>(customElements.define(t,e),e))(t,e):((t,e)=>{const{kind:i,elements:s}=e;return{kind:i,elements:s,finisher(e){customElements.define(t,e)}}})(t,e),n=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(i){i.createProperty(e.key,t)}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:e.key,initializer(){"function"==typeof e.initializer&&(this[e.key]=e.initializer.call(this))},finisher(i){i.createProperty(e.key,t)}},r=(t,e,i)=>{e.constructor.createProperty(i,t)};function o(t){return(e,i)=>void 0!==i?r(t,e,i):n(t,e)}function l(t){return o({...t,state:!0})}const a=({finisher:t,descriptor:e})=>(i,s)=>{var n;if(void 0===s){const s=null!==(n=i.originalKey)&&void 0!==n?n:i.key,r=null!=e?{kind:"method",placement:"prototype",key:s,descriptor:e(i.key)}:{...i,key:s};return null!=t&&(r.finisher=function(e){t(e,s)}),r}{const n=i.constructor;void 0!==e&&Object.defineProperty(i,s,e(s)),null==t||t(n,s)}};function c(t){return a({finisher:(e,i)=>{Object.assign(e.prototype[i],t)}})}function h(t,e){return a({descriptor:i=>{const s={get(){var e,i;return null!==(i=null===(e=this.renderRoot)||void 0===e?void 0:e.querySelector(t))&&void 0!==i?i:null},enumerable:!0,configurable:!0};if(e){const e="symbol"==typeof i?Symbol():"__"+i;s.get=function(){var i,s;return void 0===this[e]&&(this[e]=null!==(s=null===(i=this.renderRoot)||void 0===i?void 0:i.querySelector(t))&&void 0!==s?s:null),this[e]}}return s}})}function d(t){return a({descriptor:e=>({get(){var e,i;return null!==(i=null===(e=this.renderRoot)||void 0===e?void 0:e.querySelectorAll(t))&&void 0!==i?i:[]},enumerable:!0,configurable:!0})})}function u(t){return a({descriptor:e=>({async get(){var e;return await this.updateComplete,null===(e=this.renderRoot)||void 0===e?void 0:e.querySelector(t)},enumerable:!0,configurable:!0})})}var p;const v=null!=(null===(p=window.HTMLSlotElement)||void 0===p?void 0:p.prototype.assignedElements)?(t,e)=>t.assignedElements(e):(t,e)=>t.assignedNodes(e).filter((t=>t.nodeType===Node.ELEMENT_NODE));function f(t){const{slot:e,selector:i}=null!=t?t:{};return a({descriptor:s=>({get(){var s;const n="slot"+(e?`[name=${e}]`:":not([name])"),r=null===(s=this.renderRoot)||void 0===s?void 0:s.querySelector(n),o=null!=r?v(r,t):[];return i?o.filter((t=>t.matches(i))):o},enumerable:!0,configurable:!0})})}function $(t,e,i){let s,n=t;return"object"==typeof t?(n=t.slot,s=t):s={flatten:e},i?f({slot:n,flatten:e,selector:i}):a({descriptor:t=>({get(){var t,e;const i="slot"+(n?`[name=${n}]`:":not([name])"),r=null===(t=this.renderRoot)||void 0===t?void 0:t.querySelector(i);return null!==(e=null==r?void 0:r.assignedNodes(s))&&void 0!==e?e:[]},enumerable:!0,configurable:!0})})}},62:(t,e,i)=>{i.r(e),i.d(e,{CSSResult:()=>l,LitElement:()=>vt,ReactiveElement:()=>b,UpdatingElement:()=>pt,_$LE:()=>$t,_$LH:()=>at,adoptStyles:()=>h,css:()=>c,defaultConverter:()=>y,getCompatibleStyle:()=>d,html:()=>V,isServer:()=>yt,noChange:()=>K,notEqual:()=>_,nothing:()=>W,render:()=>ht,supportsAdoptingStyleSheets:()=>n,svg:()=>F,unsafeCSS:()=>a});const s=window,n=s.ShadowRoot&&(void 0===s.ShadyCSS||s.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,r=Symbol(),o=new WeakMap;class l{constructor(t,e,i){if(this._$cssResult$=!0,i!==r)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(n&&void 0===t){const i=void 0!==e&&1===e.length;i&&(t=o.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),i&&o.set(e,t))}return t}toString(){return this.cssText}}const a=t=>new l("string"==typeof t?t:t+"",void 0,r),c=(t,...e)=>{const i=1===t.length?t[0]:e.reduce(((e,i,s)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+t[s+1]),t[0]);return new l(i,t,r)},h=(t,e)=>{n?t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):e.forEach((e=>{const i=document.createElement("style"),n=s.litNonce;void 0!==n&&i.setAttribute("nonce",n),i.textContent=e.cssText,t.appendChild(i)}))},d=n?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return a(e)})(t):t;var u;const p=window,v=p.trustedTypes,f=v?v.emptyScript:"",$=p.reactiveElementPolyfillSupport,y={toAttribute(t,e){switch(e){case Boolean:t=t?f:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(t){i=null}}return i}},_=(t,e)=>e!==t&&(e==e||t==t),g={attribute:!0,type:String,converter:y,reflect:!1,hasChanged:_},m="finalized";class b extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this._$Eu()}static addInitializer(t){var e;this.finalize(),(null!==(e=this.h)&&void 0!==e?e:this.h=[]).push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,i)=>{const s=this._$Ep(i,e);void 0!==s&&(this._$Ev.set(s,i),t.push(s))})),t}static createProperty(t,e=g){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const i="symbol"==typeof t?Symbol():"__"+t,s=this.getPropertyDescriptor(t,i,e);void 0!==s&&Object.defineProperty(this.prototype,t,s)}}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(s){const n=this[t];this[e]=s,this.requestUpdate(t,n,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||g}static finalize(){if(this.hasOwnProperty(m))return!1;this[m]=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),void 0!==t.h&&(this.h=[...t.h]),this.elementProperties=new Map(t.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const i of e)this.createProperty(i,t[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(d(t))}else void 0!==t&&e.push(d(t));return e}static _$Ep(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}_$Eu(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,i;(null!==(e=this._$ES)&&void 0!==e?e:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(i=t.hostConnected)||void 0===i||i.call(t))}removeController(t){var e;null===(e=this._$ES)||void 0===e||e.splice(this._$ES.indexOf(t)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Ei.set(e,this[e]),delete this[e])}))}createRenderRoot(){var t;const e=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return h(e,this.constructor.elementStyles),e}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$EO(t,e,i=g){var s;const n=this.constructor._$Ep(t,i);if(void 0!==n&&!0===i.reflect){const r=(void 0!==(null===(s=i.converter)||void 0===s?void 0:s.toAttribute)?i.converter:y).toAttribute(e,i.type);this._$El=t,null==r?this.removeAttribute(n):this.setAttribute(n,r),this._$El=null}}_$AK(t,e){var i;const s=this.constructor,n=s._$Ev.get(t);if(void 0!==n&&this._$El!==n){const t=s.getPropertyOptions(n),r="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(i=t.converter)||void 0===i?void 0:i.fromAttribute)?t.converter:y;this._$El=n,this[n]=r.fromAttribute(e,t.type),this._$El=null}}requestUpdate(t,e,i){let s=!0;void 0!==t&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||_)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===i.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,i))):s=!1),!this.isUpdatePending&&s&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach(((t,e)=>this[e]=t)),this._$Ei=void 0);let e=!1;const i=this._$AL;try{e=this.shouldUpdate(i),e?(this.willUpdate(i),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(i)):this._$Ek()}catch(t){throw e=!1,this._$Ek(),t}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;null===(e=this._$ES)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return!0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,e)=>this._$EO(e,this[e],t))),this._$EC=void 0),this._$Ek()}updated(t){}firstUpdated(t){}}var A;b[m]=!0,b.elementProperties=new Map,b.elementStyles=[],b.shadowRootOptions={mode:"open"},null==$||$({ReactiveElement:b}),(null!==(u=p.reactiveElementVersions)&&void 0!==u?u:p.reactiveElementVersions=[]).push("1.6.3");const E=window,S=E.trustedTypes,w=S?S.createPolicy("lit-html",{createHTML:t=>t}):void 0,C="$lit$",x=`lit$${(Math.random()+"").slice(9)}$`,k="?"+x,O=`<${k}>`,P=document,N=()=>P.createComment(""),U=t=>null===t||"object"!=typeof t&&"function"!=typeof t,T=Array.isArray,R=t=>T(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]),H="[ \t\n\f\r]",j=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,M=/-->/g,L=/>/g,I=RegExp(`>|${H}(?:([^\\s"'>=/]+)(${H}*=${H}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),q=/'/g,z=/"/g,D=/^(?:script|style|textarea|title)$/i,B=t=>(e,...i)=>({_$litType$:t,strings:e,values:i}),V=B(1),F=B(2),K=Symbol.for("lit-noChange"),W=Symbol.for("lit-nothing"),J=new WeakMap,Z=P.createTreeWalker(P,129,null,!1);function G(t,e){if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==w?w.createHTML(e):e}const Q=(t,e)=>{const i=t.length-1,s=[];let n,r=2===e?"":"",o=j;for(let e=0;e"===a[0]?(o=null!=n?n:j,c=-1):void 0===a[1]?c=-2:(c=o.lastIndex-a[2].length,l=a[1],o=void 0===a[3]?I:'"'===a[3]?z:q):o===z||o===q?o=I:o===M||o===L?o=j:(o=I,n=void 0);const d=o===I&&t[e+1].startsWith("/>")?" ":"";r+=o===j?i+O:c>=0?(s.push(l),i.slice(0,c)+C+i.slice(c)+x+d):i+x+(-2===c?(s.push(void 0),e):d)}return[G(t,r+(t[i]||">")+(2===e?" ":"")),s]};class X{constructor({strings:t,_$litType$:e},i){let s;this.parts=[];let n=0,r=0;const o=t.length-1,l=this.parts,[a,c]=Q(t,e);if(this.el=X.createElement(a,i),Z.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(s=Z.nextNode())&&l.length0){s.textContent=S?S.emptyScript:"";for(let i=0;i2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=W}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,s){const n=this.strings;let r=!1;if(void 0===n)t=Y(this,t,e,0),r=!U(t)||t!==this._$AH&&t!==K,r&&(this._$AH=t);else{const s=t;let o,l;for(t=n[0],o=0;o{var s,n;const r=null!==(s=null==i?void 0:i.renderBefore)&&void 0!==s?s:e;let o=r._$litPart$;if(void 0===o){const t=null!==(n=null==i?void 0:i.renderBefore)&&void 0!==n?n:null;r._$litPart$=o=new et(e.insertBefore(N(),t),t,void 0,null!=i?i:{})}return o._$AI(t),o};var dt,ut;const pt=b;class vt extends b{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var t,e;const i=super.createRenderRoot();return null!==(t=(e=this.renderOptions).renderBefore)&&void 0!==t||(e.renderBefore=i.firstChild),i}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=ht(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!1)}render(){return K}}vt.finalized=!0,vt._$litElement$=!0,null===(dt=globalThis.litElementHydrateSupport)||void 0===dt||dt.call(globalThis,{LitElement:vt});const ft=globalThis.litElementPolyfillSupport;null==ft||ft({LitElement:vt});const $t={_$AK:(t,e,i)=>{t._$AK(e,i)},_$AL:t=>t._$AL};(null!==(ut=globalThis.litElementVersions)&&void 0!==ut?ut:globalThis.litElementVersions=[]).push("3.3.3");const yt=!1},147:t=>{t.exports=JSON.parse('{"name":"service-call-tile-feature","version":"1.2.0","description":"Service Call Tile Feature for Home Assistant Tile Card","main":"./dist/service-call-tile-feature.js","scripts":{"test":"echo \\"Error: no test specified\\" && exit 1","build":"npx webpack","prelint":"tsc --noemit","lint":"eslint ./src --fix --ext .ts --config ./.eslintrc.js","pretty-quick":"pretty-quick","postinstall":"husky install","build-css":"tcm src"},"repository":{"type":"git","url":"git+https://github.com/Nerwyn/service-call-tile-feature.git"},"keywords":[],"author":"Nerwyn","license":"Apache-2.0","bugs":{"url":"https://github.com/Nerwyn/service-call-tile-feature/issues"},"homepage":"https://github.com/Nerwyn/service-call-tile-feature#readme","husky":{"hooks":{"pre-commit":"pretty-quick --staged"}},"dependencies":{"custom-card-helpers":"^1.9.0","lit":"^2.8.0"},"devDependencies":{"@typescript-eslint/eslint-plugin":"^6.6.0","@typescript-eslint/parser":"^6.6.0","eslint":"^8.48.0","husky":"^8.0.3","prettier":"^3.0.3","pretty-quick":"^3.1.3","ts-loader":"^9.4.4","typescript":"^5.2.2","webpack":"^5.88.2","webpack-cli":"^5.1.4"}}')}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s].call(r.exports,r,r.exports,i),r.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i(114)})();
\ No newline at end of file
diff --git a/package.json b/package.json
index 270bba0a..951e0fef 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "service-call-tile-feature",
- "version": "1.1.0",
+ "version": "1.2.0",
"description": "Service Call Tile Feature for Home Assistant Tile Card",
"main": "./dist/service-call-tile-feature.js",
"scripts": {
diff --git a/src/models/interfaces/IConfig.ts b/src/models/interfaces/IConfig.ts
index a66fdbb5..86204db3 100644
--- a/src/models/interfaces/IConfig.ts
+++ b/src/models/interfaces/IConfig.ts
@@ -1,18 +1,27 @@
export interface IConfig {
type: string;
- buttons: [
- {
- service: string;
- data?: {
- entity_id?: string;
- [key: string]: string | number | boolean | undefined;
- };
- color?: string;
- opacity?: number;
- icon?: string;
- icon_color?: string;
- label?: string;
- label_color?: string;
- },
- ];
+ buttons: IButton[];
+}
+
+export interface IButton extends IServiceCall, IStyle {}
+
+export interface IServiceCall {
+ service: string;
+ data?: {
+ [key: string]: string | string[] | number | boolean;
+ };
+ target?: {
+ entity_id?: string | string[];
+ device_id?: string | string[];
+ area_id?: string | string[];
+ };
+}
+
+export interface IStyle {
+ color?: string;
+ opacity?: number;
+ icon?: string;
+ icon_color?: string;
+ label?: string;
+ label_color?: string;
}
diff --git a/src/service-call-tile-feature.ts b/src/service-call-tile-feature.ts
index 09541505..6227f26f 100644
--- a/src/service-call-tile-feature.ts
+++ b/src/service-call-tile-feature.ts
@@ -1,9 +1,15 @@
+import { version } from '../package.json';
import { LitElement, TemplateResult, html, css } from 'lit';
import { property } from 'lit/decorators.js';
import { HomeAssistant } from 'custom-card-helpers';
import { HassEntity } from 'home-assistant-js-websocket';
import { IConfig } from './models/interfaces';
+console.info(
+ `%c SERVICE-CALL-TILE-FEATURE v${version}`,
+ 'color: white; font-weight: bold; background: cornflowerblue',
+);
+
class ServiceCallTileFeature extends LitElement {
@property({ attribute: false })
hass!: HomeAssistant;
@@ -30,7 +36,6 @@ class ServiceCallTileFeature extends LitElement {
buttons: [
{
service: '',
- data: {},
},
],
};
@@ -40,6 +45,14 @@ class ServiceCallTileFeature extends LitElement {
if (!config) {
throw new Error('Invalid configuration');
}
+ config = JSON.parse(JSON.stringify(config));
+ for (const button of config.buttons) {
+ // Merge target and data fields
+ button.data = {
+ ...(button.data || {}),
+ ...(button.target || {}),
+ };
+ }
this.config = config;
}
@@ -50,14 +63,53 @@ class ServiceCallTileFeature extends LitElement {
'-1',
);
const button = this.config.buttons[i];
+ const [domain, service] = button.service.split('.');
+
+ const data = button.data || {};
+ if (
+ !('entity_id' in data) &&
+ !('device_id' in data) &&
+ !('area_id' in data)
+ ) {
+ data['entity_id'] = this.stateObj.entity_id;
+ }
+
+ this.hass.callService(domain, service, data);
+ }
- const data = JSON.parse(JSON.stringify(button.data || {}));
- if (!('entity_id' in data) || data.entity_id == '') {
- data.entity_id = this.stateObj.entity_id;
+ renderBackground(itemid: number, color?: string, opacity?: number) {
+ let colorStyle = ``;
+ let opacityStyle = ``;
+ if (color) {
+ colorStyle = `background-color: ${color};`;
+ }
+ if (opacity) {
+ opacityStyle = `opacity: ${opacity};`;
}
- const [domain, entity] = button.service.split('.');
+ const style = `${colorStyle}${opacityStyle}`;
+
+ return html` `;
+ }
- this.hass.callService(domain, entity, data);
+ renderIcon(icon: string, color?: string) {
+ let style = ``;
+ if (color) {
+ style = `color: ${color};`;
+ }
+ return html` `;
+ }
+
+ renderLabel(text: string, color?: string) {
+ let style = ``;
+ if (color) {
+ style = `color: ${color};`;
+ }
+ return html`${text}
`;
}
render() {
@@ -69,48 +121,20 @@ class ServiceCallTileFeature extends LitElement {
for (const [i, entry] of this.config.buttons.entries()) {
const button: TemplateResult[] = [];
- // Button color and opacity
- let color = ``;
- let opacity = ``;
- if ('color' in entry) {
- color = `background-color: ${entry.color};`;
- }
- if ('opacity' in entry) {
- opacity = `opacity: ${entry.opacity};`;
- }
- const style = `${color}${opacity}`;
- button.push(
- html` `,
- );
+ // Button/Background
+ button.push(this.renderBackground(i, entry.color, entry.opacity));
// Icon
if ('icon' in entry) {
- let iconStyle = ``;
- if ('icon_color' in entry) {
- iconStyle = `color: ${entry.icon_color};`;
- }
button.push(
- html` `,
+ this.renderIcon(entry.icon as string, entry.icon_color),
);
}
// Label
if ('label' in entry) {
- let labelStyle = ``;
- if ('label_color' in entry) {
- labelStyle = `color: ${entry.label_color};`;
- }
button.push(
- // prettier-ignore
- html`${entry.label}
`,
+ this.renderLabel(entry.label as string, entry.label_color),
);
}
@@ -129,7 +153,8 @@ class ServiceCallTileFeature extends LitElement {
flex-flow: row;
justify-content: center;
align-items: center;
- padding: 0 12px 12px 12px;
+ padding: 0 12px 12px;
+ gap: 12px;
width: auto;
}
.container {
@@ -142,7 +167,6 @@ class ServiceCallTileFeature extends LitElement {
width: 100%;
border-radius: 10px;
border: none;
- margin: 0 6px;
padding: 0px;
box-sizing: border-box;
line-height: 0;
@@ -189,7 +213,6 @@ class ServiceCallTileFeature extends LitElement {
width: inherit;
font-family: inherit;
font-size: 12px;
- bottom: 2px;
}
`;
}