If no Reolink HTTP api available, do not set configuration_url (#146684)

* If no http api available, do not set configuration_url

* Add tests
This commit is contained in:
starkillerOG 2025-06-18 09:16:08 +02:00 committed by GitHub
parent ba2aac4614
commit 07110e288d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View File

@ -75,6 +75,9 @@ class ReolinkHostCoordinatorEntity(CoordinatorEntity[DataUpdateCoordinator[None]
)
http_s = "https" if self._host.api.use_https else "http"
if self._host.api.baichuan_only:
self._conf_url = None
else:
self._conf_url = f"{http_s}://{self._host.api.host}:{self._host.api.port}"
self._dev_id = self._host.unique_id
self._attr_device_info = DeviceInfo(
@ -184,6 +187,11 @@ class ReolinkChannelCoordinatorEntity(ReolinkHostCoordinatorEntity):
if mac := self._host.api.baichuan.mac_address(dev_ch):
connections.add((CONNECTION_NETWORK_MAC, mac))
if self._conf_url is None:
conf_url = None
else:
conf_url = f"{self._conf_url}/?ch={dev_ch}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self._dev_id)},
connections=connections,
@ -195,7 +203,7 @@ class ReolinkChannelCoordinatorEntity(ReolinkHostCoordinatorEntity):
hw_version=self._host.api.camera_hardware_version(dev_ch),
sw_version=self._host.api.camera_sw_version(dev_ch),
serial_number=self._host.api.camera_uid(dev_ch),
configuration_url=f"{self._conf_url}/?ch={dev_ch}",
configuration_url=conf_url,
)
@property

View File

@ -1186,6 +1186,19 @@ async def test_camera_wake_callback(
assert hass.states.get(entity_id).state == STATE_OFF
async def test_baichaun_only(
hass: HomeAssistant,
reolink_connect: MagicMock,
config_entry: MockConfigEntry,
) -> None:
"""Test initializing a baichuan only device."""
reolink_connect.baichuan_only = True
with patch("homeassistant.components.reolink.PLATFORMS", [Platform.SWITCH]):
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
async def test_remove(
hass: HomeAssistant,
reolink_connect: MagicMock,