diff --git a/media-source-image-card.js b/media-source-image-card.js index ddc56eb..2a8b27e 100644 --- a/media-source-image-card.js +++ b/media-source-image-card.js @@ -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) { @@ -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() { @@ -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', );