mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Fix hue retry crash (#21083)
* Fix Hue retry crash * Fix hue retry crash * Fix tests
This commit is contained in:
parent
93f84a5cd1
commit
1130ccb325
@ -23,6 +23,8 @@ CONF_BRIDGES = "bridges"
|
|||||||
CONF_ALLOW_UNREACHABLE = 'allow_unreachable'
|
CONF_ALLOW_UNREACHABLE = 'allow_unreachable'
|
||||||
DEFAULT_ALLOW_UNREACHABLE = False
|
DEFAULT_ALLOW_UNREACHABLE = False
|
||||||
|
|
||||||
|
DATA_CONFIGS = 'hue_configs'
|
||||||
|
|
||||||
PHUE_CONFIG_FILE = 'phue.conf'
|
PHUE_CONFIG_FILE = 'phue.conf'
|
||||||
|
|
||||||
CONF_ALLOW_HUE_GROUPS = "allow_hue_groups"
|
CONF_ALLOW_HUE_GROUPS = "allow_hue_groups"
|
||||||
@ -54,6 +56,7 @@ async def async_setup(hass, config):
|
|||||||
conf = {}
|
conf = {}
|
||||||
|
|
||||||
hass.data[DOMAIN] = {}
|
hass.data[DOMAIN] = {}
|
||||||
|
hass.data[DATA_CONFIGS] = {}
|
||||||
configured = configured_hosts(hass)
|
configured = configured_hosts(hass)
|
||||||
|
|
||||||
# User has configured bridges
|
# User has configured bridges
|
||||||
@ -66,7 +69,7 @@ async def async_setup(hass, config):
|
|||||||
host = bridge_conf[CONF_HOST]
|
host = bridge_conf[CONF_HOST]
|
||||||
|
|
||||||
# Store config in hass.data so the config entry can find it
|
# 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 configured, the bridge will be set up during config entry phase
|
||||||
if host in configured:
|
if host in configured:
|
||||||
@ -91,7 +94,7 @@ async def async_setup(hass, config):
|
|||||||
async def async_setup_entry(hass, entry):
|
async def async_setup_entry(hass, entry):
|
||||||
"""Set up a bridge from a config entry."""
|
"""Set up a bridge from a config entry."""
|
||||||
host = entry.data['host']
|
host = entry.data['host']
|
||||||
config = hass.data[DOMAIN].get(host)
|
config = hass.data[DATA_CONFIGS].get(host)
|
||||||
|
|
||||||
if config is None:
|
if config is None:
|
||||||
allow_unreachable = DEFAULT_ALLOW_UNREACHABLE
|
allow_unreachable = DEFAULT_ALLOW_UNREACHABLE
|
||||||
@ -101,11 +104,11 @@ async def async_setup_entry(hass, entry):
|
|||||||
allow_groups = config[CONF_ALLOW_HUE_GROUPS]
|
allow_groups = config[CONF_ALLOW_HUE_GROUPS]
|
||||||
|
|
||||||
bridge = HueBridge(hass, entry, allow_unreachable, allow_groups)
|
bridge = HueBridge(hass, entry, allow_unreachable, allow_groups)
|
||||||
hass.data[DOMAIN][host] = bridge
|
|
||||||
|
|
||||||
if not await bridge.async_setup():
|
if not await bridge.async_setup():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
hass.data[DOMAIN][host] = bridge
|
||||||
config = bridge.api.config
|
config = bridge.api.config
|
||||||
device_registry = await dr.async_get_registry(hass)
|
device_registry = await dr.async_get_registry(hass)
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
|
@ -39,7 +39,7 @@ async def test_setup_defined_hosts_known_auth(hass):
|
|||||||
assert len(mock_config_entries.flow.mock_calls) == 0
|
assert len(mock_config_entries.flow.mock_calls) == 0
|
||||||
|
|
||||||
# Config stored for domain.
|
# Config stored for domain.
|
||||||
assert hass.data[hue.DOMAIN] == {
|
assert hass.data[hue.DATA_CONFIGS] == {
|
||||||
'0.0.0.0': {
|
'0.0.0.0': {
|
||||||
hue.CONF_HOST: '0.0.0.0',
|
hue.CONF_HOST: '0.0.0.0',
|
||||||
hue.CONF_FILENAME: 'bla.conf',
|
hue.CONF_FILENAME: 'bla.conf',
|
||||||
@ -73,7 +73,7 @@ async def test_setup_defined_hosts_no_known_auth(hass):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Config stored for domain.
|
# Config stored for domain.
|
||||||
assert hass.data[hue.DOMAIN] == {
|
assert hass.data[hue.DATA_CONFIGS] == {
|
||||||
'0.0.0.0': {
|
'0.0.0.0': {
|
||||||
hue.CONF_HOST: '0.0.0.0',
|
hue.CONF_HOST: '0.0.0.0',
|
||||||
hue.CONF_FILENAME: 'bla.conf',
|
hue.CONF_FILENAME: 'bla.conf',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user