Skip to content
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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

LouisChrist
Copy link

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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Requirement for other PR: PR: Add config_flow to bluesound

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @thrawnarn, mind taking a look at this pull request as it has been labeled with an integration (bluesound) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of bluesound can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign bluesound Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@LouisChrist LouisChrist changed the title Integrate pypi libraray: pyblu Integrate pypi library: pyblu May 11, 2024
Comment on lines +330 to +333
with suppress(TimeoutError):
await self.async_update_sync_status()
await self.async_update_presets()
await self.async_update_captures()
Copy link
Member

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?

Copy link
Author

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.

Comment on lines +384 to +385
if self._sync_status is None:
return None
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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

Copy link
Author

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.

Copy link
Member

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

Copy link
Author

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.

Copy link
Member

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


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):
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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?

Copy link
Author

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.

@MartinHjelmare MartinHjelmare changed the title Integrate pypi library: pyblu Use pyblu library in bluesound May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants