Add the ability to reload homekit from yaml (#39326)

This commit is contained in:
J. Nick Koston 2020-08-28 09:46:45 -05:00 committed by GitHub
parent 400741006b
commit 414a59ae9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 182 additions and 18 deletions

View file

@ -4,6 +4,7 @@ from typing import Dict
import pytest
from homeassistant import config as hass_config
from homeassistant.components import zeroconf
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_BATTERY_CHARGING,
@ -49,6 +50,7 @@ from homeassistant.const import (
DEVICE_CLASS_HUMIDITY,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
SERVICE_RELOAD,
STATE_ON,
UNIT_PERCENTAGE,
)
@ -1181,3 +1183,69 @@ async def test_homekit_finds_linked_humidity_sensors(
"linked_humidity_sensor": "sensor.humidifier_humidity_sensor",
},
)
async def test_reload(hass):
"""Test we can reload from yaml."""
entry = MockConfigEntry(
domain=DOMAIN,
source=SOURCE_IMPORT,
data={CONF_NAME: "reloadable", CONF_PORT: 12345},
options={},
)
entry.add_to_hass(hass)
with patch(f"{PATH_HOMEKIT}.HomeKit") as mock_homekit:
mock_homekit.return_value = homekit = Mock()
type(homekit).async_start = AsyncMock()
assert await async_setup_component(
hass, "homekit", {"homekit": {CONF_NAME: "reloadable", CONF_PORT: 12345}}
)
await hass.async_block_till_done()
mock_homekit.assert_any_call(
hass,
"reloadable",
12345,
None,
ANY,
{},
DEFAULT_SAFE_MODE,
None,
entry.entry_id,
)
assert mock_homekit().setup.called is True
yaml_path = os.path.join(
_get_fixtures_base_path(),
"fixtures",
"homekit/configuration.yaml",
)
with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path), patch(
f"{PATH_HOMEKIT}.HomeKit"
) as mock_homekit2:
mock_homekit2.return_value = homekit = Mock()
type(homekit).async_start = AsyncMock()
await hass.services.async_call(
"homekit",
SERVICE_RELOAD,
{},
blocking=True,
)
await hass.async_block_till_done()
mock_homekit2.assert_any_call(
hass,
"reloadable",
45678,
None,
ANY,
{},
DEFAULT_SAFE_MODE,
None,
entry.entry_id,
)
assert mock_homekit2().setup.called is True
def _get_fixtures_base_path():
return os.path.dirname(os.path.dirname(os.path.dirname(__file__)))