1 """The Husqvarna Autoconnect Bluetooth integration."""
3 from __future__
import annotations
5 from automower_ble.mower
import Mower
6 from bleak
import BleakError
7 from bleak_retry_connector
import close_stale_connections_by_address, get_device
15 from .const
import LOGGER
16 from .coordinator
import HusqvarnaCoordinator
24 """Set up Husqvarna Autoconnect Bluetooth from a config entry."""
25 address = entry.data[CONF_ADDRESS]
26 channel_id = entry.data[CONF_CLIENT_ID]
28 mower = Mower(channel_id, address)
30 await close_stale_connections_by_address(address)
32 LOGGER.debug(
"connecting to %s with channel ID %s", address,
str(channel_id))
34 device = bluetooth.async_ble_device_from_address(
35 hass, address, connectable=
True
37 if not await mower.connect(device):
38 raise ConfigEntryNotReady
39 except (TimeoutError, BleakError)
as exception:
41 f
"Unable to connect to device {address} due to {exception}"
43 LOGGER.debug(
"connected and paired")
45 model = await mower.get_model()
46 LOGGER.debug(
"Connected to Automower: %s", model)
50 await coordinator.async_config_entry_first_refresh()
51 entry.runtime_data = coordinator
52 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
58 """Unload a config entry."""
59 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
60 coordinator: HusqvarnaCoordinator = entry.runtime_data
61 await coordinator.async_shutdown()
DeviceEntry get_device(HomeAssistant hass, str unique_id)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)