LinkPlay Integration

I think, “companion_app_name” also is not correct name for field. It may be misunderstand by user as “name of companion application”…

I think, best name for field is “device_name”, because it is short, already used in the companion application in approximately the same form and, together with the field “name”, will lead the user to think that this is some special device name, not a name for the frontend.

Hi! First of all, thanks for your amazing job. Literally, it works :slight_smile:
Well, or it used to work… after upgrading HA to 0.88.1, and using last code from https://github.com/nicjo814/home-assistant/blob/noiuri/homeassistant/components/media_player/linkplay.py I get this error went starting:

Error loading custom_components.media_player.linkplay. Make sure all dependencies are installed

Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.6/site-packages/homeassistant/loader.py”, line 147, in _load_file
module = importlib.import_module(path)
File “/usr/lib/python3.6/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 678, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/home/homeassistant/.homeassistant/custom_components/media_player/linkplay.py”, line 19, in
from homeassistant.components.media_player import (
ImportError: cannot import name ‘MEDIA_TYPE_MUSIC’

It’s weird, because MEDIA_TYPE_MUSIC is there…
Please, help. If I can help you in any way, just ask.
Thank you.

That’s interesting… Will take a look at this when possible.

1 Like

Solution:
First rename media_player/linkplay.py to linkplay/media_player.py
Then in this file replace lines 19-24 from

from homeassistant.components.media_player import (
    DOMAIN, MEDIA_PLAYER_SCHEMA, MEDIA_TYPE_MUSIC, PLATFORM_SCHEMA,
    SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PLAY, SUPPORT_PLAY_MEDIA,
    SUPPORT_PREVIOUS_TRACK, SUPPORT_SEEK, SUPPORT_SELECT_SOUND_MODE,
    SUPPORT_SELECT_SOURCE, SUPPORT_SHUFFLE_SET, SUPPORT_VOLUME_MUTE,
    SUPPORT_VOLUME_SET, MediaPlayerDevice)

to

from homeassistant.components.media_player import (
    MEDIA_PLAYER_SCHEMA, MediaPlayerDevice)
from homeassistant.components.media_player.const import (
    DOMAIN, MEDIA_TYPE_MUSIC, SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, SUPPORT_PLAY,
    SUPPORT_PLAY_MEDIA, SUPPORT_PREVIOUS_TRACK, SUPPORT_SEEK,
    SUPPORT_SELECT_SOUND_MODE, SUPPORT_SELECT_SOURCE, SUPPORT_SHUFFLE_SET,
    SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET)

then replace line 60 from

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({

to

PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({

Have a nice day! :wink:

Thanks! I found that the constants had moved to the “const” file… However I’ll probably fix it with a try/except solution to make it compatible with both pre and post .88 versions of HA. I won’t be able to fix it in a few days though.

Could you explain the reasoning behind why you suggest the name change to linkplay/media_player.py? I haven’t looked very carefully at the last couple of commits yet :slight_smile:

Ok, thanks! That makes it more difficult to have a single version that is compatible with both pre and post .88 version of HA…

Detailed description about paths changing: Embedded platforms and the road to packaged components · Issue #124 · home-assistant/architecture · GitHub

1 Like

Thank you guys, works like a charm. I definitely need to learn python :slight_smile:

Sure, I will try it in a week or two, when I return home.

Thanks again for all your help. I’ve created a new branch where further development will be done here:

It includes your fixes for the 0.88 version of HA.

I’ve now added the “devicename” parameter which should be set to the name of the device from the ios/android companion app (it’s a required parameter). The “name” parameter is now optional and will be set to the same as the “devicename” parameter if not provided.

This change is only committed to the post-88 branch above.

I have updated the files and added devicename to config, is this the way to do it still?

  • platform: linkplay
    host: 192.168.99.6
    devicename: Köket
  • platform: linkplay
    host: 192.168.99.9
    devicename: Vardagsrummet

How about the ability to automatically update a component via custom_updater?

Detailed description: https://github.com/custom-components/custom_updater/wiki/components

1 Like

Yes, looks correct

By the way…
I’ve published my Home Assistant configuration. Maybe it will be helpful for some people.

I get this alot in the Logs. It bugs me to get big logs:

Log Details (ERROR)

Sat Mar 23 2019 13:17:28 GMT+0100 (centraleuropeisk normaltid)

Error fetching data: <PreparedRequest [GET]> from http://192.168.99.9/httpapi.asp?command=getPlayerStatus failed with HTTPConnectionPool(host=‘192.168.99.9’, port=80): Max retries exceeded with url: /httpapi.asp?command=getPlayerStatus (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x7fc3c18e3240>, ‘Connection to 192.168.99.9 timed out. (connect timeout=2)’))

Does the speaker IP is correct, speaker is switched on and works in Master mode?

Tryed using

“media_player.linkplay_connect_multiroom”

with service data

{
“entity_id”: “alb”,
“master_id”: “albastru”
}

configuration.yaml:

  • platform: linkplay
    host: 192.168.0.151
    name: albastru

  • platform: linkplay
    host: 192.168.0.152
    name: alb

The log:

Entity ID alb is an invalid entity id for dictionary value @ data[‘entity_id’]
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/websocket_api/commands.py”, line 148, in handle_call_service
connection.context(msg))
File “/usr/local/lib/python3.7/site-packages/homeassistant/core.py”, line 1113, in async_call
processed_data = handler.schema(service_data)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 267, in call
return self._compiled(, data)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 589, in validate_dict
return base_validate(path, iteritems(data), out)
File “/usr/local/lib/python3.7/site-packages/voluptuous/schema_builder.py”, line 427, in validate_mapping
raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: Entity ID alb is an invalid entity id for dictionary value @ data[‘entity_id’]

When it’s in master mode it works correctly, but I don’t use them separately mostly as multiroom. And if this is because of that then the component needs to be able to detect if they are paird or not.