Add reason for unvailability to opendisplay (#172909)

This commit is contained in:
Josef Zweck
2026-06-03 19:48:56 +02:00
committed by GitHub
parent 8ba3e6c8c1
commit 2e041dd45f
3 changed files with 33 additions and 7 deletions
@@ -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:
@@ -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()
@@ -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."