diff --git a/homeassistant/components/opendisplay/__init__.py b/homeassistant/components/opendisplay/__init__.py index 4fcc7c95d0a2..fb695f84ab49 100644 --- a/homeassistant/components/opendisplay/__init__.py +++ b/homeassistant/components/opendisplay/__init__.py @@ -15,7 +15,11 @@ from opendisplay import ( OpenDisplayError, ) -from homeassistant.components.bluetooth import async_ble_device_from_address +from homeassistant.components.bluetooth import ( + BluetoothReachabilityIntent, + async_address_reachability_diagnostics, + async_ble_device_from_address, +) from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant @@ -83,9 +87,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: OpenDisplayConfigEntry) ble_device = async_ble_device_from_address(hass, address, connectable=True) if ble_device is None: raise ConfigEntryNotReady( - f"Could not find OpenDisplay device with address {address}" + translation_domain=DOMAIN, + translation_key="device_not_found", + translation_placeholders={ + "address": address, + "reason": async_address_reachability_diagnostics( + hass, + address.upper(), + BluetoothReachabilityIntent.CONNECTION, + ), + }, ) - encryption_key = _get_encryption_key(entry) try: diff --git a/homeassistant/components/opendisplay/services.py b/homeassistant/components/opendisplay/services.py index 9bbf17d51775..c5a7824c39ae 100644 --- a/homeassistant/components/opendisplay/services.py +++ b/homeassistant/components/opendisplay/services.py @@ -22,7 +22,11 @@ from opendisplay import ( from PIL import Image as PILImage, ImageOps import voluptuous as vol -from homeassistant.components.bluetooth import async_ble_device_from_address +from homeassistant.components.bluetooth import ( + BluetoothReachabilityIntent, + async_address_reachability_diagnostics, + async_ble_device_from_address, +) from homeassistant.components.http.auth import async_sign_path from homeassistant.components.media_source import async_resolve_media from homeassistant.config_entries import ConfigEntryState @@ -108,7 +112,7 @@ def _get_entry_for_device(call: ServiceCall) -> OpenDisplayConfigEntry: if entry is None or entry.state is not ConfigEntryState.LOADED: raise ServiceValidationError( translation_domain=DOMAIN, - translation_key="device_not_found", + translation_key="config_entry_not_found", translation_placeholders={"address": mac_address}, ) @@ -171,7 +175,14 @@ async def _async_upload_image(call: ServiceCall) -> None: raise HomeAssistantError( translation_domain=DOMAIN, translation_key="device_not_found", - translation_placeholders={"address": address}, + translation_placeholders={ + "address": address, + "reason": async_address_reachability_diagnostics( + call.hass, + address.upper(), + BluetoothReachabilityIntent.CONNECTION, + ), + }, ) current = asyncio.current_task() diff --git a/homeassistant/components/opendisplay/strings.json b/homeassistant/components/opendisplay/strings.json index 0d3e8e92cd21..90eb2b716afa 100644 --- a/homeassistant/components/opendisplay/strings.json +++ b/homeassistant/components/opendisplay/strings.json @@ -74,8 +74,11 @@ "authentication_error": { "message": "Authentication failed. Please update the encryption key." }, + "config_entry_not_found": { + "message": "Config entry not found: `{address}`" + }, "device_not_found": { - "message": "Could not find Bluetooth device with address `{address}`." + "message": "Could not find Bluetooth device with address `{address}`. Reason: {reason}" }, "invalid_device_id": { "message": "Device `{device_id}` is not a valid OpenDisplay device."