Home Assistant release (hass --version):
0.65.4 (docker image)
Python release (python3 --version):
โฏ docker-compose exec server python3 --version
Python 3.6.4
Component/platform:
sonos media player
Description of problem:
Since the sonos changes in 0.64, I am unable to receive state from my sonos players. I have my players statically defined using the hosts list. The component does detect them correctly (player name, etc) and load them, but cannot determine if they are playing or not, nor update what is or isn't playing. The play/pause button in the Web UI does correctly reach the sonos players, but home assistant never updates based on those changes.
Expected:
See what's playing, know whether the sonos player is playing or not.
Problem-relevant configuration.yaml entries and steps to reproduce:
media_player:
- platform: sonos
hosts:
- sonos1.lan.private
- sonos2.lan.private
Additional info:
I run home assistant on a different subnet that my Sonos players. This has worked reliably until the switch to using SoCo's events.
I've forwarded 1400 into my container and overridden the undocumented advertise_addr with the IP of my docker host, which allows me to see the traffic flowing to the host (prior to that it was using the docker internal IP). Unfortunately, the processes in the docker container are not listening on 1400 so nothing happens.
root@3de8aa501b68:/usr/src/app# ss -ltnp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 *:8883 *:* users:(("python",pid=1,fd=16))
LISTEN 0 128 127.0.0.11:34259 *:*
LISTEN 0 100 *:8123 *:* users:(("python",pid=1,fd=36))
LISTEN 0 100 *:1883 *:* users:(("python",pid=1,fd=15))
The required SoCo support for advertise_addr was never merged so I don't think this setup can currently work.
Ahh, well hass is still setup to use it: https://github.com/home-assistant/home-assistant/blob/0.65.4/homeassistant/components/media_player/sonos.py#L144-L146
Without some way to have separate listen and advertise IPs, this new sonos component will never work for docker users.
edit: for docker users that aren't using net=host
I run Hassbian in a Python virt.environment. Just updated Python to 3.6.4 and updating to HA 0.65.4. I have the same issue as described above.
Please try this polling version as a custom component and let me know how it works for you.
I'll try that version when I get a chance, but may take a couple days @amelchio. I did grab the version from 0.63.3 and threw it in custom_components in order to stay upgraded but get it working.
FYI the SoCo PR has been reopened here: https://github.com/SoCo/SoCo/pull/604
Yeah, I thought I'd give recreating that PR a try, hopefully it will get accepted, as it could save some headaches for Docker users
Just for the record, what's bad about using --net=host ?
@amelchio difficult. The container have his own virtual network and can't get access to hole socket data or memory. Other case is that the software can't open a port without they will be available outsite.
I run normally container also not on host but home-assistant is so a big software they need discovery so many data, that he need run on host or you run into problems if you not know your own environment. That is also the reason why hass.io run it on host. Point of view, hass.io need run home-assistant as main application.
Anyway that is a wrong security feeling. If you really want protect your container, you need use also apparmor or other hardening of kernel. But that will be another topic.
I have been running without --net=host for many months without issue. My network is likely more complicated than others, but all of my configuration allows for static discovery. Sonos is a good example of a component that allows you to specify the Sonos device by ip/hostname, so it implies non-discovery methods of configuration.
I run a couple dozen containers for various purposes, none of which require running on the host's network interface.
I'm running docker and sonos have stopped working. Tried to add network_mode: host (docker-compose v2+ parameter).
Getting this error:
Error while setting up platform sonos
Traceback (most recent call last):
File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 82, in async_setup
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
return fut.result()
File "/usr/local/lib/python3.6/asyncio/futures.py", line 243, in result
raise self._exception
File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/app/homeassistant/components/media_player/sonos.py", line 182, in setup_platform
add_devices([SonosDevice(p) for p in players])
File "/usr/src/app/homeassistant/components/media_player/sonos.py", line 182, in <listcomp>
add_devices([SonosDevice(p) for p in players])
File "/usr/src/app/homeassistant/components/media_player/sonos.py", line 359, in __init__
self._set_basic_information()
File "/usr/src/app/homeassistant/components/media_player/sonos.py", line 426, in _set_basic_information
self._play_mode = self.soco.play_mode
File "/usr/local/lib/python3.6/site-packages/soco/core.py", line 388, in play_mode
('InstanceID', 0),
File "/usr/local/lib/python3.6/site-packages/soco/services.py", line 181, in _dispatcher
return self.send_command(action, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/soco/services.py", line 404, in send_command
self.handle_upnp_error(response.text)
File "/usr/local/lib/python3.6/site-packages/soco/services.py", line 455, in handle_upnp_error
error = XML.fromstring(xml_error)
File "/usr/local/lib/python3.6/xml/etree/ElementTree.py", line 1315, in XML
return parser.close()
File "<string>", line None
xml.etree.ElementTree.ParseError: no element found: line 1, column 0
@frode I think that error means that you are trying to use a sub as a player, so try removing it from the list of players. If that does not work, please open a separate issue as it is unrelated to this one.
I have been running without
--net=hostfor many months without issue.
Well, you must always have been missing out on push updates, you just did not know.
This is not just about discovery. If the events are not working you do not get immediate updates in HA when operating the player with the Sonos app or even just when a new song starts playing.
Looking forward to feedback on the polling version.
FYI, I removed advertise_addr from HA to avoid further confusion but I am not against putting it back if SoCo is updated.
I have updated the polling version and it is now fairly clean so I would not mind merging it. First, however, I need someone that is affected by this issue to test the change and verify that it solves the problem.
To test, copy this file to config/custom_components/media_player/sonos.py and restart.
@amelchio i confirm that it works for me! thanks,
@amelchio I got this error using the latest file:
2018-03-18 10:38:58 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up platform sonos
Traceback (most recent call last):
File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 82, in async_setup
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
return fut.result()
File "/usr/local/lib/python3.6/asyncio/futures.py", line 243, in result
raise self._exception
File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/media_player/sonos.py", line 176, in setup_platform
add_devices(SonosDevice(p) for p in players)
File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 119, in _schedule_add_entities
self._async_schedule_add_entities, list(new_entities),
File "/config/custom_components/media_player/sonos.py", line 176, in <genexpr>
add_devices(SonosDevice(p) for p in players)
File "/config/custom_components/media_player/sonos.py", line 359, in __init__
self._set_basic_information()
File "/config/custom_components/media_player/sonos.py", line 429, in _set_basic_information
for fav in self.soco.music_library.get_sonos_favorites():
AttributeError: 'MusicLibrary' object has no attribute 'get_sonos_favorites'
@adamcstephens This means that your SoCo library is not version 0.14. Try nuking your config/deps folder and do a restart to have dependencies reinstalled.
@amelchio that worked and so does the updated component.
Well, you must always have been missing out on push updates, you just did not know.
That's likely. State was updating, albeit delayed by some time. I'd love to get the event model working, but at least the polling version gets me back to a functional state. There are probably other setups where falling back to polling is a good thing, so it seems a good option to me.
I'll keep an eye on the SoCo PR. Otherwise my issue is fixed for now. I'll leave this open in case others have issues, but feel free to close when you are ready.
@amelchio It wasnt a SUB, but I pointed to all my 6 sonos devices per IP address. When i referenced only 1 of them, all got resolved. Is this how the module is designed, to discover all connected devices based on one available? Sorry if i create noise in a non-relevant case here.
@frode In a normal network setup you do not need to list any players at all, it will discover automatically.