2023-04-13 03:23:20 +00:00
|
|
|
"""Test VoIP devices."""
|
2024-03-08 13:44:56 +00:00
|
|
|
|
2023-04-13 03:23:20 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from voip_utils import CallInfo
|
|
|
|
|
2023-04-17 02:59:05 +00:00
|
|
|
from homeassistant.components.voip import DOMAIN
|
|
|
|
from homeassistant.components.voip.devices import VoIPDevice, VoIPDevices
|
2023-04-13 03:23:20 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2023-05-04 09:25:35 +00:00
|
|
|
from homeassistant.helpers import device_registry as dr
|
2023-04-13 03:23:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_device_registry_info(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
voip_devices: VoIPDevices,
|
|
|
|
call_info: CallInfo,
|
2023-05-04 09:25:35 +00:00
|
|
|
device_registry: dr.DeviceRegistry,
|
2023-04-13 03:23:20 +00:00
|
|
|
) -> None:
|
|
|
|
"""Test info in device registry."""
|
2023-04-17 02:59:05 +00:00
|
|
|
voip_device = voip_devices.async_get_or_create(call_info)
|
|
|
|
assert not voip_device.async_allow_call(hass)
|
2023-04-13 03:23:20 +00:00
|
|
|
|
2023-07-13 17:39:25 +00:00
|
|
|
device = device_registry.async_get_device(
|
|
|
|
identifiers={(DOMAIN, call_info.caller_ip)}
|
|
|
|
)
|
2023-04-13 03:23:20 +00:00
|
|
|
assert device is not None
|
|
|
|
assert device.name == call_info.caller_ip
|
|
|
|
assert device.manufacturer == "Grandstream"
|
|
|
|
assert device.model == "HT801"
|
|
|
|
assert device.sw_version == "1.0.17.5"
|
|
|
|
|
|
|
|
# Test we update the device if the fw updates
|
|
|
|
call_info.headers["user-agent"] = "Grandstream HT801 2.0.0.0"
|
2023-04-17 02:59:05 +00:00
|
|
|
voip_device = voip_devices.async_get_or_create(call_info)
|
2023-04-13 03:23:20 +00:00
|
|
|
|
2023-04-17 02:59:05 +00:00
|
|
|
assert not voip_device.async_allow_call(hass)
|
2023-04-13 03:23:20 +00:00
|
|
|
|
2023-07-13 17:39:25 +00:00
|
|
|
device = device_registry.async_get_device(
|
|
|
|
identifiers={(DOMAIN, call_info.caller_ip)}
|
|
|
|
)
|
2023-04-13 03:23:20 +00:00
|
|
|
assert device.sw_version == "2.0.0.0"
|
|
|
|
|
|
|
|
|
|
|
|
async def test_device_registry_info_from_unknown_phone(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
voip_devices: VoIPDevices,
|
|
|
|
call_info: CallInfo,
|
2023-05-04 09:25:35 +00:00
|
|
|
device_registry: dr.DeviceRegistry,
|
2023-04-13 03:23:20 +00:00
|
|
|
) -> None:
|
|
|
|
"""Test info in device registry from unknown phone."""
|
|
|
|
call_info.headers["user-agent"] = "Unknown"
|
2023-04-17 02:59:05 +00:00
|
|
|
voip_device = voip_devices.async_get_or_create(call_info)
|
|
|
|
assert not voip_device.async_allow_call(hass)
|
2023-04-13 03:23:20 +00:00
|
|
|
|
2023-07-13 17:39:25 +00:00
|
|
|
device = device_registry.async_get_device(
|
|
|
|
identifiers={(DOMAIN, call_info.caller_ip)}
|
|
|
|
)
|
2023-04-13 03:23:20 +00:00
|
|
|
assert device.manufacturer is None
|
|
|
|
assert device.model == "Unknown"
|
|
|
|
assert device.sw_version is None
|
2023-04-17 02:59:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_remove_device_registry_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
voip_device: VoIPDevice,
|
|
|
|
voip_devices: VoIPDevices,
|
2023-05-04 09:25:35 +00:00
|
|
|
device_registry: dr.DeviceRegistry,
|
2023-04-17 02:59:05 +00:00
|
|
|
) -> None:
|
|
|
|
"""Test removing a device registry entry."""
|
|
|
|
assert voip_device.voip_id in voip_devices.devices
|
|
|
|
assert hass.states.get("switch.192_168_1_210_allow_calls") is not None
|
|
|
|
|
|
|
|
device_registry.async_remove_device(voip_device.device_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert hass.states.get("switch.192_168_1_210_allow_calls") is None
|
|
|
|
assert voip_device.voip_id not in voip_devices.devices
|