diff --git a/README.md b/README.md index da038e8..9306ac4 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,23 @@ channels: number: '503' ``` +### Media device Options + +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 | +| -------------- | ----------- | ------------ | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `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 | | -------------- | ----------- | ------------ | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | diff --git a/lg-remote-control.js b/lg-remote-control.js index c0fdd64..2c32068 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_devices){ + 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 {