Update HAP-python to 2.1.0 (#14528)
This commit is contained in:
parent
d36996c8f0
commit
12e76ef7c1
8 changed files with 56 additions and 48 deletions
|
@ -29,7 +29,7 @@ from .util import show_setup_message, validate_entity_config
|
||||||
TYPES = Registry()
|
TYPES = Registry()
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
REQUIREMENTS = ['HAP-python==2.0.0']
|
REQUIREMENTS = ['HAP-python==2.1.0']
|
||||||
|
|
||||||
# #### Driver Status ####
|
# #### Driver Status ####
|
||||||
STATUS_READY = 0
|
STATUS_READY = 0
|
||||||
|
@ -185,7 +185,8 @@ class HomeKit():
|
||||||
ip_addr = self._ip_address or get_local_ip()
|
ip_addr = self._ip_address or get_local_ip()
|
||||||
path = self.hass.config.path(HOMEKIT_FILE)
|
path = self.hass.config.path(HOMEKIT_FILE)
|
||||||
self.bridge = HomeBridge(self.hass)
|
self.bridge = HomeBridge(self.hass)
|
||||||
self.driver = HomeDriver(self.bridge, self._port, ip_addr, path)
|
self.driver = HomeDriver(self.hass, self.bridge, port=self._port,
|
||||||
|
address=ip_addr, persist_file=path)
|
||||||
|
|
||||||
def add_bridge_accessory(self, state):
|
def add_bridge_accessory(self, state):
|
||||||
"""Try adding accessory to bridge if configured beforehand."""
|
"""Try adding accessory to bridge if configured beforehand."""
|
||||||
|
@ -213,8 +214,8 @@ class HomeKit():
|
||||||
self.add_bridge_accessory(state)
|
self.add_bridge_accessory(state)
|
||||||
self.bridge.set_driver(self.driver)
|
self.bridge.set_driver(self.driver)
|
||||||
|
|
||||||
if not self.bridge.paired:
|
if not self.driver.state.paired:
|
||||||
show_setup_message(self.hass, self.bridge)
|
show_setup_message(self.hass, self.driver.state.pincode)
|
||||||
|
|
||||||
_LOGGER.debug('Driver start')
|
_LOGGER.debug('Driver start')
|
||||||
self.hass.add_job(self.driver.start)
|
self.hass.add_job(self.driver.start)
|
||||||
|
|
|
@ -115,20 +115,23 @@ class HomeBridge(Bridge):
|
||||||
"""Prevent print of pyhap setup message to terminal."""
|
"""Prevent print of pyhap setup message to terminal."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def add_paired_client(self, client_uuid, client_public):
|
|
||||||
"""Override super function to dismiss setup message if paired."""
|
|
||||||
super().add_paired_client(client_uuid, client_public)
|
|
||||||
dismiss_setup_message(self.hass)
|
|
||||||
|
|
||||||
def remove_paired_client(self, client_uuid):
|
|
||||||
"""Override super function to show setup message if unpaired."""
|
|
||||||
super().remove_paired_client(client_uuid)
|
|
||||||
show_setup_message(self.hass, self)
|
|
||||||
|
|
||||||
|
|
||||||
class HomeDriver(AccessoryDriver):
|
class HomeDriver(AccessoryDriver):
|
||||||
"""Adapter class for AccessoryDriver."""
|
"""Adapter class for AccessoryDriver."""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, hass, *args, **kwargs):
|
||||||
"""Initialize a AccessoryDriver object."""
|
"""Initialize a AccessoryDriver object."""
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
self.hass = hass
|
||||||
|
|
||||||
|
def pair(self, client_uuid, client_public):
|
||||||
|
"""Override super function to dismiss setup message if paired."""
|
||||||
|
value = super().pair(client_uuid, client_public)
|
||||||
|
if value:
|
||||||
|
dismiss_setup_message(self.hass)
|
||||||
|
return value
|
||||||
|
|
||||||
|
def unpair(self, client_uuid):
|
||||||
|
"""Override super function to show setup message if unpaired."""
|
||||||
|
super().unpair(client_uuid)
|
||||||
|
show_setup_message(self.hass, self.state.pincode)
|
||||||
|
|
|
@ -38,9 +38,9 @@ def validate_entity_config(values):
|
||||||
return entities
|
return entities
|
||||||
|
|
||||||
|
|
||||||
def show_setup_message(hass, bridge):
|
def show_setup_message(hass, pincode):
|
||||||
"""Display persistent notification with setup information."""
|
"""Display persistent notification with setup information."""
|
||||||
pin = bridge.pincode.decode()
|
pin = pincode.decode()
|
||||||
_LOGGER.info('Pincode: %s', pin)
|
_LOGGER.info('Pincode: %s', pin)
|
||||||
message = 'To setup Home Assistant in the Home App, enter the ' \
|
message = 'To setup Home Assistant in the Home App, enter the ' \
|
||||||
'following code:\n### {}'.format(pin)
|
'following code:\n### {}'.format(pin)
|
||||||
|
|
|
@ -28,7 +28,7 @@ Adafruit-SHT31==1.0.2
|
||||||
DoorBirdPy==0.1.3
|
DoorBirdPy==0.1.3
|
||||||
|
|
||||||
# homeassistant.components.homekit
|
# homeassistant.components.homekit
|
||||||
HAP-python==2.0.0
|
HAP-python==2.1.0
|
||||||
|
|
||||||
# homeassistant.components.notify.mastodon
|
# homeassistant.components.notify.mastodon
|
||||||
Mastodon.py==1.2.2
|
Mastodon.py==1.2.2
|
||||||
|
|
|
@ -19,7 +19,7 @@ requests_mock==1.5
|
||||||
|
|
||||||
|
|
||||||
# homeassistant.components.homekit
|
# homeassistant.components.homekit
|
||||||
HAP-python==2.0.0
|
HAP-python==2.1.0
|
||||||
|
|
||||||
# homeassistant.components.notify.html5
|
# homeassistant.components.notify.html5
|
||||||
PyJWT==1.6.0
|
PyJWT==1.6.0
|
||||||
|
|
|
@ -116,26 +116,6 @@ def test_home_bridge():
|
||||||
# setup_message
|
# setup_message
|
||||||
bridge.setup_message()
|
bridge.setup_message()
|
||||||
|
|
||||||
# add_paired_client
|
|
||||||
with patch('pyhap.accessory.Accessory.add_paired_client') \
|
|
||||||
as mock_add_paired_client, \
|
|
||||||
patch('homeassistant.components.homekit.accessories.'
|
|
||||||
'dismiss_setup_message') as mock_dissmiss_msg:
|
|
||||||
bridge.add_paired_client('client_uuid', 'client_public')
|
|
||||||
|
|
||||||
mock_add_paired_client.assert_called_with('client_uuid', 'client_public')
|
|
||||||
mock_dissmiss_msg.assert_called_with('hass')
|
|
||||||
|
|
||||||
# remove_paired_client
|
|
||||||
with patch('pyhap.accessory.Accessory.remove_paired_client') \
|
|
||||||
as mock_remove_paired_client, \
|
|
||||||
patch('homeassistant.components.homekit.accessories.'
|
|
||||||
'show_setup_message') as mock_show_msg:
|
|
||||||
bridge.remove_paired_client('client_uuid')
|
|
||||||
|
|
||||||
mock_remove_paired_client.assert_called_with('client_uuid')
|
|
||||||
mock_show_msg.assert_called_with('hass', bridge)
|
|
||||||
|
|
||||||
|
|
||||||
def test_home_driver():
|
def test_home_driver():
|
||||||
"""Test HomeDriver class."""
|
"""Test HomeDriver class."""
|
||||||
|
@ -143,9 +123,30 @@ def test_home_driver():
|
||||||
ip_address = '127.0.0.1'
|
ip_address = '127.0.0.1'
|
||||||
port = 51826
|
port = 51826
|
||||||
path = '.homekit.state'
|
path = '.homekit.state'
|
||||||
|
pin = b'123-45-678'
|
||||||
|
|
||||||
with patch('pyhap.accessory_driver.AccessoryDriver.__init__') \
|
with patch('pyhap.accessory_driver.AccessoryDriver.__init__') \
|
||||||
as mock_driver:
|
as mock_driver:
|
||||||
HomeDriver(bridge, ip_address, port, path)
|
driver = HomeDriver('hass', bridge, ip_address, port, path)
|
||||||
|
|
||||||
mock_driver.assert_called_with(bridge, ip_address, port, path)
|
mock_driver.assert_called_with(bridge, ip_address, port, path)
|
||||||
|
driver.state = Mock(pincode=pin)
|
||||||
|
|
||||||
|
# pair
|
||||||
|
with patch('pyhap.accessory_driver.AccessoryDriver.pair') as mock_pair, \
|
||||||
|
patch('homeassistant.components.homekit.accessories.'
|
||||||
|
'dismiss_setup_message') as mock_dissmiss_msg:
|
||||||
|
driver.pair('client_uuid', 'client_public')
|
||||||
|
|
||||||
|
mock_pair.assert_called_with('client_uuid', 'client_public')
|
||||||
|
mock_dissmiss_msg.assert_called_with('hass')
|
||||||
|
|
||||||
|
# unpair
|
||||||
|
with patch('pyhap.accessory_driver.AccessoryDriver.unpair') \
|
||||||
|
as mock_unpair, \
|
||||||
|
patch('homeassistant.components.homekit.accessories.'
|
||||||
|
'show_setup_message') as mock_show_msg:
|
||||||
|
driver.unpair('client_uuid')
|
||||||
|
|
||||||
|
mock_unpair.assert_called_with('client_uuid')
|
||||||
|
mock_show_msg.assert_called_with('hass', pin)
|
||||||
|
|
|
@ -107,7 +107,8 @@ async def test_homekit_setup(hass):
|
||||||
path = hass.config.path(HOMEKIT_FILE)
|
path = hass.config.path(HOMEKIT_FILE)
|
||||||
assert isinstance(homekit.bridge, HomeBridge)
|
assert isinstance(homekit.bridge, HomeBridge)
|
||||||
mock_driver.assert_called_with(
|
mock_driver.assert_called_with(
|
||||||
homekit.bridge, DEFAULT_PORT, IP_ADDRESS, path)
|
hass, homekit.bridge, port=DEFAULT_PORT,
|
||||||
|
address=IP_ADDRESS, persist_file=path)
|
||||||
|
|
||||||
# Test if stop listener is setup
|
# Test if stop listener is setup
|
||||||
assert hass.bus.async_listeners().get(EVENT_HOMEASSISTANT_STOP) == 1
|
assert hass.bus.async_listeners().get(EVENT_HOMEASSISTANT_STOP) == 1
|
||||||
|
@ -119,7 +120,8 @@ async def test_homekit_setup_ip_address(hass):
|
||||||
|
|
||||||
with patch(PATH_HOMEKIT + '.accessories.HomeDriver') as mock_driver:
|
with patch(PATH_HOMEKIT + '.accessories.HomeDriver') as mock_driver:
|
||||||
await hass.async_add_job(homekit.setup)
|
await hass.async_add_job(homekit.setup)
|
||||||
mock_driver.assert_called_with(ANY, DEFAULT_PORT, '172.0.0.0', ANY)
|
mock_driver.assert_called_with(
|
||||||
|
hass, ANY, port=DEFAULT_PORT, address='172.0.0.0', persist_file=ANY)
|
||||||
|
|
||||||
|
|
||||||
async def test_homekit_add_accessory(hass):
|
async def test_homekit_add_accessory(hass):
|
||||||
|
@ -167,9 +169,10 @@ async def test_homekit_entity_filter(hass):
|
||||||
|
|
||||||
async def test_homekit_start(hass, debounce_patcher):
|
async def test_homekit_start(hass, debounce_patcher):
|
||||||
"""Test HomeKit start method."""
|
"""Test HomeKit start method."""
|
||||||
|
pin = b'123-45-678'
|
||||||
homekit = HomeKit(hass, None, None, {}, {'cover.demo': {}})
|
homekit = HomeKit(hass, None, None, {}, {'cover.demo': {}})
|
||||||
homekit.bridge = HomeBridge(hass)
|
homekit.bridge = HomeBridge(hass)
|
||||||
homekit.driver = Mock()
|
homekit.driver = Mock(state=Mock(paired=False, pincode=pin))
|
||||||
|
|
||||||
hass.states.async_set('light.demo', 'on')
|
hass.states.async_set('light.demo', 'on')
|
||||||
state = hass.states.async_all()[0]
|
state = hass.states.async_all()[0]
|
||||||
|
@ -180,7 +183,7 @@ async def test_homekit_start(hass, debounce_patcher):
|
||||||
await hass.async_add_job(homekit.start)
|
await hass.async_add_job(homekit.start)
|
||||||
|
|
||||||
mock_add_acc.assert_called_with(state)
|
mock_add_acc.assert_called_with(state)
|
||||||
mock_setup_msg.assert_called_with(hass, homekit.bridge)
|
mock_setup_msg.assert_called_with(hass, pin)
|
||||||
assert homekit.driver.start.called is True
|
assert homekit.driver.start.called is True
|
||||||
assert homekit.status == STATUS_RUNNING
|
assert homekit.status == STATUS_RUNNING
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
import pytest
|
import pytest
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.homekit.accessories import HomeBridge
|
|
||||||
from homeassistant.components.homekit.const import HOMEKIT_NOTIFY_ID
|
from homeassistant.components.homekit.const import HOMEKIT_NOTIFY_ID
|
||||||
from homeassistant.components.homekit.util import (
|
from homeassistant.components.homekit.util import (
|
||||||
show_setup_message, dismiss_setup_message, convert_to_float,
|
show_setup_message, dismiss_setup_message, convert_to_float,
|
||||||
|
@ -10,7 +9,7 @@ from homeassistant.components.homekit.util import (
|
||||||
from homeassistant.components.homekit.util import validate_entity_config \
|
from homeassistant.components.homekit.util import validate_entity_config \
|
||||||
as vec
|
as vec
|
||||||
from homeassistant.components.persistent_notification import (
|
from homeassistant.components.persistent_notification import (
|
||||||
DOMAIN, ATTR_NOTIFICATION_ID)
|
DOMAIN, ATTR_MESSAGE, ATTR_NOTIFICATION_ID)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_CODE, STATE_UNKNOWN, TEMP_CELSIUS, TEMP_FAHRENHEIT, CONF_NAME)
|
ATTR_CODE, STATE_UNKNOWN, TEMP_CELSIUS, TEMP_FAHRENHEIT, CONF_NAME)
|
||||||
|
|
||||||
|
@ -74,16 +73,17 @@ def test_density_to_air_quality():
|
||||||
|
|
||||||
async def test_show_setup_msg(hass):
|
async def test_show_setup_msg(hass):
|
||||||
"""Test show setup message as persistence notification."""
|
"""Test show setup message as persistence notification."""
|
||||||
bridge = HomeBridge(hass)
|
pincode = b'123-45-678'
|
||||||
|
|
||||||
call_create_notification = async_mock_service(hass, DOMAIN, 'create')
|
call_create_notification = async_mock_service(hass, DOMAIN, 'create')
|
||||||
|
|
||||||
await hass.async_add_job(show_setup_message, hass, bridge)
|
await hass.async_add_job(show_setup_message, hass, pincode)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert call_create_notification
|
assert call_create_notification
|
||||||
assert call_create_notification[0].data[ATTR_NOTIFICATION_ID] == \
|
assert call_create_notification[0].data[ATTR_NOTIFICATION_ID] == \
|
||||||
HOMEKIT_NOTIFY_ID
|
HOMEKIT_NOTIFY_ID
|
||||||
|
assert pincode.decode() in call_create_notification[0].data[ATTR_MESSAGE]
|
||||||
|
|
||||||
|
|
||||||
async def test_dismiss_setup_msg(hass):
|
async def test_dismiss_setup_msg(hass):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue