Skip to content

Commit

Permalink
📺 ability to specify service calls for tv options
Browse files Browse the repository at this point in the history
not supported by UI editor yet
  • Loading branch information
iantrich committed Jan 25, 2019
1 parent e884af0 commit e8a3a1e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)](#)

Expand All @@ -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

Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions roku-card-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export class RokuCardEditor extends LitElement {
>Roku TV?</paper-toggle-button
>
</div>
<div>Use the YAML editor if you need to specify custom services</div>
</div>
`;
}
Expand Down
42 changes: 35 additions & 7 deletions roku-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class RokuCard extends LitElement {
</paper-listbox>
</paper-dropdown-menu>
${
this._config.tv
this._config.tv || this._config.power
? html`
<paper-icon-button
.action="${"power"}"
Expand Down Expand Up @@ -161,7 +161,10 @@ class RokuCard extends LitElement {
</div>
${
this._config.tv
this._config.tv ||
this._config.volume_up ||
this._config.volume_down ||
this._config.volume_mute
? html`
<div class="row">
<paper-icon-button
Expand Down Expand Up @@ -234,11 +237,36 @@ class RokuCard extends LitElement {
}

handleActionClick(e) {
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
});
const custom_services = [
"power",
"volume_up",
"volume_down",
"volume_mute"
];

if (
custom_services.indexOf(e.currentTarget.action) >= 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) {
Expand Down

0 comments on commit e8a3a1e

Please sign in to comment.