Skip to content

Commit

Permalink
Fix controller not being stored when setup fails and sequentially fai…
Browse files Browse the repository at this point in the history
…ls the retry functionality (#17927)
  • Loading branch information
Kane610 authored and balloob committed Oct 29, 2018
1 parent 98dfbf2 commit b03e605
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions homeassistant/components/unifi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,21 @@ async def async_setup(hass, config):

async def async_setup_entry(hass, config_entry):
"""Set up the UniFi component."""
controller = UniFiController(hass, config_entry)

if DOMAIN not in hass.data:
hass.data[DOMAIN] = {}

controller = UniFiController(hass, config_entry)

controller_id = CONTROLLER_ID.format(
host=config_entry.data[CONF_CONTROLLER][CONF_HOST],
site=config_entry.data[CONF_CONTROLLER][CONF_SITE_ID]
)

hass.data[DOMAIN][controller_id] = controller

if not await controller.async_setup():
return False

hass.data[DOMAIN][controller_id] = controller

if controller.mac is None:
return True

Expand Down
4 changes: 2 additions & 2 deletions tests/components/unifi/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def test_successful_config_entry(hass):


async def test_controller_fail_setup(hass):
"""Test that configured options for a host are loaded via config entry."""
"""Test that a failed setup still stores controller."""
entry = MockConfigEntry(domain=unifi.DOMAIN, data={
'controller': {
'host': '0.0.0.0',
Expand All @@ -75,7 +75,7 @@ async def test_controller_fail_setup(hass):
controller_id = unifi.CONTROLLER_ID.format(
host='0.0.0.0', site='default'
)
assert controller_id not in hass.data[unifi.DOMAIN]
assert controller_id in hass.data[unifi.DOMAIN]


async def test_controller_no_mac(hass):
Expand Down

0 comments on commit b03e605

Please sign in to comment.