diff --git a/custom_components/hunterdouglas_powerview_ble/config_flow.py b/custom_components/hunterdouglas_powerview_ble/config_flow.py index 60e3f8d..cac7dc8 100644 --- a/custom_components/hunterdouglas_powerview_ble/config_flow.py +++ b/custom_components/hunterdouglas_powerview_ble/config_flow.py @@ -2,6 +2,7 @@ import asyncio import base64 +import contextlib from dataclasses import dataclass import struct from typing import Any @@ -372,12 +373,23 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): async def async_step_user( self, user_input: dict[str, Any] | None = None ) -> ConfigFlowResult: - """Handle the user step — reuse existing key or collect one.""" + """Handle the user step — reuse existing key or offer a menu.""" LOGGER.debug("user step") existing = self._existing_home_key() if existing: self._home_key = existing - return await self.async_step_select_device() + self._hub_url = self._hub_url or self._existing_entry_value("hub_url") + if self._hub_url and not self._hub_shades: + with contextlib.suppress( + TimeoutError, aiohttp.ClientError, ValueError + ): + self._hub_shades = await _fetch_shades_from_hub( + self.hass, self._hub_url + ) + return self.async_show_menu( + step_id="user", + menu_options=["select_device", "manual"], + ) return await self.async_step_homekey() def _build_selected_entries( diff --git a/custom_components/hunterdouglas_powerview_ble/strings.json b/custom_components/hunterdouglas_powerview_ble/strings.json index 617cc2e..b638f96 100644 --- a/custom_components/hunterdouglas_powerview_ble/strings.json +++ b/custom_components/hunterdouglas_powerview_ble/strings.json @@ -2,6 +2,17 @@ "config": { "flow_title": "Setup {name}", "step": { + "user": { + "title": "Add PowerView Shade", + "menu_options": { + "select_device": "Select from discovered shades", + "manual": "Enter device details manually" + }, + "menu_option_descriptions": { + "select_device": "Choose from shades detected via Bluetooth nearby.", + "manual": "Enter a Bluetooth MAC address and device name directly, for example if a shade is out of range of discovery." + } + }, "bluetooth_confirm": { "description": "[%key:component::bluetooth::config::step::bluetooth_confirm::description%]" }, @@ -43,7 +54,7 @@ }, "manual": { "title": "Enter Device Details", - "description": "No PowerView shades were found via Bluetooth. Enter the device details manually.", + "description": "Enter the device details manually.", "data": { "address": "Bluetooth MAC address (e.g. AA:BB:CC:DD:EE:FF)", "ble_name": "BLE device name (e.g. DUE:94ED)" diff --git a/custom_components/hunterdouglas_powerview_ble/translations/en.json b/custom_components/hunterdouglas_powerview_ble/translations/en.json index 101a408..5164bc8 100644 --- a/custom_components/hunterdouglas_powerview_ble/translations/en.json +++ b/custom_components/hunterdouglas_powerview_ble/translations/en.json @@ -2,6 +2,17 @@ "config": { "flow_title": "Setup {name}", "step": { + "user": { + "title": "Add PowerView Shade", + "menu_options": { + "select_device": "Select from discovered shades", + "manual": "Enter device details manually" + }, + "menu_option_descriptions": { + "select_device": "Choose from shades detected via Bluetooth nearby.", + "manual": "Enter a Bluetooth MAC address and device name directly, for example if a shade is out of range of discovery." + } + }, "bluetooth_confirm": { "description": "Do you want to set up {name}?" }, @@ -40,7 +51,7 @@ }, "manual": { "title": "Enter Device Details", - "description": "No PowerView shades were found via Bluetooth. Enter the device details manually.", + "description": "Enter the device details manually.", "data": { "address": "Bluetooth MAC address (e.g. AA:BB:CC:DD:EE:FF)", "ble_name": "BLE device name (e.g. DUE:94ED)"