From 863b6897fd8993bf080cc5ca60c8422395937238 Mon Sep 17 00:00:00 2001 From: Xinne van der Oord Date: Sun, 13 Feb 2022 13:31:50 +0100 Subject: [PATCH 1/5] added media control --- lg-remote-control.js | 77 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/lg-remote-control.js b/lg-remote-control.js index c0fdd64..12414b1 100644 --- a/lg-remote-control.js +++ b/lg-remote-control.js @@ -229,6 +229,7 @@ class LgRemoteControl extends LitElement { return { hass: {}, config: {}, + _custom_media_control: {}, _show_inputs: {}, _show_sound_output: {}, _show_text: {}, @@ -242,10 +243,29 @@ class LgRemoteControl extends LitElement { this._show_sound_output = false; this._show_text = false; this._show_keypad = false; + this._custom_media_devices = {}; + this._current_media_device = undefined; } render() { const stateObj = this.hass.states[this.config.entity]; + + if(!('source' in stateObj.attributes)){ + // tv is off + if("none" in this._custom_media_control){ + this._current_media_device = this.hass.states[this._custom_media_devices["none"].entity]; + } + else { + this._current_media_device = stateObj; + } + } + else if(stateObj.attributes.source in this._custom_media_devices){ + this._current_media_device = this.hass.states[this._custom_media_devices[stateObj.attributes.source].entity]; + }else{ + this._current_media_device = stateObj; + } + + const colorButtons = this.config.color_buttons === "enable"; const borderWidth = this.config.dimensions && this.config.dimensions.border_width ? this.config.dimensions.border_width : "1px"; @@ -399,12 +419,12 @@ class LgRemoteControl extends LitElement {
- - - - - - + + + + + +
@@ -448,12 +468,43 @@ class LgRemoteControl extends LitElement { }); } - _media_player_service(service) { + _media_control_action(action){ + + if(this._current_media_device.entity_id === this.config.entity){ + this._command("media.controls/"+action) + + } + else{ + let service = action; + switch(action){ + case "rewind": + service = "previous_track"; + break; + case "fastForward": + service = "next_track"; + break; + case "Record": + console.warn("Recording is not supported on custom media devices") + return; + } + this._media_player_entity_service("media_player.media_"+service, this._current_media_device.entity_id) + + + } + + + } + + _media_player_entity_service(service, entity){ this.hass.callService("media_player", service, { - entity_id: this.config.entity, + entity_id: entity, }); } + _media_player_service(service) { + this._media_player_entity_service(service,this.config.entity) + } + _select_source(source) { this.hass.callService("media_player", "select_source", { entity_id: this.config.entity, @@ -474,6 +525,16 @@ class LgRemoteControl extends LitElement { console.log("Invalid configuration"); } this.config = config; + if("media_devices" in this.config){ + this.config.media_devices.forEach(el => { + if(!el.entity){ + console.warn("Custom media_devices {} missing entity id!".format(el.name)) + return; + } + this._custom_media_devices[el.name] = el + }) + + } } getCardSize() { From 4a30a48ec4f498c983813e82ff42f6564eb92b10 Mon Sep 17 00:00:00 2001 From: Xinne van der Oord Date: Sun, 13 Feb 2022 13:36:45 +0100 Subject: [PATCH 2/5] fixed name bug --- lg-remote-control.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lg-remote-control.js b/lg-remote-control.js index 12414b1..8815973 100644 --- a/lg-remote-control.js +++ b/lg-remote-control.js @@ -252,7 +252,7 @@ class LgRemoteControl extends LitElement { if(!('source' in stateObj.attributes)){ // tv is off - if("none" in this._custom_media_control){ + if("none" in this._custom_media_devices){ this._current_media_device = this.hass.states[this._custom_media_devices["none"].entity]; } else { From b9ff6b292bd2b116a1df7600675c790f41b681d2 Mon Sep 17 00:00:00 2001 From: Xinne van der Oord Date: Sun, 13 Feb 2022 13:44:20 +0100 Subject: [PATCH 3/5] lil bug --- lg-remote-control.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lg-remote-control.js b/lg-remote-control.js index 8815973..2c32068 100644 --- a/lg-remote-control.js +++ b/lg-remote-control.js @@ -487,7 +487,7 @@ class LgRemoteControl extends LitElement { console.warn("Recording is not supported on custom media devices") return; } - this._media_player_entity_service("media_player.media_"+service, this._current_media_device.entity_id) + this._media_player_entity_service("media_"+service, this._current_media_device.entity_id) } From 07b07fd4d0323a875bf143f37799eef1c07ddfb5 Mon Sep 17 00:00:00 2001 From: Xinne van der Oord Date: Sun, 13 Feb 2022 13:47:03 +0100 Subject: [PATCH 4/5] added readme --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index da038e8..7a47aae 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,23 @@ channels: number: '503' ``` +### Media device Options + +If you have an external media that outputs the sound and the volume up/down/mute buttons are not passed to this device (HDMI CEC is sometimes a little hard for TV's..) you can define another media player to control. You can also specify an entity that should be controlled when the TV is in the off state. + +| Name | Type | Default | Supported options | Description | +| -------------- | ----------- | ------------ | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `name` | string | **Required** | Source options: all sources listed for your device and "none" for off-state | The name of the output mode this setting applies to | +| `entity` | string | **Required** | entity_id | Entity of the media_player that should be controlled | +```yaml + +media_devices: + - name: none + entity: media_player.sonos_bar + - name: HDMI1 + entity: media_player.living_room_chromecast +``` + ### Colors Options | Name | Type | Default | Supported options | Description | | -------------- | ----------- | ------------ | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | From 462cba7f086e9bc6df5f04be8a940f3786071a52 Mon Sep 17 00:00:00 2001 From: Xinne van der Oord Date: Sun, 13 Feb 2022 13:48:54 +0100 Subject: [PATCH 5/5] fixed readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a47aae..9306ac4 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ channels: ### Media device Options -If you have an external media that outputs the sound and the volume up/down/mute buttons are not passed to this device (HDMI CEC is sometimes a little hard for TV's..) you can define another media player to control. You can also specify an entity that should be controlled when the TV is in the off state. +If you have an external media player and the media controls are not passed to this device (HDMI CEC is sometimes a little hard for TV's..) you can define a media_player to control directly using the media_player service. You can also specify an entity that should be controlled when the TV is in the off state. | Name | Type | Default | Supported options | Description | | -------------- | ----------- | ------------ | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |