Upgrade aiohue and fix race condition (#13475)
* Bump aiohue to 1.3 * Store bridge in hass.data before setting up platform * Fix tests
This commit is contained in:
parent
08bcf84170
commit
f1d37fc849
5 changed files with 7 additions and 9 deletions
|
@ -21,7 +21,7 @@ from homeassistant.helpers import discovery, aiohttp_client
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.util.json import save_json
|
from homeassistant.util.json import save_json
|
||||||
|
|
||||||
REQUIREMENTS = ['aiohue==1.2.0']
|
REQUIREMENTS = ['aiohue==1.3.0']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -145,7 +145,6 @@ async def async_setup_bridge(
|
||||||
bridge = HueBridge(host, hass, filename, username, allow_unreachable,
|
bridge = HueBridge(host, hass, filename, username, allow_unreachable,
|
||||||
allow_hue_groups)
|
allow_hue_groups)
|
||||||
await bridge.async_setup()
|
await bridge.async_setup()
|
||||||
hass.data[DOMAIN][host] = bridge
|
|
||||||
|
|
||||||
|
|
||||||
def _find_username_from_config(hass, filename):
|
def _find_username_from_config(hass, filename):
|
||||||
|
@ -209,6 +208,8 @@ class HueBridge(object):
|
||||||
self.host)
|
self.host)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.hass.data[DOMAIN][self.host] = self
|
||||||
|
|
||||||
# If we came here and configuring this host, mark as done
|
# If we came here and configuring this host, mark as done
|
||||||
if self.config_request_id:
|
if self.config_request_id:
|
||||||
request_id = self.config_request_id
|
request_id = self.config_request_id
|
||||||
|
|
|
@ -74,7 +74,7 @@ aiodns==1.1.1
|
||||||
aiohttp_cors==0.7.0
|
aiohttp_cors==0.7.0
|
||||||
|
|
||||||
# homeassistant.components.hue
|
# homeassistant.components.hue
|
||||||
aiohue==1.2.0
|
aiohue==1.3.0
|
||||||
|
|
||||||
# homeassistant.components.sensor.imap
|
# homeassistant.components.sensor.imap
|
||||||
aioimaplib==0.7.13
|
aioimaplib==0.7.13
|
||||||
|
|
|
@ -35,7 +35,7 @@ aioautomatic==0.6.5
|
||||||
aiohttp_cors==0.7.0
|
aiohttp_cors==0.7.0
|
||||||
|
|
||||||
# homeassistant.components.hue
|
# homeassistant.components.hue
|
||||||
aiohue==1.2.0
|
aiohue==1.3.0
|
||||||
|
|
||||||
# homeassistant.components.notify.apns
|
# homeassistant.components.notify.apns
|
||||||
apns2==0.3.0
|
apns2==0.3.0
|
||||||
|
|
|
@ -66,6 +66,7 @@ async def test_only_create_no_username(hass):
|
||||||
|
|
||||||
async def test_configurator_callback(hass, mock_request):
|
async def test_configurator_callback(hass, mock_request):
|
||||||
"""."""
|
"""."""
|
||||||
|
hass.data[hue.DOMAIN] = {}
|
||||||
with patch('aiohue.Bridge.create_user',
|
with patch('aiohue.Bridge.create_user',
|
||||||
side_effect=aiohue.LinkButtonNotPressed):
|
side_effect=aiohue.LinkButtonNotPressed):
|
||||||
await MockBridge(hass).async_setup()
|
await MockBridge(hass).async_setup()
|
||||||
|
|
|
@ -18,7 +18,6 @@ async def test_setup_with_multiple_hosts(hass, mock_bridge):
|
||||||
assert len(mock_bridge.mock_calls) == 2
|
assert len(mock_bridge.mock_calls) == 2
|
||||||
hosts = sorted(mock_call[1][0] for mock_call in mock_bridge.mock_calls)
|
hosts = sorted(mock_call[1][0] for mock_call in mock_bridge.mock_calls)
|
||||||
assert hosts == ['127.0.0.1', '192.168.1.10']
|
assert hosts == ['127.0.0.1', '192.168.1.10']
|
||||||
assert len(hass.data[hue.DOMAIN]) == 2
|
|
||||||
|
|
||||||
|
|
||||||
async def test_bridge_discovered(hass, mock_bridge):
|
async def test_bridge_discovered(hass, mock_bridge):
|
||||||
|
@ -33,7 +32,6 @@ async def test_bridge_discovered(hass, mock_bridge):
|
||||||
|
|
||||||
assert len(mock_bridge.mock_calls) == 1
|
assert len(mock_bridge.mock_calls) == 1
|
||||||
assert mock_bridge.mock_calls[0][1][0] == '192.168.1.10'
|
assert mock_bridge.mock_calls[0][1][0] == '192.168.1.10'
|
||||||
assert len(hass.data[hue.DOMAIN]) == 1
|
|
||||||
|
|
||||||
|
|
||||||
async def test_bridge_configure_and_discovered(hass, mock_bridge):
|
async def test_bridge_configure_and_discovered(hass, mock_bridge):
|
||||||
|
@ -48,7 +46,7 @@ async def test_bridge_configure_and_discovered(hass, mock_bridge):
|
||||||
|
|
||||||
assert len(mock_bridge.mock_calls) == 1
|
assert len(mock_bridge.mock_calls) == 1
|
||||||
assert mock_bridge.mock_calls[0][1][0] == '192.168.1.10'
|
assert mock_bridge.mock_calls[0][1][0] == '192.168.1.10'
|
||||||
assert len(hass.data[hue.DOMAIN]) == 1
|
hass.data[hue.DOMAIN] = {'192.168.1.10': {}}
|
||||||
|
|
||||||
mock_bridge.reset_mock()
|
mock_bridge.reset_mock()
|
||||||
|
|
||||||
|
@ -59,7 +57,6 @@ async def test_bridge_configure_and_discovered(hass, mock_bridge):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(mock_bridge.mock_calls) == 0
|
assert len(mock_bridge.mock_calls) == 0
|
||||||
assert len(hass.data[hue.DOMAIN]) == 1
|
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_no_host(hass, aioclient_mock):
|
async def test_setup_no_host(hass, aioclient_mock):
|
||||||
|
@ -71,4 +68,3 @@ async def test_setup_no_host(hass, aioclient_mock):
|
||||||
assert result
|
assert result
|
||||||
|
|
||||||
assert len(aioclient_mock.mock_calls) == 1
|
assert len(aioclient_mock.mock_calls) == 1
|
||||||
assert len(hass.data[hue.DOMAIN]) == 0
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue