Skip to content

Commit

Permalink
handle disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
dudanov committed Jul 18, 2024
1 parent 0bb193d commit ec661ce
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions custom_components/ftms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions custom_components/ftms/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}."
}
Expand Down
3 changes: 3 additions & 0 deletions custom_components/ftms/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@
"device_not_found": {
"message": "Bluetooth устройство {mac} не найдено."
},
"device_disconnected": {
"message": "Соединение с Bluetooth устройством {mac} потеряно."
},
"connection_failed": {
"message": "Ошибка соединения с Bluetooth устройством {mac}."
}
Expand Down

0 comments on commit ec661ce

Please sign in to comment.