From 07110e288dfd44e9fceb795f283e5ab8b8d32438 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Wed, 18 Jun 2025 09:16:08 +0200 Subject: [PATCH] If no Reolink HTTP api available, do not set configuration_url (#146684) * If no http api available, do not set configuration_url * Add tests --- homeassistant/components/reolink/entity.py | 12 ++++++++++-- tests/components/reolink/test_init.py | 13 +++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/reolink/entity.py b/homeassistant/components/reolink/entity.py index 2e0f1ac9e6a..467472fef9c 100644 --- a/homeassistant/components/reolink/entity.py +++ b/homeassistant/components/reolink/entity.py @@ -75,7 +75,10 @@ class ReolinkHostCoordinatorEntity(CoordinatorEntity[DataUpdateCoordinator[None] ) http_s = "https" if self._host.api.use_https else "http" - self._conf_url = f"{http_s}://{self._host.api.host}:{self._host.api.port}" + 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( identifiers={(DOMAIN, self._dev_id)}, @@ -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 diff --git a/tests/components/reolink/test_init.py b/tests/components/reolink/test_init.py index 86c4ed861a1..482928560b9 100644 --- a/tests/components/reolink/test_init.py +++ b/tests/components/reolink/test_init.py @@ -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,