Skip to content

Commit e769f60

Browse files
committed
Fix hassfest validation and add bluetooth discovery confirm step
- Replace leftover integration_blueprint boilerplate in translations/en.json that contained a URL (rejected by hassfest) and described a non-existent username/password flow; align strings with the actual bluetooth flow. - Require user confirmation for bluetooth-discovered devices via a new async_step_bluetooth_confirm instead of silently creating the entry, and use the device name for the title and discovery card. - Use no_devices_found abort key and correct the documentation/issue_tracker URLs in manifest.json to point at the ha-run-chicken repo.
1 parent d68d313 commit e769f60

3 files changed

Lines changed: 35 additions & 24 deletions

File tree

custom_components/run_chicken/config_flow.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
from typing import TYPE_CHECKING, Any
77

88
import voluptuous as vol
9-
from homeassistant.components.bluetooth import (
10-
BluetoothServiceInfo,
11-
async_discovered_service_info,
12-
)
9+
from homeassistant.components.bluetooth import async_discovered_service_info
1310
from homeassistant.config_entries import ConfigFlow
1411
from homeassistant.const import CONF_ADDRESS
1512

1613
from .const import DOMAIN, MANUFACTURER_ID
1714

1815
if TYPE_CHECKING:
16+
from homeassistant.components.bluetooth import BluetoothServiceInfoBleak
1917
from homeassistant.data_entry_flow import FlowResult
2018

2119
_LOGGER = logging.getLogger(__name__)
@@ -26,19 +24,32 @@ class RunChickenConfigFlow(ConfigFlow, domain=DOMAIN):
2624

2725
VERSION = 1
2826

29-
async def async_step_bluetooth(self, discovery_info: BluetoothServiceInfo) -> FlowResult:
30-
"""Handle a bluetooth discovery. Add immediately without prompts."""
31-
address = discovery_info.address
27+
_discovery_info: BluetoothServiceInfoBleak
28+
29+
async def async_step_bluetooth(self, discovery_info: BluetoothServiceInfoBleak) -> FlowResult:
30+
"""Handle a bluetooth discovery and ask the user to confirm."""
3231
if MANUFACTURER_ID not in discovery_info.manufacturer_data:
3332
return self.async_abort(reason="not_run_chicken_device")
3433

35-
_LOGGER.debug("Bluetooth discovery for Run-Chicken: %s", address)
34+
_LOGGER.debug("Bluetooth discovery for Run-Chicken: %s", discovery_info.address)
3635

37-
await self.async_set_unique_id(address)
36+
await self.async_set_unique_id(discovery_info.address)
3837
self._abort_if_unique_id_configured()
3938

40-
# Create the entry right away; we identify devices by address only
41-
return self.async_create_entry(title=address, data={})
39+
self._discovery_info = discovery_info
40+
self.context["title_placeholders"] = {"name": discovery_info.name}
41+
return await self.async_step_bluetooth_confirm()
42+
43+
async def async_step_bluetooth_confirm(self, user_input: dict[str, Any] | None = None) -> FlowResult:
44+
"""Confirm adding a device discovered over bluetooth."""
45+
if user_input is not None:
46+
return self.async_create_entry(title=self._discovery_info.name, data={})
47+
48+
self._set_confirm_only()
49+
return self.async_show_form(
50+
step_id="bluetooth_confirm",
51+
description_placeholders={"name": self._discovery_info.name},
52+
)
4253

4354
async def async_step_user(self, user_input: dict[str, Any] | None = None) -> FlowResult:
4455
"""Show list of discovered devices (by address) and let user pick one."""
@@ -61,7 +72,7 @@ async def async_step_user(self, user_input: dict[str, Any] | None = None) -> Flo
6172
options[addr] = f"{addr}"
6273

6374
if not options:
64-
return self.async_abort(reason="No devices found")
75+
return self.async_abort(reason="no_devices_found")
6576

6677
schema = vol.Schema({vol.Required(CONF_ADDRESS): vol.In(options)})
6778
return self.async_show_form(step_id="user", data_schema=schema)

custom_components/run_chicken/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
"dependencies": [
1515
"bluetooth_adapters"
1616
],
17-
"documentation": "https://github.com/bkanuka/run_chicken",
17+
"documentation": "https://github.com/bkanuka/ha-run-chicken",
1818
"integration_type": "device",
1919
"iot_class": "local_push",
20-
"issue_tracker": "https://github.com/bkanuka/run_chicken/issues",
20+
"issue_tracker": "https://github.com/bkanuka/ha-run-chicken/issues",
2121
"loggers": [
2222
"run_chicken",
2323
"run_chicken.run_chicken_ble"
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
{
22
"config": {
3+
"flow_title": "{name}",
34
"step": {
45
"user": {
5-
"description": "If you need help with the configuration have a look here: https://github.com/ludeeus/run_chicken",
6+
"description": "Select the Run-Chicken door to add.",
67
"data": {
7-
"username": "Username",
8-
"password": "Password"
8+
"address": "Device"
99
}
10+
},
11+
"bluetooth_confirm": {
12+
"description": "Do you want to set up the Run-Chicken door {name}?"
1013
}
1114
},
12-
"error": {
13-
"auth": "Username/Password is wrong.",
14-
"connection": "Unable to connect to the server.",
15-
"unknown": "Unknown error occurred."
16-
},
1715
"abort": {
18-
"already_configured": "This entry is already configured."
16+
"already_configured": "This device is already configured.",
17+
"not_run_chicken_device": "The discovered device is not a Run-Chicken door.",
18+
"no_devices_found": "No Run-Chicken devices were found."
1919
}
2020
}
21-
}
21+
}

0 commit comments

Comments
 (0)