Skip to content

Commit

Permalink
Fix hue retry crash (#21083)
Browse files Browse the repository at this point in the history
* Fix Hue retry crash

* Fix hue retry crash

* Fix tests
  • Loading branch information
balloob committed Feb 15, 2019
1 parent 2de65af commit da672c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions homeassistant/components/hue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
CONF_ALLOW_UNREACHABLE = 'allow_unreachable'
DEFAULT_ALLOW_UNREACHABLE = False

DATA_CONFIGS = 'hue_configs'

PHUE_CONFIG_FILE = 'phue.conf'

CONF_ALLOW_HUE_GROUPS = "allow_hue_groups"
Expand Down Expand Up @@ -59,6 +61,7 @@ async def async_setup(hass, config):
conf = {}

hass.data[DOMAIN] = {}
hass.data[DATA_CONFIGS] = {}
configured = configured_hosts(hass)

# User has configured bridges
Expand All @@ -71,7 +74,7 @@ async def async_setup(hass, config):
host = bridge_conf[CONF_HOST]

# Store config in hass.data so the config entry can find it
hass.data[DOMAIN][host] = bridge_conf
hass.data[DATA_CONFIGS][host] = bridge_conf

# If configured, the bridge will be set up during config entry phase
if host in configured:
Expand All @@ -96,7 +99,7 @@ async def async_setup(hass, config):
async def async_setup_entry(hass, entry):
"""Set up a bridge from a config entry."""
host = entry.data['host']
config = hass.data[DOMAIN].get(host)
config = hass.data[DATA_CONFIGS].get(host)

if config is None:
allow_unreachable = DEFAULT_ALLOW_UNREACHABLE
Expand All @@ -106,11 +109,11 @@ async def async_setup_entry(hass, entry):
allow_groups = config[CONF_ALLOW_HUE_GROUPS]

bridge = HueBridge(hass, entry, allow_unreachable, allow_groups)
hass.data[DOMAIN][host] = bridge

if not await bridge.async_setup():
return False

hass.data[DOMAIN][host] = bridge
config = bridge.api.config
device_registry = await dr.async_get_registry(hass)
device_registry.async_get_or_create(
Expand Down
4 changes: 2 additions & 2 deletions tests/components/hue/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def test_setup_defined_hosts_known_auth(hass):
assert len(mock_config_entries.flow.mock_calls) == 0

# Config stored for domain.
assert hass.data[hue.DOMAIN] == {
assert hass.data[hue.DATA_CONFIGS] == {
'0.0.0.0': {
hue.CONF_HOST: '0.0.0.0',
hue.CONF_FILENAME: 'bla.conf',
Expand Down Expand Up @@ -73,7 +73,7 @@ async def test_setup_defined_hosts_no_known_auth(hass):
}

# Config stored for domain.
assert hass.data[hue.DOMAIN] == {
assert hass.data[hue.DATA_CONFIGS] == {
'0.0.0.0': {
hue.CONF_HOST: '0.0.0.0',
hue.CONF_FILENAME: 'bla.conf',
Expand Down

0 comments on commit da672c6

Please sign in to comment.