Add Songpal ("Sony Audio Control API") platform#12143
Add Songpal ("Sony Audio Control API") platform#12143balloob merged 16 commits intohome-assistant:devfrom
Conversation
There was a problem hiding this comment.
false positive, this is used in async_setup_platform.
f666564 to
7a0c1da
Compare
7a0c1da to
84e95e5
Compare
|
Added WIP back as this depends on python >3.5 due due to In the meantime, it would be nice to get more people who have such a device to test the tool and the integration :-) |
63d0704 to
e315db8
Compare
There was a problem hiding this comment.
continuation line under-indented for visual indent
There was a problem hiding this comment.
line too long (85 > 79 characters)
47eeb6b to
555c0b5
Compare
555c0b5 to
cae80d5
Compare
There was a problem hiding this comment.
Remove default=None. It's unnecessary for Optional to work and it also won't work since we upgraded voluptuous. The upgraded voluptuous will validate all values passed via default with the validator. None is not valid for cv.string
There was a problem hiding this comment.
This won't work. devices is not shared between 2 configured entities. It would also mean that you are registering the service twice.
There was a problem hiding this comment.
Indeed, no idea where I came up with that idea. Converted it to store devices in hass.data.
There was a problem hiding this comment.
What do you mean by moving this to a constant? Which part of it precisely?
There was a problem hiding this comment.
The whole thing.
SET_SOUND_SCHEMA = vol.Schema(…)
There was a problem hiding this comment.
Done, moved it on top of the file.
There was a problem hiding this comment.
Why? Why not just assign it to self.dev in the constructor?
This adds support for a variety of Sony soundbars and potentially many more devices using the same API. See http://vssupport.sony.net/en_ww/device.html for list of supported devices.
…r better exception handling
ae4d6f9 to
9a5f653
Compare
| except SongpalException as ex: | ||
| # if we were available, print out the exception | ||
| if self._available: | ||
| _LOGGER.error("Got an exception %s", ex, exc_info=True) |
There was a problem hiding this comment.
Use _LOGGER.exception(""), it will log the exception.
Does this also mean that whenever the device goes offline, we log a whole stack trace? That seems undesirable.
There was a problem hiding this comment.
That it will do indeed. I thought it'd be a good idea to have something visible in case some of the above calls fail, but I can remove it and just print out the exception.
| from songpal import SongpalException | ||
| try: | ||
| volumes = await self.dev.get_volume_information() | ||
| if not volumes: |
There was a problem hiding this comment.
Can you move all code that will not raise out of the try…except
There was a problem hiding this comment.
The problem is that all the method calls may result in such an exception. One solution would be to do the fetching inside one block and then access the properties outside of it, I just kept it like this to keep the assignments & their usage nearby. I would not really like to have three separate try-except-blocks for this.
There was a problem hiding this comment.
Fixed the rest of the issues (plus one extra I spotted in wrong handling of multiple volume controls) except this one. If you really prefer to have those fetches in one block, I could simply return in case of failure and set the state variables outside the try-catch block.
| try: | ||
| volumes = await self.dev.get_volume_information() | ||
| if not volumes: | ||
| _LOGGER.error("Got no volume controls, bailing out") |
There was a problem hiding this comment.
Should this set available to False?
There was a problem hiding this comment.
It should never get that far I suppose, but I can add a safe-guard for it.
edit: done.
.coveragerc
Outdated
| homeassistant/components/media_player/roku.py | ||
| homeassistant/components/media_player/russound_rio.py | ||
| homeassistant/components/media_player/russound_rnet.py | ||
| homeassistant/components/media_player/songpal.py |
* Fix coveragerc ordering * Do not print out the whole exception trace when failing to update * Do not bail out when receiving more than one volume control * Set to unavailable when no volume controls are available
| """Set volume level.""" | ||
| volume = int(volume * self._volume_max) | ||
| _LOGGER.debug("Setting volume to %s", volume) | ||
| return await self._volume_control.set_volume(volume) |
There was a problem hiding this comment.
That is indeed unnecessary here, but it should not cause any side effects so I will fix that with the same PR where this will be converted non-polling, if that's okay.
Description:
This adds support for a variety of Sony soundbars and potentially
many more devices using the same API with the help of python-songpal: https://github.com/rytilahti/python-songpal
This device is automatically discovered by netdisco and added into homeassistant accordingly, so no manual configuration is required wherever it is working.
Official API from Sony: https://developer.sony.com/develop/audio-control-api/
Officially supported devices by Sony: HT-ST5000, HT-MT500, HT-CT800, SRS-ZR5, STR-DN1080 - however, see http://vssupport.sony.net/en_ww/device.html for list of (potentially) supported devices.
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#4570
Example entry for
configuration.yaml(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
toxrun successfully. Your PR cannot be merged unless tests passREQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.