From c801c628ce79bf36e1cf3189f5182bcc5c5e564c Mon Sep 17 00:00:00 2001 From: Piotr Machowski Date: Sun, 5 Nov 2023 05:22:55 +0100 Subject: [PATCH] Add overriding keys --- changing_buttons.md | 61 ++++++++++++++++++++++++++++++++++++++++ src/const.ts | 1 - src/lg-remote-control.ts | 47 +++++++++++++++++++++---------- 3 files changed, 93 insertions(+), 16 deletions(-) create mode 100644 changing_buttons.md diff --git a/changing_buttons.md b/changing_buttons.md new file mode 100644 index 0000000..147662d --- /dev/null +++ b/changing_buttons.md @@ -0,0 +1,61 @@ +## Overriding key actions + +Example config: +```yaml +type: custom:lg-remote-control +av_receiver_family: anthemav +entity: media_player.lg_webos_smart_tv +is_smart_tv: 'true' +colors: + buttons: red + text: blue + background: blue +projectorentity: '' +mac: '00:11:22:33:44:66' +keys: + LEFT: + service: light.toggle + data: + entity_id: light.tv + VOLUME_UP: + service: light.toggle + data: + entity_id: light.tv +``` + +available keys: +- `"1"` +- `"2"` +- `"3"` +- `"4"` +- `"5"` +- `"6"` +- `"7"` +- `"8"` +- `"9"` +- `"0"` +- `"UP"` +- `"LEFT"` +- `"ENTER"` +- `"RIGHT"` +- `"BACK"` +- `"DOWN"` +- `"EXIT"` +- `"RED"` +- `"GREEN"` +- `"YELLOW"` +- `"BLUE"` +- `"HOME"` +- `"CHANNELUP"` +- `"MUTE"` +- `"INFO"` +- `"CHANNELDOWN"` +- `"PLAY"` +- `"PAUSE"` +- `"STOP"` +- `"REWIND"` +- `"RECORD"` +- `"FAST_FOWARD"` +- `"POWER"` +- `"VOLUME_UP"` +- `"VOLUME_DOWN"` diff --git a/src/const.ts b/src/const.ts index cdd0949..8f2841e 100644 --- a/src/const.ts +++ b/src/const.ts @@ -1,4 +1,3 @@ export const CARD_VERSION = "v@LG_REMOTE_CONTROL_CARD_VERSION_PLACEHOLDER@"; - export const CARD_TAG_NAME = "lg-remote-control"; export const EDITOR_CARD_TAG_NAME = "lg-remote-control-editor"; diff --git a/src/lg-remote-control.ts b/src/lg-remote-control.ts index 49076f4..fad0668 100644 --- a/src/lg-remote-control.ts +++ b/src/lg-remote-control.ts @@ -123,7 +123,7 @@ class LgRemoteControl extends LitElement { ${stateObj.state === 'off' ? html` ` : html` - + `} @@ -261,12 +261,12 @@ class LgRemoteControl extends LitElement {
- - - - - - + + + + + +
@@ -297,30 +297,31 @@ class LgRemoteControl extends LitElement { } _button(button) { - this.hass.callService("webostv", "button", { + this.callServiceFromConfig(button, "webostv.button", { entity_id: this.config.entity, button: button - }); + }) } - _command(command) { - this.hass.callService("webostv", "command", { + _command(button, command) { + this.callServiceFromConfig(button, "webostv.command", { entity_id: this.config.entity, command: command }); } + _media_player_turn_on(mac) { if (this.config.mac) { this.hass.callService("wake_on_lan", "send_magic_packet", { mac: mac }); } else { - this._media_player_service("turn_on"); + this._media_player_service("POWER", "turn_on"); } } - _media_player_service(service) { - this.hass.callService("media_player", service, { + _media_player_service(button, service) { + this.callServiceFromConfig(button, `media_player.${service}`, { entity_id: this.config.entity, }); } @@ -335,7 +336,7 @@ class LgRemoteControl extends LitElement { // Funzione per aggiornare e chiamare il servizio const updateValue = (service) => { - this.hass.callService("media_player", service, { + this.callServiceFromConfig(service.toUpperCase(), `media_player.${service}`, { entity_id: this.output_entity, }); }; @@ -477,6 +478,22 @@ class LgRemoteControl extends LitElement { return 15; } + callServiceFromConfig(key: string, service: string, serviceData: Record) { + let serviceToUse = service; + let serviceDataToUse = serviceData; + if(this.config.keys && key in this.config.keys) { + const keyConfig = this.config.keys[key]; + serviceToUse = keyConfig["service"]; + serviceDataToUse = keyConfig["data"]; + } + this.hass.callService( + serviceToUse.split(".")[0], + serviceToUse.split(".")[1], + serviceDataToUse + ); + + } + static getIcon(iconName) { return Object.keys(LgRemoteControl.iconMapping).includes(iconName) ? LgRemoteControl.iconMapping[iconName]