-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
VoIP: Add support for announce #135291
base: dev
Are you sure you want to change the base?
VoIP: Add support for announce #135291
Conversation
Hey there @balloob, @synesthesiam, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
We will need to add some way for the HassVoipDatagramProtocol to pick an appropriate protocol factory for the different use cases: HA receiving a call, HA calling out for an announcement, and HA calling out as part of the start_conversation service. I imagine at some point we will want to account for what happens when one of those services, announce or start_conversation, is called while there is an active call with the target VOIP device. Currently the code assumes there is not an active call and will always start by calling the phone. |
), | ||
): str, | ||
vol.Required( | ||
CONF_SIP_HOST, |
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 want to ask the user these values?
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.
Is this to get the IP address of the HA box? We should instead import async_get_source_ip
from homeassistant.components.network
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.
Is that guaranteed to be the external IP for the HA box? I think there would still be value in allowing the host sent in the outgoing invite message to be configurable, but using async_get_source_ip as a default value would make sense. Depending on SIP server configurations a specific user might be required in the INVITE From header, so even though that configuration isn't officially supported, it is helpful for me. If we make those optional with sane defaults is that still a workable solution?
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.
We don't want them in the main configuration flow, as users will be confused (we want to ask as little information as possible when setting up an integration).
Can you try if it works for you with async_get_source_ip
?
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 user and host to an "advanced options" page and defaulted host to the value of async_get_source_ip, I hope that is an acceptable solution?
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, let's stick with just calling async_get_source_ip
when we need to do an announcement. That method exists to get the right IP address for exactly this reason:
@bind_hass
async def async_get_source_ip(
hass: HomeAssistant, target_ip: str | UndefinedType = UNDEFINED
) -> str:
"""Get the source ip for a target ip."""
Adding this option puts an extra burden on the user having a bunch of IP addresses configured hidden inside config entry configurations.
voip_id = ( | ||
call_info.caller_endpoint.uri | ||
if call_info.caller_endpoint | ||
else call_info.caller_ip |
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.
Can we do an auto-migration here? So every incoming device, we check if it exists under the old ID, and if so, we migrate it to the new endpoint uri.
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 tried to update it to do an auto-migration, but it would be difficult for me to test that since I already have new devices for all of my phones.
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.
Can you break out the caller ID breaking change into its own PR? I also added a note how we can try to auto-migrate old devices automatically. Would be cool to add to that PR if possible.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
We should also make sure that we start with speaking the announcement message. Once we did that, Home Assistant should hang up. Users should use |
430dda1
to
a4b7063
Compare
|
293d6b6
to
8216fd1
Compare
@@ -416,6 +416,7 @@ async def _resolve_announcement_media_id( | |||
language=pipeline.tts_language, | |||
options=tts_options, | |||
) | |||
return AssistSatelliteAnnouncement(message, media_id, media_id_source) |
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.
Seems like this has the potential to affect other assist satellite components, but the VOIP announcements wouldn't work otherwise.
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 added an internal_media_id property to the AssistSatelliteAnnouncement to hopefully mitigate this issue.
This PR is already pretty unwieldy as it is, I figure we can get this stable and add start_conversation support as a separate PR. |
@@ -96,7 +96,11 @@ class AssistSatelliteAnnouncement: | |||
media_id: str | |||
"""Media ID to be played.""" | |||
|
|||
internal_media_id: str |
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've extracted this as #136141 and renamed to original_media_id
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.
Should I rebase this branch to pick up that change or clean that up later?
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.
rebase.
def on_call(self, call_info: CallInfo): | ||
"""Set up state when starting a call.""" | ||
device = self.devices.async_get_or_create(call_info) | ||
if device is not 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.
The response can never be None
.
"""Set up state when starting a call.""" | ||
device = self.devices.async_get_or_create(call_info) | ||
if device is not None: | ||
device.current_call = call_info |
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.
Is this something that we want to pass to set_active
instead? Having a call info then indicates it's active.
@@ -126,6 +126,9 @@ async def async_process_audio_stream( | |||
text = transcript.text | |||
break | |||
|
|||
except TimeoutError: |
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 was this added?
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.
Without it the call state wouldn't get properly cleaned up which I think was causing subsequent calls to not create a new RTP server and there would be no audio on the phone.
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 removed it in the latest change, I am still having issues with it but it is not the same as before so that might have been a red herring when I added it the first time. I think I need to increase the timeout value because it seems like when I say a command it will make the tone like it heard the command, but then shortly after it hangs up on me from what I assume is caused by the timeout error.
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 added this back in because hanging up after the regular command pipeline loop wouldn't work without it.
We need to add an implementation for this still, right? |
It should be implemented, line 134 homeassistant/components/voip/voip.py |
It's not explicitely mentioned, but this PR requires home-assistant-libs/voip-utils#25 to be merged and released right? |
Yes, is there a way to specify an unreleased version in the manifest? Edit: I think I found it, https://developers.home-assistant.io/docs/creating_integration_manifest/#custom-requirements-during-development--testing |
Currently when making an announcement the phone will be called and will go into the regular assist pipeline when the call is answered.
The create rtp server method is in voip_utils
Made a queue of pipeline operations that can be added to in case the announcement service is called during an ongoing call.
Improve task queue handling by using put_nowait for adding tasks to avoid the need for creating a task for adding items. The task queue should also be cleared when the call ends. If the call needs to end, either because it is the end of an announcement or there was an unrecoverable error, HA should initiate a hang up in an attempt to cleanly end the call.
6796078
to
4897501
Compare
The pre-commit checks complain if I try to set the voip_utils requirement to point to my branch, so I left that as is. I am still having an issue where when I hang up after doing the regular voice command pipeline stuff the TimeoutError isn't being caught in the _run_pipeline method which means the call isn't hung up. This means if I try to then play an announcement after that it thinks the previous call is ongoing and tries to play the announcement on that non-existent call. I still haven't figured out a way to get that to work such that it hangs up after I hang up my phone without it randomly hanging up in the middle of processing commands. |
Breaking change
Proposed change
This adds the "Announce" service to the VOIP Assist Satellite component. Currently when announce is called HA will call the phone and go into the standard assist pipeline when the call is answered.
Type of change
Additional information
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
.To help with the load of incoming pull requests: