mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Hue tweak registered device type + discovery exception (#25977)
* Include location name in create user * Guard against no host in context * Fix tests and typing
This commit is contained in:
parent
6c292846be
commit
57ef721d5d
@ -458,7 +458,7 @@ class AuthManager:
|
|||||||
result["data"]
|
result["data"]
|
||||||
)
|
)
|
||||||
|
|
||||||
if flow.context is not None and flow.context.get("credential_only"):
|
if flow.context.get("credential_only"):
|
||||||
result["result"] = credentials
|
result["result"] = credentials
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ async def get_bridge(hass, host, username=None):
|
|||||||
with async_timeout.timeout(10):
|
with async_timeout.timeout(10):
|
||||||
# Create username if we don't have one
|
# Create username if we don't have one
|
||||||
if not username:
|
if not username:
|
||||||
await bridge.create_user("home-assistant")
|
await bridge.create_user(f"home-assistant#{hass.config.location_name}")
|
||||||
# Initialize bridge (and validate our username)
|
# Initialize bridge (and validate our username)
|
||||||
await bridge.initialize()
|
await bridge.initialize()
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ class HueFlowHandler(config_entries.ConfigFlow):
|
|||||||
async def async_step_init(self, user_input=None):
|
async def async_step_init(self, user_input=None):
|
||||||
"""Handle a flow start."""
|
"""Handle a flow start."""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
self.host = user_input["host"]
|
self.host = self.context["host"] = user_input["host"]
|
||||||
return await self.async_step_link()
|
return await self.async_step_link()
|
||||||
|
|
||||||
websession = aiohttp_client.async_get_clientsession(self.hass)
|
websession = aiohttp_client.async_get_clientsession(self.hass)
|
||||||
@ -141,10 +141,11 @@ class HueFlowHandler(config_entries.ConfigFlow):
|
|||||||
if "HASS Bridge" in discovery_info.get("name", ""):
|
if "HASS Bridge" in discovery_info.get("name", ""):
|
||||||
return self.async_abort(reason="already_configured")
|
return self.async_abort(reason="already_configured")
|
||||||
|
|
||||||
# pylint: disable=unsupported-assignment-operation
|
|
||||||
host = self.context["host"] = discovery_info.get("host")
|
host = self.context["host"] = discovery_info.get("host")
|
||||||
|
|
||||||
if any(host == flow["context"]["host"] for flow in self._async_in_progress()):
|
if any(
|
||||||
|
host == flow["context"].get("host") for flow in self._async_in_progress()
|
||||||
|
):
|
||||||
return self.async_abort(reason="already_in_progress")
|
return self.async_abort(reason="already_in_progress")
|
||||||
|
|
||||||
if host in configured_hosts(self.hass):
|
if host in configured_hosts(self.hass):
|
||||||
@ -166,10 +167,11 @@ class HueFlowHandler(config_entries.ConfigFlow):
|
|||||||
|
|
||||||
async def async_step_homekit(self, homekit_info):
|
async def async_step_homekit(self, homekit_info):
|
||||||
"""Handle HomeKit discovery."""
|
"""Handle HomeKit discovery."""
|
||||||
# pylint: disable=unsupported-assignment-operation
|
|
||||||
host = self.context["host"] = homekit_info.get("host")
|
host = self.context["host"] = homekit_info.get("host")
|
||||||
|
|
||||||
if any(host == flow["context"]["host"] for flow in self._async_in_progress()):
|
if any(
|
||||||
|
host == flow["context"].get("host") for flow in self._async_in_progress()
|
||||||
|
):
|
||||||
return self.async_abort(reason="already_in_progress")
|
return self.async_abort(reason="already_in_progress")
|
||||||
|
|
||||||
if host in configured_hosts(self.hass):
|
if host in configured_hosts(self.hass):
|
||||||
@ -192,7 +194,7 @@ class HueFlowHandler(config_entries.ConfigFlow):
|
|||||||
and create an entry. Otherwise we will delegate to `link` step which
|
and create an entry. Otherwise we will delegate to `link` step which
|
||||||
will ask user to link the bridge.
|
will ask user to link the bridge.
|
||||||
"""
|
"""
|
||||||
host = import_info["host"]
|
host = self.context["host"] = import_info["host"]
|
||||||
path = import_info.get("path")
|
path = import_info.get("path")
|
||||||
|
|
||||||
if path is not None:
|
if path is not None:
|
||||||
|
@ -179,7 +179,7 @@ class FlowHandler:
|
|||||||
hass: Optional[HomeAssistant] = None
|
hass: Optional[HomeAssistant] = None
|
||||||
handler = None
|
handler = None
|
||||||
cur_step: Optional[Dict[str, str]] = None
|
cur_step: Optional[Dict[str, str]] = None
|
||||||
context: Optional[Dict] = None
|
context: Dict
|
||||||
|
|
||||||
# Set by _async_create_flow callback
|
# Set by _async_create_flow callback
|
||||||
init_step = "init"
|
init_step = "init"
|
||||||
|
@ -255,6 +255,7 @@ async def test_import_with_existing_config(hass):
|
|||||||
"""Test importing a host with an existing config file."""
|
"""Test importing a host with an existing config file."""
|
||||||
flow = config_flow.HueFlowHandler()
|
flow = config_flow.HueFlowHandler()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
flow.context = {}
|
||||||
|
|
||||||
bridge = Mock()
|
bridge = Mock()
|
||||||
bridge.username = "username-abc"
|
bridge.username = "username-abc"
|
||||||
@ -280,6 +281,7 @@ async def test_import_with_no_config(hass):
|
|||||||
"""Test importing a host without an existing config file."""
|
"""Test importing a host without an existing config file."""
|
||||||
flow = config_flow.HueFlowHandler()
|
flow = config_flow.HueFlowHandler()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
flow.context = {}
|
||||||
|
|
||||||
with patch.object(
|
with patch.object(
|
||||||
config_flow, "get_bridge", side_effect=errors.AuthenticationRequired
|
config_flow, "get_bridge", side_effect=errors.AuthenticationRequired
|
||||||
@ -294,6 +296,7 @@ async def test_import_with_existing_but_invalid_config(hass):
|
|||||||
"""Test importing a host with a config file with invalid username."""
|
"""Test importing a host with a config file with invalid username."""
|
||||||
flow = config_flow.HueFlowHandler()
|
flow = config_flow.HueFlowHandler()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
flow.context = {}
|
||||||
|
|
||||||
with patch.object(
|
with patch.object(
|
||||||
config_flow, "_find_username_from_config", return_value="mock-user"
|
config_flow, "_find_username_from_config", return_value="mock-user"
|
||||||
@ -310,6 +313,7 @@ async def test_import_cannot_connect(hass):
|
|||||||
"""Test importing a host that we cannot conncet to."""
|
"""Test importing a host that we cannot conncet to."""
|
||||||
flow = config_flow.HueFlowHandler()
|
flow = config_flow.HueFlowHandler()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
flow.context = {}
|
||||||
|
|
||||||
with patch.object(config_flow, "get_bridge", side_effect=errors.CannotConnect):
|
with patch.object(config_flow, "get_bridge", side_effect=errors.CannotConnect):
|
||||||
result = await flow.async_step_import({"host": "0.0.0.0"})
|
result = await flow.async_step_import({"host": "0.0.0.0"})
|
||||||
@ -337,6 +341,7 @@ async def test_creating_entry_removes_entries_for_same_host_or_bridge(hass):
|
|||||||
|
|
||||||
flow = config_flow.HueFlowHandler()
|
flow = config_flow.HueFlowHandler()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
flow.context = {}
|
||||||
|
|
||||||
bridge = Mock()
|
bridge = Mock()
|
||||||
bridge.username = "username-abc"
|
bridge.username = "username-abc"
|
||||||
|
@ -80,6 +80,7 @@ async def test_discovery_single_instance(hass, discovery_flow_conf, source):
|
|||||||
"""Test we not allow duplicates."""
|
"""Test we not allow duplicates."""
|
||||||
flow = config_entries.HANDLERS["test"]()
|
flow = config_entries.HANDLERS["test"]()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
flow.context = {}
|
||||||
|
|
||||||
MockConfigEntry(domain="test").add_to_hass(hass)
|
MockConfigEntry(domain="test").add_to_hass(hass)
|
||||||
result = await getattr(flow, "async_step_{}".format(source))({})
|
result = await getattr(flow, "async_step_{}".format(source))({})
|
||||||
@ -93,6 +94,7 @@ async def test_discovery_confirmation(hass, discovery_flow_conf, source):
|
|||||||
"""Test we ask for confirmation via discovery."""
|
"""Test we ask for confirmation via discovery."""
|
||||||
flow = config_entries.HANDLERS["test"]()
|
flow = config_entries.HANDLERS["test"]()
|
||||||
flow.hass = hass
|
flow.hass = hass
|
||||||
|
flow.context = {}
|
||||||
|
|
||||||
result = await getattr(flow, "async_step_{}".format(source))({})
|
result = await getattr(flow, "async_step_{}".format(source))({})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user