Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
Preliminary HA announce support
Browse files Browse the repository at this point in the history
  • Loading branch information
nagyrobi committed Jun 2, 2022
1 parent 6bec73d commit c4247de
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom_components/linkplay/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "linkplay",
"name": "Linkplay",
"version":"3.1.7",
"version":"3.1.8",
"documentation": "https://github.com/nagyrobi/home-assistant-custom-components-linkplay",
"issue_tracker": "https://github.com/nagyrobi/home-assistant-custom-components-linkplay/issues",
"after_dependencies": ["http", "tts", "media_source"],
Expand Down
20 changes: 19 additions & 1 deletion custom_components/linkplay/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from homeassistant.components.media_player.const import (
ATTR_GROUP_MEMBERS,
ATTR_MEDIA_CONTENT_ID,
ATTR_MEDIA_ANNOUNCE,
MEDIA_TYPE_MUSIC,
MEDIA_TYPE_URL,
MEDIA_TYPE_TRACK,
Expand Down Expand Up @@ -126,6 +127,7 @@
DEFAULT_MULTIROOM_WIFIDIRECT = False
DEFAULT_LEDOFF = False
DEFAULT_VOLUME_STEP = 5
DEFAULT_ANNOUNCE_VOLUME_INCREASE = 15

DEBUGSTR_ATTR = True
LASTFM_API_BASE = 'http://ws.audioscrobbler.com/2.0/?method='
Expand Down Expand Up @@ -371,6 +373,7 @@ def __init__(self,
self._playing_mediabrowser = False
self._playing_mass = False
self._playing_mass_radio = False
self._announce = False
self._slave_list = None
self._multiroom_wifidirect = multiroom_wifidirect
self._multiroom_group = []
Expand Down Expand Up @@ -799,6 +802,8 @@ async def async_update(self):
self._media_image_url = None
self._icecast_name = None
self._playing_tts = False
if self._announce:
await self.async_restore()

if self._playing_localfile and self._state in [STATE_PLAYING, STATE_PAUSED] and not self._playing_tts and not self._playing_mass:
#_LOGGER.debug("10 Update async_get_playerstatus_metadata FILE %s, %s", self.entity_id, self._name)
Expand Down Expand Up @@ -909,7 +914,7 @@ def name(self):
def icon(self):
"""Return the icon of the device."""

if self._playing_tts:
if self._playing_tts or self._announce:
return ICON_TTS

if self._state in [STATE_PAUSED, STATE_UNAVAILABLE, STATE_IDLE, STATE_UNKNOWN]:
Expand Down Expand Up @@ -1365,6 +1370,18 @@ async def async_play_media(self, media_type, media_id, **kwargs):
_LOGGER.debug("Trying to play media. Device: %s, Media_type: %s, Media_id: %s", self.entity_id, media_type, media_id)
if not self._slave_mode:

if kwargs.get(ATTR_MEDIA_ANNOUNCE):
self._announce = True
await self.async_snapshot(True)

volume = int(self._volume) + int(DEFAULT_ANNOUNCE_VOLUME_INCREASE)
if volume > 100:
volume = 100

value = await self.call_linkplay_httpapi("setPlayerCmd:vol:{0}".format(str(volume)), None)
if value == "OK":
self._volume = volume

if not (media_type in [MEDIA_TYPE_MUSIC, MEDIA_TYPE_URL, MEDIA_TYPE_TRACK] or media_source.is_media_source_id(media_id)):
_LOGGER.warning("For: %s Invalid media type %s. Only %s and %s is supported", self._name, media_type, MEDIA_TYPE_MUSIC, MEDIA_TYPE_URL)
await self.async_media_stop()
Expand Down Expand Up @@ -2611,6 +2628,7 @@ async def async_restore(self):
# await asyncio.sleep(.6)

self._playing_tts = False
self._announce = False
self._playhead_position = self._snap_playhead_position

if self._snap_spotify:
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"content_in_root": false,
"render_readme": false,
"domains": ["media_player"],
"homeassistant": "2022.3.0"
"homeassistant": "2022.6.0"
}

0 comments on commit c4247de

Please sign in to comment.