Skip to content

Commit

Permalink
Adds HA standard support for tap action
Browse files Browse the repository at this point in the history
  • Loading branch information
luixal committed Apr 19, 2024
1 parent 300301f commit 4d23976
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions media-source-image-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class MediaSourceImageCard extends HTMLElement {
if (this.watchEntities(this.config.image, hass)) this.renderContent();
// if forced_refresh_interval is set, register timeout to re-render content:
if (this.config.forced_refresh_interval && !this.forced_refresh_interval) {
this.forced_refresh_interval = setInterval(() => {console.log('timeout!!!!!!'); this.renderContent() }, this.config.forced_refresh_interval * 1000);
this.forced_refresh_interval = setInterval(() => { this.renderContent() }, this.config.forced_refresh_interval * 1000);
}
// apply grayscale according to entity state:
if (this.config.entity_id) {
Expand All @@ -173,24 +173,18 @@ class MediaSourceImageCard extends HTMLElement {
}

handleClick() {
// actions: toggle, call-service, none, (unsupported -->) more-info, navigate, url
// handle none case:
if (this.config.tap_action == 'none') return;
// default values for toggle case:
let domain = 'homeassistant';
let service = 'toggle';
let target = { entity_id: this.config.entity_id };
let data = {};
// handle call-service case:
if (this.config.tap_action?.action == 'call-service') {
let _data = this.config.tap_action;
domain = _data.service.split('.')[0];
service = _data.service.split('.')[1];
if (_data.target) target = _data.target;
if (_data.data) data = _data.data;
}
// call service:
this._hass.callService(domain, service, target, data);
const event = new Event('hass-action', {
bubbles: true,
composed: true
});
event.detail = {
config: {
entity: this.config.entity_id,
tap_action: this.config.tap_action
},
action: 'tap'
};
this.dispatchEvent(event);
}

getCardSize() {
Expand All @@ -208,7 +202,7 @@ window.customCards.push({
});

console.info(
`%c MEDIA SOURCE IMAGE CARD %c Version 0.3.0 `,
`%c MEDIA SOURCE IMAGE CARD %c Version 0.4.0 `,
'color: orange; font-weight: bold; background: black',
'color: white; font-weight: bold; background: dimgray',
);

0 comments on commit 4d23976

Please sign in to comment.