From ec661ce0ce23405389d06f0ab3564bb0812187fd Mon Sep 17 00:00:00 2001 From: "Sergey V. DUDANOV" Date: Thu, 18 Jul 2024 13:14:14 +0400 Subject: [PATCH] handle disconnect --- custom_components/ftms/__init__.py | 8 +++++--- custom_components/ftms/translations/en.json | 3 +++ custom_components/ftms/translations/ru.json | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/custom_components/ftms/__init__.py b/custom_components/ftms/__init__.py index e5f1a7c..2581eac 100644 --- a/custom_components/ftms/__init__.py +++ b/custom_components/ftms/__init__.py @@ -50,14 +50,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: FtmsConfigEntry) -> bool if not (srv_info := bluetooth.async_last_service_info(hass, mac)): raise ConfigEntryNotReady( translation_key="device_not_found", - translation_placeholders={"address": mac}, + translation_placeholders={CONF_MAC: mac}, ) def _on_disconnect(ftms_: pyftms.FitnessMachine) -> None: """Disconnect handler. Reload entry on disconnect.""" - if ftms_.need_connect: - hass.config_entries.async_schedule_reload(entry.entry_id) + raise ConfigEntryNotReady( + translation_key="device_disconnected", + translation_placeholders={CONF_MAC: mac}, + ) ftms = pyftms.get_client(srv_info.device, srv_info.advertisement) ftms.set_disconnect_callback(_on_disconnect) diff --git a/custom_components/ftms/translations/en.json b/custom_components/ftms/translations/en.json index 9f5bf6a..da0c715 100644 --- a/custom_components/ftms/translations/en.json +++ b/custom_components/ftms/translations/en.json @@ -243,6 +243,9 @@ "device_not_found": { "message": "Bluetooth device {mac} not found." }, + "device_disconnected": { + "message": "Unexpectedly lost the Bluetooth device {mac} connection." + }, "connection_failed": { "message": "Failed connect to Bluetooth device {mac}." } diff --git a/custom_components/ftms/translations/ru.json b/custom_components/ftms/translations/ru.json index e33fe38..7b1aeeb 100644 --- a/custom_components/ftms/translations/ru.json +++ b/custom_components/ftms/translations/ru.json @@ -243,6 +243,9 @@ "device_not_found": { "message": "Bluetooth устройство {mac} не найдено." }, + "device_disconnected": { + "message": "Соединение с Bluetooth устройством {mac} потеряно." + }, "connection_failed": { "message": "Ошибка соединения с Bluetooth устройством {mac}." }