diff --git a/homeassistant/components/homekit/__init__.py b/homeassistant/components/homekit/__init__.py index a79fbf85400b277ab3003ca7e2a80eba8a449e5b..ce3b79e6c72236f4118098d1cc9e2e8532b39415 100644 --- a/homeassistant/components/homekit/__init__.py +++ b/homeassistant/components/homekit/__init__.py @@ -30,7 +30,7 @@ from .util import ( TYPES = Registry() _LOGGER = logging.getLogger(__name__) -REQUIREMENTS = ['HAP-python==2.1.0'] +REQUIREMENTS = ['HAP-python==2.2.2'] # #### Driver Status #### STATUS_READY = 0 @@ -84,7 +84,7 @@ async def async_setup(hass, config): return True -def get_accessory(hass, state, aid, config): +def get_accessory(hass, driver, state, aid, config): """Take state and return an accessory object if supported.""" if not aid: _LOGGER.warning('The entitiy "%s" is not supported, since it ' @@ -157,7 +157,7 @@ def get_accessory(hass, state, aid, config): return None _LOGGER.debug('Add "%s" as "%s"', state.entity_id, a_type) - return TYPES[a_type](hass, name, state.entity_id, aid, config) + return TYPES[a_type](hass, driver, name, state.entity_id, aid, config) def generate_aid(entity_id): @@ -192,9 +192,9 @@ class HomeKit(): ip_addr = self._ip_address or get_local_ip() path = self.hass.config.path(HOMEKIT_FILE) - self.bridge = HomeBridge(self.hass) - self.driver = HomeDriver(self.hass, self.bridge, port=self._port, - address=ip_addr, persist_file=path) + self.driver = HomeDriver(self.hass, address=ip_addr, + port=self._port, persist_file=path) + self.bridge = HomeBridge(self.hass, self.driver) def add_bridge_accessory(self, state): """Try adding accessory to bridge if configured beforehand.""" @@ -202,7 +202,7 @@ class HomeKit(): return aid = generate_aid(state.entity_id) conf = self._config.pop(state.entity_id, {}) - acc = get_accessory(self.hass, state, aid, conf) + acc = get_accessory(self.hass, self.driver, state, aid, conf) if acc is not None: self.bridge.add_accessory(acc) @@ -220,7 +220,7 @@ class HomeKit(): for state in self.hass.states.all(): self.add_bridge_accessory(state) - self.bridge.set_driver(self.driver) + self.driver.add_accessory(self.bridge) if not self.driver.state.paired: show_setup_message(self.hass, self.driver.state.pincode) diff --git a/homeassistant/components/homekit/accessories.py b/homeassistant/components/homekit/accessories.py index ded4526b0086aa8d0c8f8e94cd203ffb90e67ce6..711bf0030f00693b91fde058ad707c0a8c887a73 100644 --- a/homeassistant/components/homekit/accessories.py +++ b/homeassistant/components/homekit/accessories.py @@ -64,10 +64,10 @@ def debounce(func): class HomeAccessory(Accessory): """Adapter class for Accessory.""" - def __init__(self, hass, name, entity_id, aid, config, + def __init__(self, hass, driver, name, entity_id, aid, config, category=CATEGORY_OTHER): """Initialize a Accessory object.""" - super().__init__(name, aid=aid) + super().__init__(driver, name, aid=aid) model = split_entity_id(entity_id)[0].replace("_", " ").title() self.set_info_service( firmware_revision=__version__, manufacturer=MANUFACTURER, @@ -104,9 +104,9 @@ class HomeAccessory(Accessory): class HomeBridge(Bridge): """Adapter class for Bridge.""" - def __init__(self, hass, name=BRIDGE_NAME): + def __init__(self, hass, driver, name=BRIDGE_NAME): """Initialize a Bridge object.""" - super().__init__(name) + super().__init__(driver, name) self.set_info_service( firmware_revision=__version__, manufacturer=MANUFACTURER, model=BRIDGE_MODEL, serial_number=BRIDGE_SERIAL_NUMBER) @@ -120,9 +120,9 @@ class HomeBridge(Bridge): class HomeDriver(AccessoryDriver): """Adapter class for AccessoryDriver.""" - def __init__(self, hass, *args, **kwargs): + def __init__(self, hass, **kwargs): """Initialize a AccessoryDriver object.""" - super().__init__(*args, **kwargs) + super().__init__(**kwargs) self.hass = hass def pair(self, client_uuid, client_public): diff --git a/homeassistant/components/homekit/type_switches.py b/homeassistant/components/homekit/type_switches.py index 5754266587c46c973a9321f8fec93e9ae6247728..69f14821bd67ed27942a9f7b367b1cdddada43f4 100644 --- a/homeassistant/components/homekit/type_switches.py +++ b/homeassistant/components/homekit/type_switches.py @@ -19,7 +19,7 @@ class Switch(HomeAccessory): """Generate a Switch accessory.""" def __init__(self, *args): - """Initialize a Switch accessory object to represent a remote.""" + """Initialize a Switch accessory object.""" super().__init__(*args, category=CATEGORY_SWITCH) self._domain = split_entity_id(self.entity_id)[0] self.flag_target_state = False diff --git a/requirements_all.txt b/requirements_all.txt index 1b1db52daef34ffd911ef5639dfc87ee4314f687..3a190a29ed8b64c9d68bd4969d2ad4695e77fb09 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -28,7 +28,7 @@ Adafruit-SHT31==1.0.2 DoorBirdPy==0.1.3 # homeassistant.components.homekit -HAP-python==2.1.0 +HAP-python==2.2.2 # homeassistant.components.notify.mastodon Mastodon.py==1.2.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index adcba607db01cab1d86296ab6ad3039fd0b9444a..56b7eec6c5eb4a12ac6b5100cba59e0c2eced997 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -19,7 +19,7 @@ requests_mock==1.5 # homeassistant.components.homekit -HAP-python==2.1.0 +HAP-python==2.2.2 # homeassistant.components.notify.html5 PyJWT==1.6.0 diff --git a/tests/components/homekit/conftest.py b/tests/components/homekit/conftest.py new file mode 100644 index 0000000000000000000000000000000000000000..f783926593950fdbea1dd69a65b5fb7993b350e0 --- /dev/null +++ b/tests/components/homekit/conftest.py @@ -0,0 +1,16 @@ +"""HomeKit session fixtures.""" +from unittest.mock import patch + +import pytest + +from pyhap.accessory_driver import AccessoryDriver + + +@pytest.fixture(scope='session') +def hk_driver(): + """Return a custom AccessoryDriver instance for HomeKit accessory init.""" + with patch('pyhap.accessory_driver.Zeroconf'), \ + patch('pyhap.accessory_driver.AccessoryEncoder'), \ + patch('pyhap.accessory_driver.HAPServer'), \ + patch('pyhap.accessory_driver.AccessoryDriver.publish'): + return AccessoryDriver(pincode=b'123-45-678') diff --git a/tests/components/homekit/test_accessories.py b/tests/components/homekit/test_accessories.py index 3d1c335f8ae5e2c37355245c1aabeb5bd2add893..a0764d580000e930cc5195ca2f11fde387478278 100644 --- a/tests/components/homekit/test_accessories.py +++ b/tests/components/homekit/test_accessories.py @@ -50,13 +50,14 @@ async def test_debounce(hass): assert counter == 2 -async def test_home_accessory(hass): +async def test_home_accessory(hass, hk_driver): """Test HomeAccessory class.""" entity_id = 'homekit.accessory' hass.states.async_set(entity_id, None) await hass.async_block_till_done() - acc = HomeAccessory(hass, 'Home Accessory', entity_id, 2, None) + acc = HomeAccessory(hass, hk_driver, 'Home Accessory', + entity_id, 2, None) assert acc.hass == hass assert acc.display_name == 'Home Accessory' assert acc.aid == 2 @@ -86,14 +87,15 @@ async def test_home_accessory(hass): acc.update_state('new_state') # Test model name from domain - acc = HomeAccessory('hass', 'test_name', 'test_model.demo', 2, None) + entity_id = 'test_model.demo' + acc = HomeAccessory('hass', hk_driver, 'test_name', entity_id, 2, None) serv = acc.services[0] # SERV_ACCESSORY_INFO assert serv.get_characteristic(CHAR_MODEL).value == 'Test Model' -def test_home_bridge(): +def test_home_bridge(hk_driver): """Test HomeBridge class.""" - bridge = HomeBridge('hass') + bridge = HomeBridge('hass', hk_driver) assert bridge.hass == 'hass' assert bridge.display_name == BRIDGE_NAME assert bridge.category == 2 # Category.BRIDGE @@ -107,7 +109,7 @@ def test_home_bridge(): assert serv.get_characteristic(CHAR_SERIAL_NUMBER).value == \ BRIDGE_SERIAL_NUMBER - bridge = HomeBridge('hass', 'test_name') + bridge = HomeBridge('hass', hk_driver, 'test_name') assert bridge.display_name == 'test_name' assert len(bridge.services) == 1 serv = bridge.services[0] # SERV_ACCESSORY_INFO @@ -118,7 +120,6 @@ def test_home_bridge(): def test_home_driver(): """Test HomeDriver class.""" - bridge = HomeBridge('hass') ip_address = '127.0.0.1' port = 51826 path = '.homekit.state' @@ -126,9 +127,11 @@ def test_home_driver(): with patch('pyhap.accessory_driver.AccessoryDriver.__init__') \ as mock_driver: - driver = HomeDriver('hass', bridge, ip_address, port, path) + driver = HomeDriver('hass', address=ip_address, port=port, + persist_file=path) - mock_driver.assert_called_with(bridge, ip_address, port, path) + mock_driver.assert_called_with(address=ip_address, port=port, + persist_file=path) driver.state = Mock(pincode=pin) # pair diff --git a/tests/components/homekit/test_get_accessories.py b/tests/components/homekit/test_get_accessories.py index 46e5f8b117411b67b05da22afc45cc38a0f9bdcc..3b7f307fce712a2d1f2917c074eb15ce8e0b9926 100644 --- a/tests/components/homekit/test_get_accessories.py +++ b/tests/components/homekit/test_get_accessories.py @@ -18,10 +18,12 @@ from homeassistant.const import ( def test_not_supported(caplog): """Test if none is returned if entity isn't supported.""" # not supported entity - assert get_accessory(None, State('demo.demo', 'on'), 2, {}) is None + assert get_accessory(None, None, State('demo.demo', 'on'), 2, {}) \ + is None # invalid aid - assert get_accessory(None, State('light.demo', 'on'), None, None) is None + assert get_accessory(None, None, State('light.demo', 'on'), None, None) \ + is None assert caplog.records[0].levelname == 'WARNING' assert 'invalid aid' in caplog.records[0].msg @@ -31,11 +33,11 @@ def test_not_supported_media_player(): # selected mode for entity not supported config = {CONF_FEATURE_LIST: {FEATURE_ON_OFF: None}} entity_state = State('media_player.demo', 'on') - get_accessory(None, entity_state, 2, config) is None + get_accessory(None, None, entity_state, 2, config) is None # no supported modes for entity entity_state = State('media_player.demo', 'on') - assert get_accessory(None, entity_state, 2, {}) is None + assert get_accessory(None, None, entity_state, 2, {}) is None @pytest.mark.parametrize('config, name', [ @@ -46,8 +48,9 @@ def test_customize_options(config, name): mock_type = Mock() with patch.dict(TYPES, {'Light': mock_type}): entity_state = State('light.demo', 'on') - get_accessory(None, entity_state, 2, config) - mock_type.assert_called_with(None, name, 'light.demo', 2, config) + get_accessory(None, None, entity_state, 2, config) + mock_type.assert_called_with(None, None, name, + 'light.demo', 2, config) @pytest.mark.parametrize('type_name, entity_id, state, attrs, config', [ @@ -70,7 +73,7 @@ def test_types(type_name, entity_id, state, attrs, config): mock_type = Mock() with patch.dict(TYPES, {type_name: mock_type}): entity_state = State(entity_id, state, attrs) - get_accessory(None, entity_state, 2, config) + get_accessory(None, None, entity_state, 2, config) assert mock_type.called if config: @@ -91,7 +94,7 @@ def test_type_covers(type_name, entity_id, state, attrs): mock_type = Mock() with patch.dict(TYPES, {type_name: mock_type}): entity_state = State(entity_id, state, attrs) - get_accessory(None, entity_state, 2, {}) + get_accessory(None, None, entity_state, 2, {}) assert mock_type.called @@ -122,7 +125,7 @@ def test_type_sensors(type_name, entity_id, state, attrs): mock_type = Mock() with patch.dict(TYPES, {type_name: mock_type}): entity_state = State(entity_id, state, attrs) - get_accessory(None, entity_state, 2, {}) + get_accessory(None, None, entity_state, 2, {}) assert mock_type.called @@ -138,5 +141,5 @@ def test_type_switches(type_name, entity_id, state, attrs): mock_type = Mock() with patch.dict(TYPES, {type_name: mock_type}): entity_state = State(entity_id, state, attrs) - get_accessory(None, entity_state, 2, {}) + get_accessory(None, None, entity_state, 2, {}) assert mock_type.called diff --git a/tests/components/homekit/test_homekit.py b/tests/components/homekit/test_homekit.py index 31337088b33f3d1c77cf5c4b488b59d166b06a49..08e8da7857ea28b4ab87fd4c43993d437c4b6047 100644 --- a/tests/components/homekit/test_homekit.py +++ b/tests/components/homekit/test_homekit.py @@ -94,11 +94,12 @@ async def test_setup_auto_start_disabled(hass): assert homekit.start.called is False -async def test_homekit_setup(hass): +async def test_homekit_setup(hass, hk_driver): """Test setup of bridge and driver.""" homekit = HomeKit(hass, DEFAULT_PORT, None, {}, {}) - with patch(PATH_HOMEKIT + '.accessories.HomeDriver') as mock_driver, \ + with patch(PATH_HOMEKIT + '.accessories.HomeDriver', + return_value=hk_driver) as mock_driver, \ patch('homeassistant.util.get_local_ip') as mock_ip: mock_ip.return_value = IP_ADDRESS await hass.async_add_job(homekit.setup) @@ -106,41 +107,42 @@ async def test_homekit_setup(hass): path = hass.config.path(HOMEKIT_FILE) assert isinstance(homekit.bridge, HomeBridge) mock_driver.assert_called_with( - hass, homekit.bridge, port=DEFAULT_PORT, - address=IP_ADDRESS, persist_file=path) + hass, address=IP_ADDRESS, port=DEFAULT_PORT, persist_file=path) # Test if stop listener is setup assert hass.bus.async_listeners().get(EVENT_HOMEASSISTANT_STOP) == 1 -async def test_homekit_setup_ip_address(hass): +async def test_homekit_setup_ip_address(hass, hk_driver): """Test setup with given IP address.""" homekit = HomeKit(hass, DEFAULT_PORT, '172.0.0.0', {}, {}) - with patch(PATH_HOMEKIT + '.accessories.HomeDriver') as mock_driver: + with patch(PATH_HOMEKIT + '.accessories.HomeDriver', + return_value=hk_driver) as mock_driver: await hass.async_add_job(homekit.setup) mock_driver.assert_called_with( - hass, ANY, port=DEFAULT_PORT, address='172.0.0.0', persist_file=ANY) + hass, address='172.0.0.0', port=DEFAULT_PORT, persist_file=ANY) async def test_homekit_add_accessory(): """Add accessory if config exists and get_acc returns an accessory.""" homekit = HomeKit('hass', None, None, lambda entity_id: True, {}) + homekit.driver = 'driver' homekit.bridge = mock_bridge = Mock() with patch(PATH_HOMEKIT + '.get_accessory') as mock_get_acc: mock_get_acc.side_effect = [None, 'acc', None] homekit.add_bridge_accessory(State('light.demo', 'on')) - mock_get_acc.assert_called_with('hass', ANY, 363398124, {}) + mock_get_acc.assert_called_with('hass', 'driver', ANY, 363398124, {}) assert not mock_bridge.add_accessory.called homekit.add_bridge_accessory(State('demo.test', 'on')) - mock_get_acc.assert_called_with('hass', ANY, 294192020, {}) + mock_get_acc.assert_called_with('hass', 'driver', ANY, 294192020, {}) assert mock_bridge.add_accessory.called homekit.add_bridge_accessory(State('demo.test_2', 'on')) - mock_get_acc.assert_called_with('hass', ANY, 429982757, {}) + mock_get_acc.assert_called_with('hass', 'driver', ANY, 429982757, {}) mock_bridge.add_accessory.assert_called_with('acc') @@ -164,30 +166,35 @@ async def test_homekit_entity_filter(hass): assert mock_get_acc.called is False -async def test_homekit_start(hass, debounce_patcher): +async def test_homekit_start(hass, hk_driver, debounce_patcher): """Test HomeKit start method.""" pin = b'123-45-678' homekit = HomeKit(hass, None, None, {}, {'cover.demo': {}}) - homekit.bridge = Mock() - homekit.driver = mock_driver = Mock(state=Mock(paired=False, pincode=pin)) + homekit.bridge = 'bridge' + homekit.driver = hk_driver hass.states.async_set('light.demo', 'on') state = hass.states.async_all()[0] with patch(PATH_HOMEKIT + '.HomeKit.add_bridge_accessory') as \ mock_add_acc, \ - patch(PATH_HOMEKIT + '.show_setup_message') as mock_setup_msg: + patch(PATH_HOMEKIT + '.show_setup_message') as mock_setup_msg, \ + patch('pyhap.accessory_driver.AccessoryDriver.add_accessory') as \ + hk_driver_add_acc, \ + patch('pyhap.accessory_driver.AccessoryDriver.start') as \ + hk_driver_start: await hass.async_add_job(homekit.start) mock_add_acc.assert_called_with(state) mock_setup_msg.assert_called_with(hass, pin) - assert mock_driver.start.called is True + hk_driver_add_acc.assert_called_with('bridge') + assert hk_driver_start.called assert homekit.status == STATUS_RUNNING # Test start() if already started - mock_driver.reset_mock() + hk_driver_start.reset_mock() await hass.async_add_job(homekit.start) - assert mock_driver.start.called is False + assert not hk_driver_start.called async def test_homekit_stop(hass): diff --git a/tests/components/homekit/test_type_covers.py b/tests/components/homekit/test_type_covers.py index 8138d1c506b0ba19064e3147ed339536ebb17596..c69ddacd328e6a70c3d2e9291aacb90ffe531028 100644 --- a/tests/components/homekit/test_type_covers.py +++ b/tests/components/homekit/test_type_covers.py @@ -28,13 +28,13 @@ def cls(): patcher.stop() -async def test_garage_door_open_close(hass, cls): +async def test_garage_door_open_close(hass, hk_driver, cls): """Test if accessory and HA are updated accordingly.""" entity_id = 'cover.garage_door' hass.states.async_set(entity_id, None) await hass.async_block_till_done() - acc = cls.garage(hass, 'Garage Door', entity_id, 2, None) + acc = cls.garage(hass, hk_driver, 'Garage Door', entity_id, 2, None) await hass.async_add_job(acc.run) assert acc.aid == 2 @@ -85,13 +85,13 @@ async def test_garage_door_open_close(hass, cls): assert acc.char_target_state.value == 0 -async def test_window_set_cover_position(hass, cls): +async def test_window_set_cover_position(hass, hk_driver, cls): """Test if accessory and HA are updated accordingly.""" entity_id = 'cover.window' hass.states.async_set(entity_id, None) await hass.async_block_till_done() - acc = cls.window(hass, 'Cover', entity_id, 2, None) + acc = cls.window(hass, hk_driver, 'Cover', entity_id, 2, None) await hass.async_add_job(acc.run) assert acc.aid == 2 @@ -133,13 +133,13 @@ async def test_window_set_cover_position(hass, cls): assert acc.char_target_position.value == 75 -async def test_window_open_close(hass, cls): +async def test_window_open_close(hass, hk_driver, cls): """Test if accessory and HA are updated accordingly.""" entity_id = 'cover.window' hass.states.async_set(entity_id, STATE_UNKNOWN, {ATTR_SUPPORTED_FEATURES: 0}) - acc = cls.window_basic(hass, 'Cover', entity_id, 2, None) + acc = cls.window_basic(hass, hk_driver, 'Cover', entity_id, 2, None) await hass.async_add_job(acc.run) assert acc.aid == 2 @@ -196,13 +196,13 @@ async def test_window_open_close(hass, cls): assert acc.char_position_state.value == 2 -async def test_window_open_close_stop(hass, cls): +async def test_window_open_close_stop(hass, hk_driver, cls): """Test if accessory and HA are updated accordingly.""" entity_id = 'cover.window' hass.states.async_set(entity_id, STATE_UNKNOWN, {ATTR_SUPPORTED_FEATURES: SUPPORT_STOP}) - acc = cls.window_basic(hass, 'Cover', entity_id, 2, None) + acc = cls.window_basic(hass, hk_driver, 'Cover', entity_id, 2, None) await hass.async_add_job(acc.run) # Set from HomeKit diff --git a/tests/components/homekit/test_type_fans.py b/tests/components/homekit/test_type_fans.py index f96fe19d6035486a7719e7e98bc7f88526db372a..ba7d4ccdcf069223a3cf16700a3b5b4461fc759e 100644 --- a/tests/components/homekit/test_type_fans.py +++ b/tests/components/homekit/test_type_fans.py @@ -27,14 +27,14 @@ def cls(): patcher.stop() -async def test_fan_basic(hass, cls): +async def test_fan_basic(hass, hk_driver, cls): """Test fan with char state.""" entity_id = 'fan.demo' hass.states.async_set(entity_id, STATE_ON, {ATTR_SUPPORTED_FEATURES: 0}) await hass.async_block_till_done() - acc = cls.fan(hass, 'Fan', entity_id, 2, None) + acc = cls.fan(hass, hk_driver, 'Fan', entity_id, 2, None) assert acc.aid == 2 assert acc.category == 3 # Fan @@ -75,7 +75,7 @@ async def test_fan_basic(hass, cls): assert call_turn_off[0].data[ATTR_ENTITY_ID] == entity_id -async def test_fan_direction(hass, cls): +async def test_fan_direction(hass, hk_driver, cls): """Test fan with direction.""" entity_id = 'fan.demo' @@ -83,7 +83,7 @@ async def test_fan_direction(hass, cls): ATTR_SUPPORTED_FEATURES: SUPPORT_DIRECTION, ATTR_DIRECTION: DIRECTION_FORWARD}) await hass.async_block_till_done() - acc = cls.fan(hass, 'Fan', entity_id, 2, None) + acc = cls.fan(hass, hk_driver, 'Fan', entity_id, 2, None) assert acc.char_direction.value == 0 @@ -113,14 +113,14 @@ async def test_fan_direction(hass, cls): assert call_set_direction[1].data[ATTR_DIRECTION] == DIRECTION_REVERSE -async def test_fan_oscillate(hass, cls): +async def test_fan_oscillate(hass, hk_driver, cls): """Test fan with oscillate.""" entity_id = 'fan.demo' hass.states.async_set(entity_id, STATE_ON, { ATTR_SUPPORTED_FEATURES: SUPPORT_OSCILLATE, ATTR_OSCILLATING: False}) await hass.async_block_till_done() - acc = cls.fan(hass, 'Fan', entity_id, 2, None) + acc = cls.fan(hass, hk_driver, 'Fan', entity_id, 2, None) assert acc.char_swing.value == 0 diff --git a/tests/components/homekit/test_type_lights.py b/tests/components/homekit/test_type_lights.py index 7a1db7b3f711693efbb9da6d76a0f9e521c64788..a9a5f1c3ece9de63c42173b3be2f688f2b668334 100644 --- a/tests/components/homekit/test_type_lights.py +++ b/tests/components/homekit/test_type_lights.py @@ -26,14 +26,14 @@ def cls(): patcher.stop() -async def test_light_basic(hass, cls): +async def test_light_basic(hass, hk_driver, cls): """Test light with char state.""" entity_id = 'light.demo' hass.states.async_set(entity_id, STATE_ON, {ATTR_SUPPORTED_FEATURES: 0}) await hass.async_block_till_done() - acc = cls.light(hass, 'Light', entity_id, 2, None) + acc = cls.light(hass, hk_driver, 'Light', entity_id, 2, None) assert acc.aid == 2 assert acc.category == 5 # Lightbulb @@ -74,14 +74,14 @@ async def test_light_basic(hass, cls): assert call_turn_off[0].data[ATTR_ENTITY_ID] == entity_id -async def test_light_brightness(hass, cls): +async def test_light_brightness(hass, hk_driver, cls): """Test light with brightness.""" entity_id = 'light.demo' hass.states.async_set(entity_id, STATE_ON, { ATTR_SUPPORTED_FEATURES: SUPPORT_BRIGHTNESS, ATTR_BRIGHTNESS: 255}) await hass.async_block_till_done() - acc = cls.light(hass, 'Light', entity_id, 2, None) + acc = cls.light(hass, hk_driver, 'Light', entity_id, 2, None) assert acc.char_brightness.value == 0 @@ -118,7 +118,7 @@ async def test_light_brightness(hass, cls): assert call_turn_off[0].data[ATTR_ENTITY_ID] == entity_id -async def test_light_color_temperature(hass, cls): +async def test_light_color_temperature(hass, hk_driver, cls): """Test light with color temperature.""" entity_id = 'light.demo' @@ -126,7 +126,7 @@ async def test_light_color_temperature(hass, cls): ATTR_SUPPORTED_FEATURES: SUPPORT_COLOR_TEMP, ATTR_COLOR_TEMP: 190}) await hass.async_block_till_done() - acc = cls.light(hass, 'Light', entity_id, 2, None) + acc = cls.light(hass, hk_driver, 'Light', entity_id, 2, None) assert acc.char_color_temperature.value == 153 @@ -145,7 +145,7 @@ async def test_light_color_temperature(hass, cls): assert call_turn_on[0].data[ATTR_COLOR_TEMP] == 250 -async def test_light_rgb_color(hass, cls): +async def test_light_rgb_color(hass, hk_driver, cls): """Test light with rgb_color.""" entity_id = 'light.demo' @@ -153,7 +153,7 @@ async def test_light_rgb_color(hass, cls): ATTR_SUPPORTED_FEATURES: SUPPORT_COLOR, ATTR_HS_COLOR: (260, 90)}) await hass.async_block_till_done() - acc = cls.light(hass, 'Light', entity_id, 2, None) + acc = cls.light(hass, hk_driver, 'Light', entity_id, 2, None) assert acc.char_hue.value == 0 assert acc.char_saturation.value == 75 diff --git a/tests/components/homekit/test_type_locks.py b/tests/components/homekit/test_type_locks.py index f4698b1380bf4ce2c79c00e0be4e5a3e634a926c..8f18a591019389dc4b5843bbb5239e22c3fabd12 100644 --- a/tests/components/homekit/test_type_locks.py +++ b/tests/components/homekit/test_type_locks.py @@ -9,7 +9,7 @@ from homeassistant.const import ( from tests.common import async_mock_service -async def test_lock_unlock(hass): +async def test_lock_unlock(hass, hk_driver): """Test if accessory and HA are updated accordingly.""" code = '1234' config = {ATTR_CODE: code} @@ -17,7 +17,7 @@ async def test_lock_unlock(hass): hass.states.async_set(entity_id, None) await hass.async_block_till_done() - acc = Lock(hass, 'Lock', entity_id, 2, config) + acc = Lock(hass, hk_driver, 'Lock', entity_id, 2, config) await hass.async_add_job(acc.run) assert acc.aid == 2 @@ -66,13 +66,13 @@ async def test_lock_unlock(hass): @pytest.mark.parametrize('config', [{}, {ATTR_CODE: None}]) -async def test_no_code(hass, config): +async def test_no_code(hass, hk_driver, config): """Test accessory if lock doesn't require a code.""" entity_id = 'lock.kitchen_door' hass.states.async_set(entity_id, None) await hass.async_block_till_done() - acc = Lock(hass, 'Lock', entity_id, 2, config) + acc = Lock(hass, hk_driver, 'Lock', entity_id, 2, config) # Set from HomeKit call_lock = async_mock_service(hass, DOMAIN, 'lock') diff --git a/tests/components/homekit/test_type_media_players.py b/tests/components/homekit/test_type_media_players.py index d89f9740ea66c905129ac89728d92ff6a32dfd98..4076b1f8a8985bbc54682a731f34e61f0c50fbb6 100644 --- a/tests/components/homekit/test_type_media_players.py +++ b/tests/components/homekit/test_type_media_players.py @@ -15,7 +15,7 @@ from homeassistant.const import ( from tests.common import async_mock_service -async def test_media_player_set_state(hass): +async def test_media_player_set_state(hass, hk_driver): """Test if accessory and HA are updated accordingly.""" config = {CONF_FEATURE_LIST: { FEATURE_ON_OFF: None, FEATURE_PLAY_PAUSE: None, @@ -25,7 +25,7 @@ async def test_media_player_set_state(hass): hass.states.async_set(entity_id, None, {ATTR_SUPPORTED_FEATURES: 20873, ATTR_MEDIA_VOLUME_MUTED: False}) await hass.async_block_till_done() - acc = MediaPlayer(hass, 'MediaPlayer', entity_id, 2, config) + acc = MediaPlayer(hass, hk_driver, 'MediaPlayer', entity_id, 2, config) await hass.async_add_job(acc.run) assert acc.aid == 2 diff --git a/tests/components/homekit/test_type_security_systems.py b/tests/components/homekit/test_type_security_systems.py index 7b72404cdaadbc998c886aeb04edb4e177bf7d95..3ddce0f36eb4c720fc32bfbbfe7d168f3c7a7ad2 100644 --- a/tests/components/homekit/test_type_security_systems.py +++ b/tests/components/homekit/test_type_security_systems.py @@ -12,7 +12,7 @@ from homeassistant.const import ( from tests.common import async_mock_service -async def test_switch_set_state(hass): +async def test_switch_set_state(hass, hk_driver): """Test if accessory and HA are updated accordingly.""" code = '1234' config = {ATTR_CODE: code} @@ -20,7 +20,8 @@ async def test_switch_set_state(hass): hass.states.async_set(entity_id, None) await hass.async_block_till_done() - acc = SecuritySystem(hass, 'SecuritySystem', entity_id, 2, config) + acc = SecuritySystem(hass, hk_driver, 'SecuritySystem', + entity_id, 2, config) await hass.async_add_job(acc.run) assert acc.aid == 2 @@ -95,13 +96,14 @@ async def test_switch_set_state(hass): @pytest.mark.parametrize('config', [{}, {ATTR_CODE: None}]) -async def test_no_alarm_code(hass, config): +async def test_no_alarm_code(hass, hk_driver, config): """Test accessory if security_system doesn't require an alarm_code.""" entity_id = 'alarm_control_panel.test' hass.states.async_set(entity_id, None) await hass.async_block_till_done() - acc = SecuritySystem(hass, 'SecuritySystem', entity_id, 2, config) + acc = SecuritySystem(hass, hk_driver, 'SecuritySystem', + entity_id, 2, config) # Set from HomeKit call_arm_home = async_mock_service(hass, DOMAIN, 'alarm_arm_home') diff --git a/tests/components/homekit/test_type_sensors.py b/tests/components/homekit/test_type_sensors.py index e36ae67da121508478d528edde333bc9f08943ba..54ecbcb196fb178223525416be5f6e62bca2f50c 100644 --- a/tests/components/homekit/test_type_sensors.py +++ b/tests/components/homekit/test_type_sensors.py @@ -8,13 +8,14 @@ from homeassistant.const import ( STATE_OFF, STATE_ON, STATE_UNKNOWN, TEMP_CELSIUS, TEMP_FAHRENHEIT) -async def test_temperature(hass): +async def test_temperature(hass, hk_driver): """Test if accessory is updated after state change.""" entity_id = 'sensor.temperature' hass.states.async_set(entity_id, None) await hass.async_block_till_done() - acc = TemperatureSensor(hass, 'Temperature', entity_id, 2, None) + acc = TemperatureSensor(hass, hk_driver, 'Temperature', + entity_id, 2, None) await hass.async_add_job(acc.run) assert acc.aid == 2 @@ -40,13 +41,13 @@ async def test_temperature(hass): assert acc.char_temp.value == 24 -async def test_humidity(hass): +async def test_humidity(hass, hk_driver): """Test if accessory is updated after state change.""" entity_id = 'sensor.humidity' hass.states.async_set(entity_id, None) await hass.async_block_till_done() - acc = HumiditySensor(hass, 'Humidity', entity_id, 2, None) + acc = HumiditySensor(hass, hk_driver, 'Humidity', entity_id, 2, None) await hass.async_add_job(acc.run) assert acc.aid == 2 @@ -63,13 +64,14 @@ async def test_humidity(hass): assert acc.char_humidity.value == 20 -async def test_air_quality(hass): +async def test_air_quality(hass, hk_driver): """Test if accessory is updated after state change.""" entity_id = 'sensor.air_quality' hass.states.async_set(entity_id, None) await hass.async_block_till_done() - acc = AirQualitySensor(hass, 'Air Quality', entity_id, 2, None) + acc = AirQualitySensor(hass, hk_driver, 'Air Quality', + entity_id, 2, None) await hass.async_add_job(acc.run) assert acc.aid == 2 @@ -94,13 +96,13 @@ async def test_air_quality(hass): assert acc.char_quality.value == 5 -async def test_co2(hass): +async def test_co2(hass, hk_driver): """Test if accessory is updated after state change.""" entity_id = 'sensor.co2' hass.states.async_set(entity_id, None) await hass.async_block_till_done() - acc = CarbonDioxideSensor(hass, 'CO2', entity_id, 2, None) + acc = CarbonDioxideSensor(hass, hk_driver, 'CO2', entity_id, 2, None) await hass.async_add_job(acc.run) assert acc.aid == 2 @@ -129,13 +131,13 @@ async def test_co2(hass): assert acc.char_detected.value == 0 -async def test_light(hass): +async def test_light(hass, hk_driver): """Test if accessory is updated after state change.""" entity_id = 'sensor.light' hass.states.async_set(entity_id, None) await hass.async_block_till_done() - acc = LightSensor(hass, 'Light', entity_id, 2, None) + acc = LightSensor(hass, hk_driver, 'Light', entity_id, 2, None) await hass.async_add_job(acc.run) assert acc.aid == 2 @@ -152,7 +154,7 @@ async def test_light(hass): assert acc.char_light.value == 300 -async def test_binary(hass): +async def test_binary(hass, hk_driver): """Test if accessory is updated after state change.""" entity_id = 'binary_sensor.opening' @@ -160,7 +162,7 @@ async def test_binary(hass): {ATTR_DEVICE_CLASS: 'opening'}) await hass.async_block_till_done() - acc = BinarySensor(hass, 'Window Opening', entity_id, 2, None) + acc = BinarySensor(hass, hk_driver, 'Window Opening', entity_id, 2, None) await hass.async_add_job(acc.run) assert acc.aid == 2 @@ -193,7 +195,7 @@ async def test_binary(hass): assert acc.char_detected.value == 0 -async def test_binary_device_classes(hass): +async def test_binary_device_classes(hass, hk_driver): """Test if services and characteristics are assigned correctly.""" entity_id = 'binary_sensor.demo' @@ -202,6 +204,7 @@ async def test_binary_device_classes(hass): {ATTR_DEVICE_CLASS: device_class}) await hass.async_block_till_done() - acc = BinarySensor(hass, 'Binary Sensor', entity_id, 2, None) + acc = BinarySensor(hass, hk_driver, 'Binary Sensor', + entity_id, 2, None) assert acc.get_service(service).display_name == service assert acc.char_detected.display_name == char diff --git a/tests/components/homekit/test_type_switches.py b/tests/components/homekit/test_type_switches.py index ff94c4b6a0b00fbcf434826963061d2a071fbc9f..b1830d1926f122ba53231fd8831cc8257f788b8c 100644 --- a/tests/components/homekit/test_type_switches.py +++ b/tests/components/homekit/test_type_switches.py @@ -15,13 +15,13 @@ from tests.common import async_mock_service 'script.test', 'switch.test', ]) -async def test_switch_set_state(hass, entity_id): +async def test_switch_set_state(hass, hk_driver, entity_id): """Test if accessory and HA are updated accordingly.""" domain = split_entity_id(entity_id)[0] hass.states.async_set(entity_id, None) await hass.async_block_till_done() - acc = Switch(hass, 'Switch', entity_id, 2, None) + acc = Switch(hass, hk_driver, 'Switch', entity_id, 2, None) await hass.async_add_job(acc.run) assert acc.aid == 2 diff --git a/tests/components/homekit/test_type_thermostats.py b/tests/components/homekit/test_type_thermostats.py index 337ad23ad05068e5681ca65d5d45307752e3431c..6d6a48c7971b771fce4f28a5a6e54a8f1ec00d54 100644 --- a/tests/components/homekit/test_type_thermostats.py +++ b/tests/components/homekit/test_type_thermostats.py @@ -27,13 +27,13 @@ def cls(): patcher.stop() -async def test_default_thermostat(hass, cls): +async def test_default_thermostat(hass, hk_driver, cls): """Test if accessory and HA are updated accordingly.""" entity_id = 'climate.test' hass.states.async_set(entity_id, STATE_OFF, {ATTR_SUPPORTED_FEATURES: 0}) await hass.async_block_till_done() - acc = cls.thermostat(hass, 'Climate', entity_id, 2, None) + acc = cls.thermostat(hass, hk_driver, 'Climate', entity_id, 2, None) await hass.async_add_job(acc.run) assert acc.aid == 2 @@ -166,14 +166,14 @@ async def test_default_thermostat(hass, cls): assert acc.char_target_heat_cool.value == 1 -async def test_auto_thermostat(hass, cls): +async def test_auto_thermostat(hass, hk_driver, cls): """Test if accessory and HA are updated accordingly.""" entity_id = 'climate.test' # support_auto = True hass.states.async_set(entity_id, STATE_OFF, {ATTR_SUPPORTED_FEATURES: 6}) await hass.async_block_till_done() - acc = cls.thermostat(hass, 'Climate', entity_id, 2, None) + acc = cls.thermostat(hass, hk_driver, 'Climate', entity_id, 2, None) await hass.async_add_job(acc.run) assert acc.char_cooling_thresh_temp.value == 23.0 @@ -241,7 +241,7 @@ async def test_auto_thermostat(hass, cls): assert acc.char_cooling_thresh_temp.value == 25.0 -async def test_power_state(hass, cls): +async def test_power_state(hass, hk_driver, cls): """Test if accessory and HA are updated accordingly.""" entity_id = 'climate.test' @@ -252,7 +252,7 @@ async def test_power_state(hass, cls): ATTR_TEMPERATURE: 23.0, ATTR_CURRENT_TEMPERATURE: 18.0}) await hass.async_block_till_done() - acc = cls.thermostat(hass, 'Climate', entity_id, 2, None) + acc = cls.thermostat(hass, hk_driver, 'Climate', entity_id, 2, None) await hass.async_add_job(acc.run) assert acc.support_power_state is True @@ -297,14 +297,14 @@ async def test_power_state(hass, cls): assert acc.char_target_heat_cool.value == 0 -async def test_thermostat_fahrenheit(hass, cls): +async def test_thermostat_fahrenheit(hass, hk_driver, cls): """Test if accessory and HA are updated accordingly.""" entity_id = 'climate.test' # support_auto = True hass.states.async_set(entity_id, STATE_OFF, {ATTR_SUPPORTED_FEATURES: 6}) await hass.async_block_till_done() - acc = cls.thermostat(hass, 'Climate', entity_id, 2, None) + acc = cls.thermostat(hass, hk_driver, 'Climate', entity_id, 2, None) await hass.async_add_job(acc.run) hass.states.async_set(entity_id, STATE_AUTO,