mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Support setting volume in lg_netcast media_player (#58126)
Co-authored-by: Artem Draft <Drafteed@users.noreply.github.com>
This commit is contained in:
parent
8c69194695
commit
f4aefdbf0b
@ -20,6 +20,7 @@ from homeassistant.components.media_player.const import (
|
||||
SUPPORT_TURN_OFF,
|
||||
SUPPORT_TURN_ON,
|
||||
SUPPORT_VOLUME_MUTE,
|
||||
SUPPORT_VOLUME_SET,
|
||||
SUPPORT_VOLUME_STEP,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
@ -48,6 +49,7 @@ MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||
SUPPORT_LGTV = (
|
||||
SUPPORT_PAUSE
|
||||
| SUPPORT_VOLUME_STEP
|
||||
| SUPPORT_VOLUME_SET
|
||||
| SUPPORT_VOLUME_MUTE
|
||||
| SUPPORT_PREVIOUS_TRACK
|
||||
| SUPPORT_NEXT_TRACK
|
||||
@ -121,11 +123,8 @@ class LgTVDevice(MediaPlayerEntity):
|
||||
try:
|
||||
with self._client as client:
|
||||
self._state = STATE_PLAYING
|
||||
volume_info = client.query_data("volume_info")
|
||||
if volume_info:
|
||||
volume_info = volume_info[0]
|
||||
self._volume = float(volume_info.find("level").text)
|
||||
self._muted = volume_info.find("mute").text == "true"
|
||||
|
||||
self.__update_volume()
|
||||
|
||||
channel_info = client.query_data("cur_channel")
|
||||
if channel_info:
|
||||
@ -160,6 +159,13 @@ class LgTVDevice(MediaPlayerEntity):
|
||||
except (LgNetCastError, RequestException):
|
||||
self._state = STATE_OFF
|
||||
|
||||
def __update_volume(self):
|
||||
volume_info = self._client.get_volume()
|
||||
if volume_info:
|
||||
(volume, muted) = volume_info
|
||||
self._volume = volume
|
||||
self._muted = muted
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
@ -241,6 +247,10 @@ class LgTVDevice(MediaPlayerEntity):
|
||||
"""Volume down media player."""
|
||||
self.send_command(25)
|
||||
|
||||
def set_volume_level(self, volume):
|
||||
"""Set volume level, range 0..1."""
|
||||
self._client.set_volume(float(volume * 100))
|
||||
|
||||
def mute_volume(self, mute):
|
||||
"""Send mute command."""
|
||||
self.send_command(26)
|
||||
|
Loading…
x
Reference in New Issue
Block a user