2020-07-06 01:17:53 +00:00
|
|
|
"""Common methods used across tests for Bond."""
|
2020-07-11 01:20:50 +00:00
|
|
|
from typing import Any, Dict
|
|
|
|
|
|
|
|
from homeassistant import core
|
2020-07-06 01:17:53 +00:00
|
|
|
from homeassistant.components.bond.const import DOMAIN as BOND_DOMAIN
|
|
|
|
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST
|
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
|
|
from tests.async_mock import patch
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
2020-07-12 16:31:53 +00:00
|
|
|
MOCK_HUB_VERSION: dict = {"bondid": "test-bond-id"}
|
|
|
|
|
|
|
|
|
|
|
|
async def setup_bond_entity(
|
|
|
|
hass: core.HomeAssistant, config_entry: MockConfigEntry, hub_version=None
|
|
|
|
):
|
|
|
|
"""Set up Bond entity."""
|
|
|
|
if hub_version is None:
|
|
|
|
hub_version = MOCK_HUB_VERSION
|
|
|
|
|
|
|
|
config_entry.add_to_hass(hass)
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.bond.Bond.getVersion", return_value=hub_version
|
|
|
|
):
|
|
|
|
return await hass.config_entries.async_setup(config_entry.entry_id)
|
|
|
|
|
2020-07-06 01:17:53 +00:00
|
|
|
|
2020-07-11 01:20:50 +00:00
|
|
|
async def setup_platform(
|
|
|
|
hass: core.HomeAssistant, platform: str, discovered_device: Dict[str, Any]
|
|
|
|
):
|
2020-07-06 01:17:53 +00:00
|
|
|
"""Set up the specified Bond platform."""
|
|
|
|
mock_entry = MockConfigEntry(
|
|
|
|
domain=BOND_DOMAIN,
|
|
|
|
data={CONF_HOST: "1.1.1.1", CONF_ACCESS_TOKEN: "test-token"},
|
|
|
|
)
|
|
|
|
mock_entry.add_to_hass(hass)
|
|
|
|
|
2020-07-11 01:20:50 +00:00
|
|
|
with patch("homeassistant.components.bond.PLATFORMS", [platform]), patch(
|
2020-07-12 16:31:53 +00:00
|
|
|
"homeassistant.components.bond.Bond.getVersion", return_value=MOCK_HUB_VERSION
|
|
|
|
), patch(
|
2020-07-11 01:20:50 +00:00
|
|
|
"homeassistant.components.bond.Bond.getDeviceIds",
|
|
|
|
return_value=["bond-device-id"],
|
|
|
|
), patch(
|
|
|
|
"homeassistant.components.bond.Bond.getDevice", return_value=discovered_device
|
|
|
|
), patch(
|
|
|
|
"homeassistant.components.bond.Bond.getDeviceState", return_value={}
|
|
|
|
):
|
2020-07-06 01:17:53 +00:00
|
|
|
assert await async_setup_component(hass, BOND_DOMAIN, {})
|
2020-07-11 01:20:50 +00:00
|
|
|
await hass.async_block_till_done()
|
2020-07-06 01:17:53 +00:00
|
|
|
|
|
|
|
return mock_entry
|