Add Bond hub as a device for bond entities (#37772)

* Introduce Bond Hub concept

* Read Hub version information when setting up entry

* Link entities to Hub using via_device

* Add test to verify created Hub device properties
This commit is contained in:
Eugene Prystupa 2020-07-12 12:31:53 -04:00 committed by GitHub
parent 6826a8829c
commit c6ab2c5d0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 136 additions and 50 deletions

View file

@ -3,8 +3,11 @@ from homeassistant.components.bond.const import DOMAIN
from homeassistant.config_entries import ENTRY_STATE_LOADED, ENTRY_STATE_NOT_LOADED
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.setup import async_setup_component
from .common import setup_bond_entity
from tests.async_mock import patch
from tests.common import MockConfigEntry
@ -16,22 +19,45 @@ async def test_async_setup_no_domain_config(hass: HomeAssistant):
assert result is True
async def test_async_setup_entry_sets_up_supported_domains(hass: HomeAssistant):
async def test_async_setup_entry_sets_up_hub_and_supported_domains(hass: HomeAssistant):
"""Test that configuring entry sets up cover domain."""
config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_HOST: "1.1.1.1", CONF_ACCESS_TOKEN: "test-token"},
)
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.bond.cover.async_setup_entry"
) as mock_cover_async_setup_entry:
result = await hass.config_entries.async_setup(config_entry.entry_id)
) as mock_cover_async_setup_entry, patch(
"homeassistant.components.bond.fan.async_setup_entry"
) as mock_fan_async_setup_entry:
result = await setup_bond_entity(
hass,
config_entry,
hub_version={
"bondid": "test-bond-id",
"target": "test-model",
"fw_ver": "test-version",
},
)
assert result is True
await hass.async_block_till_done()
assert config_entry.entry_id in hass.data[DOMAIN]
assert config_entry.state == ENTRY_STATE_LOADED
# verify hub device is registered correctly
device_registry = await dr.async_get_registry(hass)
hub = device_registry.async_get_device(
identifiers={(DOMAIN, "test-bond-id")}, connections=set()
)
assert hub.name == "test-bond-id"
assert hub.manufacturer == "Olibra"
assert hub.model == "test-model"
assert hub.sw_version == "test-version"
# verify supported domains are setup
assert len(mock_cover_async_setup_entry.mock_calls) == 1
assert len(mock_fan_async_setup_entry.mock_calls) == 1
async def test_unload_config_entry(hass: HomeAssistant):
@ -39,15 +65,13 @@ async def test_unload_config_entry(hass: HomeAssistant):
config_entry = MockConfigEntry(
domain=DOMAIN, data={CONF_HOST: "1.1.1.1", CONF_ACCESS_TOKEN: "test-token"},
)
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.bond.cover.async_setup_entry", return_value=True
with patch("homeassistant.components.bond.cover.async_setup_entry"), patch(
"homeassistant.components.bond.fan.async_setup_entry"
):
result = await hass.config_entries.async_setup(config_entry.entry_id)
result = await setup_bond_entity(hass, config_entry)
assert result is True
await hass.async_block_till_done()
assert config_entry.entry_id in hass.data[DOMAIN]
assert config_entry.state == ENTRY_STATE_LOADED
await hass.config_entries.async_unload(config_entry.entry_id)
await hass.async_block_till_done()