Skip to content

Commit

Permalink
Update hatc-gauge-card.js
Browse files Browse the repository at this point in the history
Add tap_action
  • Loading branch information
tagcashdev committed Nov 16, 2022
1 parent c3d5607 commit ac2ff49
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion hatc-gauge-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,45 @@ function calcPercent(sValue, sMax){
return sValue / sMax * 100;
}

function handleClick(node, hass, config, entityId){
let e;
if (!config){
console.log("not config!");
return;
}

// eslint-disable-next-line default-case
switch (config.action) {
case 'more-info': {
e = new Event('hass-more-info', { composed: true });
e.detail = {
entityId: config.entity || entityId,
};
node.dispatchEvent(e);
break;
}
case 'navigate': {
if (!config.navigation_path) return;
window.history.pushState(null, '', config.navigation_path);
e = new Event('location-changed', { composed: true });
e.detail = { replace: false };
window.dispatchEvent(e);
break;
}
case 'call-service': {
if (!config.service) return;
const [domain, service] = config.service.split('.', 2);
const serviceData = { ...config.service_data };
hass.callService(domain, service, serviceData);
break;
}
case 'url': {
if (!config.url) return;
window.location.href = config.url;
}
}
}

class HatcGaugeCard extends LitElement {
static get properties() {
return {
Expand Down Expand Up @@ -130,7 +169,7 @@ class HatcGaugeCard extends LitElement {

return html`
<ha-card class="HatcGaugeCard">
<div class="box">
<div class="box" @click=${e => this._handlePopup(e)}>
<div class="header" style="${h['text-align']}">
${hIconHTML}
${hNameHTML}
Expand Down Expand Up @@ -175,6 +214,7 @@ class HatcGaugeCard extends LitElement {
return;
}
e.stopPropagation();
handleClick(this, this.hass, this.config.tap_action, false);
}

_handleEntities(e, entity) {
Expand All @@ -190,6 +230,7 @@ class HatcGaugeCard extends LitElement {
}

e.stopPropagation();
handleClick(this, this.hass, this.config.tap_action, false);
}

static get styles() {
Expand Down

0 comments on commit ac2ff49

Please sign in to comment.