mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +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_OFF,
|
||||||
SUPPORT_TURN_ON,
|
SUPPORT_TURN_ON,
|
||||||
SUPPORT_VOLUME_MUTE,
|
SUPPORT_VOLUME_MUTE,
|
||||||
|
SUPPORT_VOLUME_SET,
|
||||||
SUPPORT_VOLUME_STEP,
|
SUPPORT_VOLUME_STEP,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -48,6 +49,7 @@ MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
|||||||
SUPPORT_LGTV = (
|
SUPPORT_LGTV = (
|
||||||
SUPPORT_PAUSE
|
SUPPORT_PAUSE
|
||||||
| SUPPORT_VOLUME_STEP
|
| SUPPORT_VOLUME_STEP
|
||||||
|
| SUPPORT_VOLUME_SET
|
||||||
| SUPPORT_VOLUME_MUTE
|
| SUPPORT_VOLUME_MUTE
|
||||||
| SUPPORT_PREVIOUS_TRACK
|
| SUPPORT_PREVIOUS_TRACK
|
||||||
| SUPPORT_NEXT_TRACK
|
| SUPPORT_NEXT_TRACK
|
||||||
@ -121,11 +123,8 @@ class LgTVDevice(MediaPlayerEntity):
|
|||||||
try:
|
try:
|
||||||
with self._client as client:
|
with self._client as client:
|
||||||
self._state = STATE_PLAYING
|
self._state = STATE_PLAYING
|
||||||
volume_info = client.query_data("volume_info")
|
|
||||||
if volume_info:
|
self.__update_volume()
|
||||||
volume_info = volume_info[0]
|
|
||||||
self._volume = float(volume_info.find("level").text)
|
|
||||||
self._muted = volume_info.find("mute").text == "true"
|
|
||||||
|
|
||||||
channel_info = client.query_data("cur_channel")
|
channel_info = client.query_data("cur_channel")
|
||||||
if channel_info:
|
if channel_info:
|
||||||
@ -160,6 +159,13 @@ class LgTVDevice(MediaPlayerEntity):
|
|||||||
except (LgNetCastError, RequestException):
|
except (LgNetCastError, RequestException):
|
||||||
self._state = STATE_OFF
|
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
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the device."""
|
"""Return the name of the device."""
|
||||||
@ -241,6 +247,10 @@ class LgTVDevice(MediaPlayerEntity):
|
|||||||
"""Volume down media player."""
|
"""Volume down media player."""
|
||||||
self.send_command(25)
|
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):
|
def mute_volume(self, mute):
|
||||||
"""Send mute command."""
|
"""Send mute command."""
|
||||||
self.send_command(26)
|
self.send_command(26)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user