1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Add safe_mode HomeKit (#18356)

* Use: 'safe_mode: True' in case of pairing issues
This commit is contained in:
cdce8p
2018-11-16 11:08:39 +01:00
committed by GitHub
parent b7b8296c73
commit ed7aea006a
3 changed files with 39 additions and 15 deletions

View File

@@ -9,8 +9,8 @@ from homeassistant.components.homekit import (
STATUS_RUNNING, STATUS_STOPPED, STATUS_WAIT)
from homeassistant.components.homekit.accessories import HomeBridge
from homeassistant.components.homekit.const import (
CONF_AUTO_START, BRIDGE_NAME, DEFAULT_PORT, DOMAIN, HOMEKIT_FILE,
SERVICE_HOMEKIT_START)
CONF_AUTO_START, CONF_SAFE_MODE, BRIDGE_NAME, DEFAULT_PORT,
DEFAULT_SAFE_MODE, DOMAIN, HOMEKIT_FILE, SERVICE_HOMEKIT_START)
from homeassistant.const import (
CONF_NAME, CONF_IP_ADDRESS, CONF_PORT,
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP)
@@ -49,7 +49,7 @@ async def test_setup_min(hass):
hass, DOMAIN, {DOMAIN: {}})
mock_homekit.assert_any_call(hass, BRIDGE_NAME, DEFAULT_PORT, None, ANY,
{})
{}, DEFAULT_SAFE_MODE)
assert mock_homekit().setup.called is True
# Test auto start enabled
@@ -63,7 +63,8 @@ async def test_setup_min(hass):
async def test_setup_auto_start_disabled(hass):
"""Test async_setup with auto start disabled and test service calls."""
config = {DOMAIN: {CONF_AUTO_START: False, CONF_NAME: 'Test Name',
CONF_PORT: 11111, CONF_IP_ADDRESS: '172.0.0.0'}}
CONF_PORT: 11111, CONF_IP_ADDRESS: '172.0.0.0',
CONF_SAFE_MODE: DEFAULT_SAFE_MODE}}
with patch(PATH_HOMEKIT + '.HomeKit') as mock_homekit:
mock_homekit.return_value = homekit = Mock()
@@ -71,7 +72,7 @@ async def test_setup_auto_start_disabled(hass):
hass, DOMAIN, config)
mock_homekit.assert_any_call(hass, 'Test Name', 11111, '172.0.0.0', ANY,
{})
{}, DEFAULT_SAFE_MODE)
assert mock_homekit().setup.called is True
# Test auto_start disabled
@@ -99,7 +100,8 @@ async def test_setup_auto_start_disabled(hass):
async def test_homekit_setup(hass, hk_driver):
"""Test setup of bridge and driver."""
homekit = HomeKit(hass, BRIDGE_NAME, DEFAULT_PORT, None, {}, {})
homekit = HomeKit(hass, BRIDGE_NAME, DEFAULT_PORT, None, {}, {},
DEFAULT_SAFE_MODE)
with patch(PATH_HOMEKIT + '.accessories.HomeDriver',
return_value=hk_driver) as mock_driver, \
@@ -111,6 +113,7 @@ async def test_homekit_setup(hass, hk_driver):
assert isinstance(homekit.bridge, HomeBridge)
mock_driver.assert_called_with(
hass, address=IP_ADDRESS, port=DEFAULT_PORT, persist_file=path)
assert homekit.driver.safe_mode is False
# Test if stop listener is setup
assert hass.bus.async_listeners().get(EVENT_HOMEASSISTANT_STOP) == 1
@@ -118,7 +121,8 @@ async def test_homekit_setup(hass, hk_driver):
async def test_homekit_setup_ip_address(hass, hk_driver):
"""Test setup with given IP address."""
homekit = HomeKit(hass, BRIDGE_NAME, DEFAULT_PORT, '172.0.0.0', {}, {})
homekit = HomeKit(hass, BRIDGE_NAME, DEFAULT_PORT, '172.0.0.0', {}, {},
None)
with patch(PATH_HOMEKIT + '.accessories.HomeDriver',
return_value=hk_driver) as mock_driver:
@@ -127,9 +131,20 @@ async def test_homekit_setup_ip_address(hass, hk_driver):
hass, address='172.0.0.0', port=DEFAULT_PORT, persist_file=ANY)
async def test_homekit_setup_safe_mode(hass, hk_driver):
"""Test if safe_mode flag is set."""
homekit = HomeKit(hass, BRIDGE_NAME, DEFAULT_PORT, None, {}, {}, True)
with patch(PATH_HOMEKIT + '.accessories.HomeDriver',
return_value=hk_driver):
await hass.async_add_job(homekit.setup)
assert homekit.driver.safe_mode is True
async def test_homekit_add_accessory():
"""Add accessory if config exists and get_acc returns an accessory."""
homekit = HomeKit('hass', None, None, None, lambda entity_id: True, {})
homekit = HomeKit('hass', None, None, None, lambda entity_id: True, {},
None)
homekit.driver = 'driver'
homekit.bridge = mock_bridge = Mock()
@@ -152,7 +167,7 @@ async def test_homekit_add_accessory():
async def test_homekit_entity_filter(hass):
"""Test the entity filter."""
entity_filter = generate_filter(['cover'], ['demo.test'], [], [])
homekit = HomeKit(hass, None, None, None, entity_filter, {})
homekit = HomeKit(hass, None, None, None, entity_filter, {}, None)
with patch(PATH_HOMEKIT + '.get_accessory') as mock_get_acc:
mock_get_acc.return_value = None
@@ -172,7 +187,7 @@ async def test_homekit_entity_filter(hass):
async def test_homekit_start(hass, hk_driver, debounce_patcher):
"""Test HomeKit start method."""
pin = b'123-45-678'
homekit = HomeKit(hass, None, None, None, {}, {'cover.demo': {}})
homekit = HomeKit(hass, None, None, None, {}, {'cover.demo': {}}, None)
homekit.bridge = Mock()
homekit.bridge.accessories = []
homekit.driver = hk_driver
@@ -203,7 +218,7 @@ async def test_homekit_start(hass, hk_driver, debounce_patcher):
async def test_homekit_stop(hass):
"""Test HomeKit stop method."""
homekit = HomeKit(hass, None, None, None, None, None)
homekit = HomeKit(hass, None, None, None, None, None, None)
homekit.driver = Mock()
assert homekit.status == STATUS_READY
@@ -222,7 +237,7 @@ async def test_homekit_stop(hass):
async def test_homekit_too_many_accessories(hass, hk_driver):
"""Test adding too many accessories to HomeKit."""
homekit = HomeKit(hass, None, None, None, None, None)
homekit = HomeKit(hass, None, None, None, None, None, None)
homekit.bridge = Mock()
homekit.bridge.accessories = range(MAX_DEVICES + 1)
homekit.driver = hk_driver