1 """The Husqvarna Autoconnect Bluetooth lawn mower platform."""
3 from __future__
import annotations
5 from automower_ble.protocol
import MowerActivity, MowerState
11 LawnMowerEntityFeature,
17 from .const
import LOGGER
18 from .coordinator
import HusqvarnaCoordinator
19 from .entity
import HusqvarnaAutomowerBleEntity
24 config_entry: ConfigEntry,
25 async_add_entities: AddEntitiesCallback,
27 """Set up AutomowerLawnMower integration from a config entry."""
28 coordinator: HusqvarnaCoordinator = config_entry.runtime_data
29 address = coordinator.address
42 """Husqvarna Automower."""
45 _attr_supported_features = (
46 LawnMowerEntityFeature.PAUSE
47 | LawnMowerEntityFeature.START_MOWING
48 | LawnMowerEntityFeature.DOCK
53 coordinator: HusqvarnaCoordinator,
56 """Initialize the lawn mower."""
61 """Return the current lawn mower activity."""
62 if self.coordinator.data
is None:
65 state = self.coordinator.data[
"state"]
66 activity = self.coordinator.data[
"activity"]
68 if state
is None or activity
is None:
71 if state == MowerState.PAUSED:
72 return LawnMowerActivity.PAUSED
73 if state
in (MowerState.STOPPED, MowerState.OFF, MowerState.WAIT_FOR_SAFETYPIN):
75 return LawnMowerActivity.ERROR
77 MowerState.RESTRICTED,
78 MowerState.IN_OPERATION,
79 MowerState.PENDING_START,
82 MowerActivity.CHARGING,
86 return LawnMowerActivity.DOCKED
87 if activity
in (MowerActivity.GOING_OUT, MowerActivity.MOWING):
88 return LawnMowerActivity.MOWING
89 if activity == MowerActivity.GOING_HOME:
90 return LawnMowerActivity.RETURNING
91 return LawnMowerActivity.ERROR
95 """Handle updated data from the coordinator."""
96 LOGGER.debug(
"AutomowerLawnMower: _handle_coordinator_update")
104 LOGGER.debug(
"Starting mower")
106 if not self.coordinator.mower.is_connected():
107 device = bluetooth.async_ble_device_from_address(
108 self.coordinator.hass, self.coordinator.address, connectable=
True
110 if not await self.coordinator.mower.connect(device):
113 await self.coordinator.mower.mower_resume()
115 await self.coordinator.mower.mower_override()
123 LOGGER.debug(
"Start docking")
125 if not self.coordinator.mower.is_connected():
126 device = bluetooth.async_ble_device_from_address(
127 self.coordinator.hass, self.coordinator.address, connectable=
True
129 if not await self.coordinator.mower.connect(device):
132 await self.coordinator.mower.mower_park()
140 LOGGER.debug(
"Pausing mower")
142 if not self.coordinator.mower.is_connected():
143 device = bluetooth.async_ble_device_from_address(
144 self.coordinator.hass, self.coordinator.address, connectable=
True
146 if not await self.coordinator.mower.connect(device):
149 await self.coordinator.mower.mower_pause()
LawnMowerActivity|None _get_activity(self)
None async_start_mowing(self)
None __init__(self, HusqvarnaCoordinator coordinator, str address)
None _handle_coordinator_update(self)
None async_write_ha_state(self)
None async_request_refresh(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)