mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Enhance title placeholders in gardena_bluetooth config flow (#173442)
Co-authored-by: Joostlek <joostlek@outlook.com>
This commit is contained in:
co-authored by
Joostlek
parent
377054bb0b
commit
7affea9b5f
@@ -76,6 +76,14 @@ class GardenaBluetoothConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
return self.async_abort(reason="no_devices_found")
|
||||
|
||||
self.address = discovery_info.address
|
||||
self.context["title_placeholders"] = {
|
||||
"name": PRODUCT_NAMES[mfg.product_type],
|
||||
"identifier": (
|
||||
f"{discovery_info.name}, {discovery_info.address}"
|
||||
if discovery_info.name != discovery_info.address
|
||||
else discovery_info.address
|
||||
),
|
||||
}
|
||||
return await self.async_step_confirm()
|
||||
|
||||
async def async_step_confirm(
|
||||
@@ -83,16 +91,12 @@ class GardenaBluetoothConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
) -> ConfigFlowResult:
|
||||
"""Confirm discovery."""
|
||||
assert self.address
|
||||
title = PRODUCT_NAMES[self.devices[self.address].product_type]
|
||||
title = self.context["title_placeholders"]["name"]
|
||||
|
||||
if user_input is not None:
|
||||
data = await self.async_read_data()
|
||||
return self.async_create_entry(title=title, data=data)
|
||||
|
||||
self.context["title_placeholders"] = {
|
||||
"name": title,
|
||||
}
|
||||
|
||||
self._set_confirm_only()
|
||||
return self.async_show_form(
|
||||
step_id="confirm",
|
||||
@@ -106,6 +110,12 @@ class GardenaBluetoothConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle the initial step."""
|
||||
if user_input is not None:
|
||||
self.address = user_input[CONF_ADDRESS]
|
||||
self.context["title_placeholders"] = {
|
||||
"name": PRODUCT_NAMES[
|
||||
self.devices[user_input[CONF_ADDRESS]].product_type
|
||||
],
|
||||
"identifier": user_input[CONF_ADDRESS],
|
||||
}
|
||||
await self.async_set_unique_id(self.address, raise_on_progress=False)
|
||||
self._abort_if_unique_id_configured()
|
||||
return await self.async_step_confirm()
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
"error": {
|
||||
"cannot_connect": "Failed to connect: {error}"
|
||||
},
|
||||
"flow_title": "{name} ({identifier})",
|
||||
"step": {
|
||||
"confirm": {
|
||||
"description": "Do you want to set up {name}?\n\nBefore you continue, make sure the device is in pairing mode."
|
||||
"description": "Do you want to set up {name} ({identifier})?\n\nBefore you continue, make sure the device is in pairing mode."
|
||||
},
|
||||
"user": {
|
||||
"data": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# serializer version: 1
|
||||
# name: test_bluetooth
|
||||
# name: test_bluetooth[service_info0]
|
||||
FlowResultSnapshot({
|
||||
'context': dict({
|
||||
'confirm_only': True,
|
||||
@@ -10,6 +10,7 @@
|
||||
}),
|
||||
'source': 'bluetooth',
|
||||
'title_placeholders': dict({
|
||||
'identifier': 'Timer, 00000000-0000-0000-0000-000000000001',
|
||||
'name': 'Gardena Water Computer',
|
||||
}),
|
||||
'unique_id': '00000000-0000-0000-0000-000000000001',
|
||||
@@ -19,7 +20,7 @@
|
||||
'step_id': 'confirm',
|
||||
})
|
||||
# ---
|
||||
# name: test_bluetooth.1
|
||||
# name: test_bluetooth[service_info0].1
|
||||
FlowResultSnapshot({
|
||||
'context': dict({
|
||||
'confirm_only': True,
|
||||
@@ -31,6 +32,7 @@
|
||||
'dismiss_protected': True,
|
||||
'source': 'bluetooth',
|
||||
'title_placeholders': dict({
|
||||
'identifier': 'Timer, 00000000-0000-0000-0000-000000000001',
|
||||
'name': 'Gardena Water Computer',
|
||||
}),
|
||||
'unique_id': '00000000-0000-0000-0000-000000000001',
|
||||
@@ -82,6 +84,91 @@
|
||||
'version': 1,
|
||||
})
|
||||
# ---
|
||||
# name: test_bluetooth[service_info1]
|
||||
FlowResultSnapshot({
|
||||
'context': dict({
|
||||
'confirm_only': True,
|
||||
'discovery_key': dict({
|
||||
'domain': 'bluetooth',
|
||||
'key': '00000000-0000-0000-0000-000000000002',
|
||||
'version': 1,
|
||||
}),
|
||||
'source': 'bluetooth',
|
||||
'title_placeholders': dict({
|
||||
'identifier': '00000000-0000-0000-0000-000000000002',
|
||||
'name': 'Gardena Water Computer',
|
||||
}),
|
||||
'unique_id': '00000000-0000-0000-0000-000000000002',
|
||||
}),
|
||||
'flow_id': <ANY>,
|
||||
'handler': 'gardena_bluetooth',
|
||||
'step_id': 'confirm',
|
||||
})
|
||||
# ---
|
||||
# name: test_bluetooth[service_info1].1
|
||||
FlowResultSnapshot({
|
||||
'context': dict({
|
||||
'confirm_only': True,
|
||||
'discovery_key': dict({
|
||||
'domain': 'bluetooth',
|
||||
'key': '00000000-0000-0000-0000-000000000002',
|
||||
'version': 1,
|
||||
}),
|
||||
'dismiss_protected': True,
|
||||
'source': 'bluetooth',
|
||||
'title_placeholders': dict({
|
||||
'identifier': '00000000-0000-0000-0000-000000000002',
|
||||
'name': 'Gardena Water Computer',
|
||||
}),
|
||||
'unique_id': '00000000-0000-0000-0000-000000000002',
|
||||
}),
|
||||
'data': dict({
|
||||
'address': '00000000-0000-0000-0000-000000000002',
|
||||
'product_type': 'WATER_COMPUTER',
|
||||
}),
|
||||
'description': None,
|
||||
'description_placeholders': None,
|
||||
'flow_id': <ANY>,
|
||||
'handler': 'gardena_bluetooth',
|
||||
'minor_version': 2,
|
||||
'options': dict({
|
||||
}),
|
||||
'result': ConfigEntrySnapshot({
|
||||
'data': dict({
|
||||
'address': '00000000-0000-0000-0000-000000000002',
|
||||
'product_type': 'WATER_COMPUTER',
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'discovery_keys': dict({
|
||||
'bluetooth': tuple(
|
||||
dict({
|
||||
'domain': 'bluetooth',
|
||||
'key': '00000000-0000-0000-0000-000000000002',
|
||||
'version': 1,
|
||||
}),
|
||||
),
|
||||
}),
|
||||
'domain': 'gardena_bluetooth',
|
||||
'entry_id': <ANY>,
|
||||
'minor_version': 2,
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'bluetooth',
|
||||
'subentries': list([
|
||||
]),
|
||||
'title': 'Gardena Water Computer',
|
||||
'unique_id': '00000000-0000-0000-0000-000000000002',
|
||||
'version': 1,
|
||||
}),
|
||||
'subentries': tuple(
|
||||
),
|
||||
'title': 'Gardena Water Computer',
|
||||
'type': <FlowResultType.CREATE_ENTRY: 'create_entry'>,
|
||||
'version': 1,
|
||||
})
|
||||
# ---
|
||||
# name: test_bluetooth_invalid
|
||||
FlowResultSnapshot({
|
||||
'description_placeholders': None,
|
||||
@@ -120,6 +207,7 @@
|
||||
FlowResultSnapshot({
|
||||
'data_schema': None,
|
||||
'description_placeholders': dict({
|
||||
'identifier': '00000000-0000-0000-0000-000000000001',
|
||||
'name': 'Gardena Water Computer',
|
||||
}),
|
||||
'errors': None,
|
||||
@@ -175,6 +263,7 @@
|
||||
FlowResultSnapshot({
|
||||
'data_schema': None,
|
||||
'description_placeholders': dict({
|
||||
'identifier': '00000000-0000-0000-0000-000000000001',
|
||||
'name': 'Gardena Water Computer',
|
||||
}),
|
||||
'errors': None,
|
||||
@@ -192,6 +281,7 @@
|
||||
'confirm_only': True,
|
||||
'source': 'user',
|
||||
'title_placeholders': dict({
|
||||
'identifier': '00000000-0000-0000-0000-000000000001',
|
||||
'name': 'Gardena Water Computer',
|
||||
}),
|
||||
'unique_id': '00000000-0000-0000-0000-000000000001',
|
||||
|
||||
@@ -12,6 +12,7 @@ from homeassistant.components.gardena_bluetooth.const import DOMAIN
|
||||
from homeassistant.const import CONF_ADDRESS
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.helpers.service_info.bluetooth import BluetoothServiceInfo
|
||||
|
||||
from . import (
|
||||
MISSING_MANUFACTURER_DATA_SERVICE_INFO,
|
||||
@@ -163,14 +164,16 @@ async def test_no_devices_at_all(
|
||||
assert result.get("reason") == "no_devices_found"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("service_info"), [WATER_TIMER_SERVICE_INFO, WATER_TIMER_UNNAMED_SERVICE_INFO]
|
||||
)
|
||||
async def test_bluetooth(
|
||||
hass: HomeAssistant,
|
||||
snapshot: SnapshotAssertion,
|
||||
hass: HomeAssistant, snapshot: SnapshotAssertion, service_info: BluetoothServiceInfo
|
||||
) -> None:
|
||||
"""Test bluetooth device discovery."""
|
||||
|
||||
# Inject the service info will trigger the flow to start
|
||||
inject_bluetooth_service_info(hass, WATER_TIMER_SERVICE_INFO)
|
||||
inject_bluetooth_service_info(hass, service_info)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
result = next(iter(hass.config_entries.flow.async_progress_by_handler(DOMAIN)))
|
||||
|
||||
Reference in New Issue
Block a user