Add configuration_url to bond (#60523)

This commit is contained in:
J. Nick Koston 2021-11-28 21:44:11 -10:00 committed by GitHub
parent 15bf4dae9b
commit ef8cf9e597
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 4 deletions

View File

@ -36,7 +36,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
timeout=ClientTimeout(total=_API_TIMEOUT), timeout=ClientTimeout(total=_API_TIMEOUT),
session=async_get_clientsession(hass), session=async_get_clientsession(hass),
) )
hub = BondHub(bond) hub = BondHub(bond, host)
try: try:
await hub.setup() await hub.setup()
except ClientResponseError as ex: except ClientResponseError as ex:
@ -78,6 +78,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
model=hub.target, model=hub.target,
sw_version=hub.fw_ver, sw_version=hub.fw_ver,
suggested_area=hub.location, suggested_area=hub.location,
configuration_url=f"http://{host}",
) )
_async_remove_old_device_identifiers(config_entry_id, device_registry, hub) _async_remove_old_device_identifiers(config_entry_id, device_registry, hub)

View File

@ -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) data[CONF_HOST], data[CONF_ACCESS_TOKEN], session=async_get_clientsession(hass)
) )
try: try:
hub = BondHub(bond) hub = BondHub(bond, data[CONF_HOST])
await hub.setup(max_devices=1) await hub.setup(max_devices=1)
except ClientConnectionError as error: except ClientConnectionError as error:
raise InputValidationError("cannot_connect") from error raise InputValidationError("cannot_connect") from error

View File

@ -65,6 +65,7 @@ class BondEntity(Entity):
manufacturer=self._hub.make, manufacturer=self._hub.make,
# type ignore: tuple items should not be Optional # type ignore: tuple items should not be Optional
identifiers={(DOMAIN, self._hub.bond_id, self._device.device_id)}, # type: ignore[arg-type] 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: if self.name is not None:
device_info[ATTR_NAME] = self.name device_info[ATTR_NAME] = self.name

View File

@ -124,9 +124,10 @@ class BondDevice:
class BondHub: class BondHub:
"""Hub device representing Bond Bridge.""" """Hub device representing Bond Bridge."""
def __init__(self, bond: Bond) -> None: def __init__(self, bond: Bond, host: str) -> None:
"""Initialize Bond Hub.""" """Initialize Bond Hub."""
self.bond: Bond = bond self.bond: Bond = bond
self.host = host
self._bridge: dict[str, Any] = {} self._bridge: dict[str, Any] = {}
self._version: dict[str, Any] = {} self._version: dict[str, Any] = {}
self._devices: list[BondDevice] = [] self._devices: list[BondDevice] = []

View File

@ -25,7 +25,7 @@ from homeassistant.components.fan import (
) )
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
from homeassistant.exceptions import HomeAssistantError 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.helpers.entity_registry import EntityRegistry
from homeassistant.util import utcnow from homeassistant.util import utcnow
@ -84,6 +84,10 @@ async def test_entity_registry(hass: core.HomeAssistant):
entity = registry.entities["fan.name_1"] entity = registry.entities["fan.name_1"]
assert entity.unique_id == "test-hub-id_test-device-id" 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): 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.""" """Tests that the device is registered with custom speed list if number of supported speeds differs form 3."""

View File

@ -107,6 +107,7 @@ async def test_async_setup_entry_sets_up_hub_and_supported_domains(hass: HomeAss
assert hub.manufacturer == "Olibra" assert hub.manufacturer == "Olibra"
assert hub.model == "test-model" assert hub.model == "test-model"
assert hub.sw_version == "test-version" assert hub.sw_version == "test-version"
assert hub.configuration_url == "http://some host"
# verify supported domains are setup # verify supported domains are setup
assert len(mock_cover_async_setup_entry.mock_calls) == 1 assert len(mock_cover_async_setup_entry.mock_calls) == 1