From e8a3a1ef0b28c2003aec801927eaf7388713e6c9 Mon Sep 17 00:00:00 2001 From: Ian Richardson Date: Fri, 25 Jan 2019 17:59:15 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=BA=20ability=20to=20specify=20service?= =?UTF-8?q?=20calls=20for=20tv=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit not supported by UI editor yet --- README.md | 17 ++++++++++++++++- roku-card-editor.js | 1 + roku-card.js | 42 +++++++++++++++++++++++++++++++++++------- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e1d4920..67c54f5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -[![Version](https://img.shields.io/badge/version-0.0.5-green.svg?style=for-the-badge)](#) [![mantained](https://img.shields.io/maintenance/yes/2019.svg?style=for-the-badge)](#) +[![Version](https://img.shields.io/badge/version-0.0.6-green.svg?style=for-the-badge)](#) [![mantained](https://img.shields.io/maintenance/yes/2019.svg?style=for-the-badge)](#) [![maintainer](https://img.shields.io/badge/maintainer-Ian%20Richardson%20%40iantrich-blue.svg?style=for-the-badge)](#) @@ -27,6 +27,17 @@ This card is for [Lovelace](https://www.home-assistant.io/lovelace) on [Home Ass | name | string | **Optional** | Card name | theme | string | **Optional** | Card theme | tv | boolean | **Optional** | If `true` shows volume and power buttons. Default `false` +| power | `service` | **Optional**| service to call when power button pressed +| volume_up | `service` | **Optional**| service to call when volume_up button pressed +| volume_down | `service` | **Optional**| service to call when volume_down button pressed +| volume_mute | `service` | **Optional**| service to call when volume_mute button pressed + +## `service` Options +| Name | Type | Requirement | Description +| ---- | ---- | ------- | ----------- +| service | string | **Required** | Service to call +| service_data | string | **Optional** | Service data to use + ## Installation @@ -62,6 +73,10 @@ Add a custom element in your `ui-lovelace.yaml` name: Bedroom TV theme: darkpurple tv: true + power: + service: switch.turn_on + service_data: + entity_id: switch.bedroom_tv_power ``` [Troubleshooting](https://github.com/thomasloven/hass-config/wiki/Lovelace-Plugins) diff --git a/roku-card-editor.js b/roku-card-editor.js index 16db73b..3ed2485 100644 --- a/roku-card-editor.js +++ b/roku-card-editor.js @@ -135,6 +135,7 @@ export class RokuCardEditor extends LitElement { >Roku TV? +
Use the YAML editor if you need to specify custom services
`; } diff --git a/roku-card.js b/roku-card.js index 397828c..e94fc23 100644 --- a/roku-card.js +++ b/roku-card.js @@ -67,7 +67,7 @@ class RokuCard extends LitElement { ${ - this._config.tv + this._config.tv || this._config.power ? html` ${ - this._config.tv + this._config.tv || + this._config.volume_up || + this._config.volume_down || + this._config.volume_mute ? html`
= 0 && + this._config[e.currentTarget.action] + ) { + const [domain, service] = this._config[ + e.currentTarget.action + ].service.split(".", 2); + this.hass.callService( + domain, + service, + this._config[e.currentTarget.action].service_data + ? this._config[e.currentTarget.action].service_data + : null + ); + } else { + let remote = this._config.remote + ? this._config.remote + : "remote." + this._config.entity.split(".")[1]; + this.hass.callService("remote", "send_command", { + entity_id: remote, + command: e.currentTarget.action + }); + } } applyThemesOnElement(element, themes, localTheme) {