diff --git a/homeassistant/components/lg_netcast/media_player.py b/homeassistant/components/lg_netcast/media_player.py index 64ef4f0939f..5faf6941aeb 100644 --- a/homeassistant/components/lg_netcast/media_player.py +++ b/homeassistant/components/lg_netcast/media_player.py @@ -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)