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

add support for axis network speaker #130163

Draft
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

jonoberheide
Copy link
Contributor

@jonoberheide jonoberheide commented Nov 8, 2024

Hi! First-time HA developer here, so (1) adding this support took a lot longer/more learning than the LOC may indicate, and (2) open to feedback on anything I may have done incorrectly.

Proposed change

Add support for Axis Network Speakers, exposing the device as a Media Player.

Tested on the Axis C1410 Mk II Network Mini Speaker.

@Kane610 Right now this is just adding the basic support to broadcast audio via the Axis speaker and the Audio API transmit.cgi. There is little/no state tracking, no event updates from the device, etc. I am guessing this would work with any Axis devices that support the Audio API (eg. a camera that also has a built-in speaker), but I've only tested it on the dedicated C1410 speaker device.

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

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][dev-checklist]
  • I have followed the [perfect PR recommendations][perfect-pr]
  • 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:

  • Documentation added/updated for [www.home-assistant.io][docs-repository]

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

  • The [manifest file][manifest-docs] 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.

@home-assistant
Copy link

home-assistant bot commented Nov 8, 2024

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

Code owner commands

Code owners of axis 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 axis 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.

Copy link
Member

@Kane610 Kane610 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Thank you

I would really like to see parts related to transmit.cgi be moved and defined in the axis library instead. Keeps everything together.

Im also missing a check somewhere that validates that the device has audio out.

And once all of that is fixed Im missing tests.

I will be busy for the next two weeks but am available for support after that.

Have you referenced other integrations using ffmpeg if there are some common pattern recommended to be used?

homeassistant/components/axis/media_player.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft November 9, 2024 14:20
@home-assistant
Copy link

home-assistant bot commented Nov 9, 2024

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

Co-authored-by: Robert Svensson <Kane610@users.noreply.github.com>
@jonoberheide
Copy link
Contributor Author

I would really like to see parts related to transmit.cgi be moved and defined in the axis library instead. Keeps everything together.

Makes sense. I figured there was some logical subset to have in the axis lib. I kept everything in HA-land to start just for simplicity.

Im also missing a check somewhere that validates that the device has audio out.

I will poke at this. I have a couple Axis cameras and a network relay so hopefully those should be good devices to validate against.

And once all of that is fixed Im missing tests.

HA test suite is new territory, but I'll give it a shot.

Have you referenced other integrations using ffmpeg if there are some common pattern recommended to be used?

Yes, I modeled it roughly off a few other components that use ffmpeg for audio transcoding like tts/uiprotect/etc. Seems ffmpeg_manager is best practice in HA-land, while some components have the ffmpeg logic in the non-HA helper library. The latter could make sense here in terms of standalone usage/testing from the axis library, but ffmpeg_manager is nice for path discovery and such. One middle-ground might be to use ffmpeg_manager and pass the path into the axis library and have the rest of the logic in there. I think this is roughly what uiprotect does IIRC.

Some components use temp files with ffmpeg, but I wanted to keep things off disk with subprocess pipes. Also, in theory, ffmpeg itself could directly stream the resulting audio to the transmit.cgi URL, but keeping things native/async with vapix/httpx is better IMO.

@Kane610
Copy link
Member

Kane610 commented Nov 9, 2024

Lets take the discussion on ffmpeg once Im back. I think its good to provide s ffmpeg client into the library similar to how the httpx client is provided. Because then all axis details are kept in the library which is what we want.

I have rewritten most tests for axis this summer so they are att least a bit more modern

- move ffmpeg logic into the axis library
- add volume/mute support
- implement async_update to get latest device state
- only add a media player entity if both audio APIs are supported
@jonoberheide
Copy link
Contributor Author

New changes:

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.

2 participants