Allow configuring SIP port in VoIP (#92210)
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
d66056cfab
commit
b1d6f3afc0
9 changed files with 210 additions and 22 deletions
55
tests/components/voip/test_sip.py
Normal file
55
tests/components/voip/test_sip.py
Normal file
|
@ -0,0 +1,55 @@
|
|||
"""Test SIP server."""
|
||||
import socket
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import voip
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
async def test_create_sip_server(hass: HomeAssistant, socket_enabled) -> None:
|
||||
"""Tests starting/stopping SIP server."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
voip.DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{},
|
||||
)
|
||||
entry = result["result"]
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with pytest.raises(OSError), socket.socket(
|
||||
socket.AF_INET, socket.SOCK_DGRAM
|
||||
) as sock:
|
||||
# Server should have the port
|
||||
sock.bind(("127.0.0.1", 5060))
|
||||
|
||||
# Configure different port
|
||||
result = await hass.config_entries.options.async_init(
|
||||
entry.entry_id,
|
||||
)
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={"sip_port": 5061},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Server should be stopped now on 5060
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
|
||||
sock.bind(("127.0.0.1", 5060))
|
||||
|
||||
with pytest.raises(OSError), socket.socket(
|
||||
socket.AF_INET, socket.SOCK_DGRAM
|
||||
) as sock:
|
||||
# Server should now have the new port
|
||||
sock.bind(("127.0.0.1", 5061))
|
||||
|
||||
# Shut down
|
||||
await hass.config_entries.async_remove(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Server should be stopped
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
|
||||
sock.bind(("127.0.0.1", 5061))
|
Loading…
Add table
Add a link
Reference in a new issue