From ef8cf9e59714fffc96b799ac952610dbe0f77969 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 28 Nov 2021 21:44:11 -1000 Subject: [PATCH] Add configuration_url to bond (#60523) --- homeassistant/components/bond/__init__.py | 3 ++- homeassistant/components/bond/config_flow.py | 2 +- homeassistant/components/bond/entity.py | 1 + homeassistant/components/bond/utils.py | 3 ++- tests/components/bond/test_fan.py | 6 +++++- tests/components/bond/test_init.py | 1 + 6 files changed, 12 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/bond/__init__.py b/homeassistant/components/bond/__init__.py index bf40d4c6066..501ddfb6888 100644 --- a/homeassistant/components/bond/__init__.py +++ b/homeassistant/components/bond/__init__.py @@ -36,7 +36,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: timeout=ClientTimeout(total=_API_TIMEOUT), session=async_get_clientsession(hass), ) - hub = BondHub(bond) + hub = BondHub(bond, host) try: await hub.setup() except ClientResponseError as ex: @@ -78,6 +78,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: model=hub.target, sw_version=hub.fw_ver, suggested_area=hub.location, + configuration_url=f"http://{host}", ) _async_remove_old_device_identifiers(config_entry_id, device_registry, hub) diff --git a/homeassistant/components/bond/config_flow.py b/homeassistant/components/bond/config_flow.py index d9398edf2c9..cca8930532d 100644 --- a/homeassistant/components/bond/config_flow.py +++ b/homeassistant/components/bond/config_flow.py @@ -47,7 +47,7 @@ async def _validate_input(hass: HomeAssistant, data: dict[str, Any]) -> tuple[st data[CONF_HOST], data[CONF_ACCESS_TOKEN], session=async_get_clientsession(hass) ) try: - hub = BondHub(bond) + hub = BondHub(bond, data[CONF_HOST]) await hub.setup(max_devices=1) except ClientConnectionError as error: raise InputValidationError("cannot_connect") from error diff --git a/homeassistant/components/bond/entity.py b/homeassistant/components/bond/entity.py index 5f37de4fa19..342e407ff48 100644 --- a/homeassistant/components/bond/entity.py +++ b/homeassistant/components/bond/entity.py @@ -65,6 +65,7 @@ class BondEntity(Entity): manufacturer=self._hub.make, # type ignore: tuple items should not be Optional identifiers={(DOMAIN, self._hub.bond_id, self._device.device_id)}, # type: ignore[arg-type] + configuration_url=f"http://{self._hub.host}", ) if self.name is not None: device_info[ATTR_NAME] = self.name diff --git a/homeassistant/components/bond/utils.py b/homeassistant/components/bond/utils.py index abe3cc98002..b9dbe07ea50 100644 --- a/homeassistant/components/bond/utils.py +++ b/homeassistant/components/bond/utils.py @@ -124,9 +124,10 @@ class BondDevice: class BondHub: """Hub device representing Bond Bridge.""" - def __init__(self, bond: Bond) -> None: + def __init__(self, bond: Bond, host: str) -> None: """Initialize Bond Hub.""" self.bond: Bond = bond + self.host = host self._bridge: dict[str, Any] = {} self._version: dict[str, Any] = {} self._devices: list[BondDevice] = [] diff --git a/tests/components/bond/test_fan.py b/tests/components/bond/test_fan.py index d24128617d2..0c58596bb7f 100644 --- a/tests/components/bond/test_fan.py +++ b/tests/components/bond/test_fan.py @@ -25,7 +25,7 @@ from homeassistant.components.fan import ( ) from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers import entity_registry as er +from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers.entity_registry import EntityRegistry from homeassistant.util import utcnow @@ -84,6 +84,10 @@ async def test_entity_registry(hass: core.HomeAssistant): entity = registry.entities["fan.name_1"] assert entity.unique_id == "test-hub-id_test-device-id" + device_registry = dr.async_get(hass) + device = device_registry.async_get(entity.device_id) + assert device.configuration_url == "http://some host" + async def test_non_standard_speed_list(hass: core.HomeAssistant): """Tests that the device is registered with custom speed list if number of supported speeds differs form 3.""" diff --git a/tests/components/bond/test_init.py b/tests/components/bond/test_init.py index 42eca44dfa7..db54ffdf716 100644 --- a/tests/components/bond/test_init.py +++ b/tests/components/bond/test_init.py @@ -107,6 +107,7 @@ async def test_async_setup_entry_sets_up_hub_and_supported_domains(hass: HomeAss assert hub.manufacturer == "Olibra" assert hub.model == "test-model" assert hub.sw_version == "test-version" + assert hub.configuration_url == "http://some host" # verify supported domains are setup assert len(mock_cover_async_setup_entry.mock_calls) == 1