Files
core/tests/helpers/test_service_info.py
Paulus Schoutsen a0f67381e5 Allow configuring Z-Wave JS to talk via ESPHome (#152590)
Co-authored-by: Artur Pragacz <49985303+arturpragacz@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
Co-authored-by: J. Nick Koston <nick@koston.org>
2025-09-23 12:58:36 +02:00

38 lines
1.2 KiB
Python

"""Test service_info helpers."""
import pytest
from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo
from homeassistant.helpers.service_info.esphome import ESPHomeServiceInfo
# Ensure that incorrectly formatted mac addresses are rejected, even
# on a constant outside of a test
try:
_ = DhcpServiceInfo(ip="", hostname="", macaddress="AA:BB:CC:DD:EE:FF")
except ValueError:
pass
else:
raise RuntimeError(
"DhcpServiceInfo incorrectly formatted mac address was not rejected. "
"Please ensure that the DhcpServiceInfo is correctly patched."
)
def test_invalid_macaddress() -> None:
"""Test that DhcpServiceInfo raises ValueError for unformatted macaddress."""
with pytest.raises(ValueError):
DhcpServiceInfo(ip="", hostname="", macaddress="AA:BB:CC:DD:EE:FF")
def test_esphome_socket_path() -> None:
"""Test ESPHomeServiceInfo socket_path property."""
info = ESPHomeServiceInfo(
name="Hello World",
zwave_home_id=123456789,
ip_address="192.168.1.100",
port=6053,
)
assert info.socket_path == "esphome://192.168.1.100:6053"
info.noise_psk = "my-noise-psk"
assert info.socket_path == "esphome://my-noise-psk@192.168.1.100:6053"