Added warning to HomeKit component (#16807)

* added warning if more then 100 devices are added to HomeKit
pull/17173/head
Julius Mittenzwei 2018-10-05 12:32:26 +02:00 committed by cdce8p
parent a8f5e8699a
commit 2e62afabdc
2 changed files with 28 additions and 6 deletions

View File

@ -28,10 +28,12 @@ from .const import (
from .util import (
show_setup_message, validate_entity_config, validate_media_player_features)
TYPES = Registry()
REQUIREMENTS = ['HAP-python==2.2.2']
_LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ['HAP-python==2.2.2']
MAX_DEVICES = 100
TYPES = Registry()
# #### Driver Status ####
STATUS_READY = 0
@ -239,6 +241,10 @@ class HomeKit():
if not self.driver.state.paired:
show_setup_message(self.hass, self.driver.state.pincode)
if len(self.bridge.accessories) > MAX_DEVICES:
_LOGGER.warning('You have exceeded the device limit, which might '
'cause issues. Consider using the filter option.')
_LOGGER.debug('Driver start')
self.hass.add_job(self.driver.start)
self.status = STATUS_RUNNING

View File

@ -5,8 +5,8 @@ import pytest
from homeassistant import setup
from homeassistant.components.homekit import (
generate_aid, HomeKit, STATUS_READY, STATUS_RUNNING,
STATUS_STOPPED, STATUS_WAIT)
generate_aid, HomeKit, MAX_DEVICES, STATUS_READY,
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,
@ -173,7 +173,8 @@ 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.bridge = 'bridge'
homekit.bridge = Mock()
homekit.bridge.accessories = []
homekit.driver = hk_driver
hass.states.async_set('light.demo', 'on')
@ -190,7 +191,7 @@ async def test_homekit_start(hass, hk_driver, debounce_patcher):
mock_add_acc.assert_called_with(state)
mock_setup_msg.assert_called_with(hass, pin)
hk_driver_add_acc.assert_called_with('bridge')
hk_driver_add_acc.assert_called_with(homekit.bridge)
assert hk_driver_start.called
assert homekit.status == STATUS_RUNNING
@ -217,3 +218,18 @@ async def test_homekit_stop(hass):
homekit.status = STATUS_RUNNING
await hass.async_add_job(homekit.stop)
assert homekit.driver.stop.called is True
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.bridge = Mock()
homekit.bridge.accessories = range(MAX_DEVICES + 1)
homekit.driver = hk_driver
with patch('pyhap.accessory_driver.AccessoryDriver.start'), \
patch('pyhap.accessory_driver.AccessoryDriver.add_accessory'), \
patch('homeassistant.components.homekit._LOGGER.warning') \
as mock_warn:
await hass.async_add_job(homekit.start)
assert mock_warn.called is True