-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use pyblu library in bluesound #117257
Use pyblu library in bluesound #117257
Conversation
Hey there @thrawnarn, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
with suppress(TimeoutError): | ||
await self.async_update_sync_status() | ||
await self.async_update_presets() | ||
await self.async_update_captures() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we suppress these now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
send_bluesound_command
(which i replaced by the library) was called with raise_timeout=False
which suppressed TimeoutError
. I pulled that logic one level up and put it here.
if self._sync_status is None: | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is sync status None?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SyncStatus
is one endpoint of the device. It starts with None and might be None if the device is not reachable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the device is not reachable, I think we should raise an issue like PlatformNotReady I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the return None
to raise PlatformNotReady
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I mean, in the async_setup or async_setup_platform. If we can't fetch the state, that means the device doesn't respond and we can't get data. Right? In that case we should raise platform during setup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok. I can do that.
There is one caveat: This integrations supports multiple devices. Throwing a PlatformNotReady
would result in none of those working if one of the devices is not reachable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, let me ask some others how they did this back in the day
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any updates on this?
And as some background information: Whatever we decide here will probably be removed in my other MR, which introduces a config flow and removes the yaml configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did ask someone but got no reply, and I forgot to follow up as I was busy with my thesis, but let me ask someone else instead.
|
||
async def async_media_stop(self) -> None: | ||
"""Send stop command.""" | ||
if self.is_grouped and not self.is_master: | ||
return | ||
|
||
return await self.send_bluesound_command("Pause") | ||
async with timeout(BluesoundPlayer.COMMAND_TIMEOUT): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we put this timeout in the library instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old code did not use the timeout functionality of aiohttp
and used async with timeout(...)
instead and i kept it that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it essentially does the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it should be equivalent. I had a quick look at aiohttp
and it seems to use asyncio.timeout_at
internally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, if we can already make the code cleaner (by moving connection specific things to the library, like timeouts), go for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s always better to put the time out as far down in the code as possible so the least amount of has to worry about a cancellation.
In this case, it’s much much better for it to be done in aiohttp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the timeouts into the library. Most of the explicit timeouts have been replaced by a default timeout for all requests.
7b6e1a1
to
4c5a889
Compare
@thrawnarn Are you able to test this change? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh hi there @LouisChrist 👋
There is now a merge conflict on this PR, could you take a look?
I've drafted the PR for that reason. Please un-draft it once the CI passes and it is ready for review again by clicking the "Ready for review" button.
Thanks! 👍
../Frenck
This reverts commit a649a6b.
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
a6d9a2a
to
d48ab36
Compare
Oh one final thing:
How come this difference? |
The The problem is the underlying API. There is no consistent concept of sources. I have these "services" on my device:
Captures can be selected and they play music. Spotify works in a similar way. Presets have a different API endpoint, but can also be selected. The API endpoints for selecting and listing those services are inconsistent in what they return. And the same endpoint returns different things for different services. To summarize: It's a big mess. And this is the best solution i could find. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address the comments in a new PR. Thanks!
return | ||
await self.async_set_volume_level(current_vol + 0.01) | ||
if self.volume_level is None: | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method shouldn't return anything.
|
||
new_volume = self.volume_level + 0.01 | ||
new_volume = min(1, new_volume) | ||
return await self.async_set_volume_level(new_volume) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
Breaking change
Sources behave slightly different. Radio station providers(e.g. TuneIn, Radio Paradise) are not part of source_list anymore as they are not selectable as source. Presets which play a specific radio station can be created in the BluOS app and are displayed as sources in Home Assistant. The currently selected source tries to match those presets and falls back to the radio station provider(e.g. TuneIn, Radio Paradise).
Proposed change
Adds pypi library for all device calls: pyblu
Type of change
Additional information
Requirement for other PR: PR: Add config_flow to bluesound
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: