Explicitly pass in the config_entry in gardena_bluetooth coordinator (#137830)

explicitly pass in the config_entry in coordinator
This commit is contained in:
Michael 2025-02-08 12:47:57 +01:00 committed by GitHub
parent 4893cdaa80
commit a797b09bcb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 19 additions and 15 deletions

View File

@ -10,7 +10,6 @@ from gardena_bluetooth.const import DeviceConfiguration, DeviceInformation
from gardena_bluetooth.exceptions import CommunicationFailure
from homeassistant.components import bluetooth
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_ADDRESS, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
@ -18,7 +17,11 @@ from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.util import dt as dt_util
from .const import DOMAIN
from .coordinator import DeviceUnavailable, GardenaBluetoothCoordinator
from .coordinator import (
DeviceUnavailable,
GardenaBluetoothConfigEntry,
GardenaBluetoothCoordinator,
)
PLATFORMS: list[Platform] = [
Platform.BINARY_SENSOR,
@ -32,8 +35,6 @@ LOGGER = logging.getLogger(__name__)
TIMEOUT = 20.0
DISCONNECT_DELAY = 5
type GardenaBluetoothConfigEntry = ConfigEntry[GardenaBluetoothCoordinator]
def get_connection(hass: HomeAssistant, address: str) -> CachedConnection:
"""Set up a cached client that keeps connection after last use."""
@ -80,7 +81,7 @@ async def async_setup_entry(
)
coordinator = GardenaBluetoothCoordinator(
hass, LOGGER, client, uuids, device, address
hass, entry, LOGGER, client, uuids, device, address
)
entry.runtime_data = coordinator

View File

@ -16,7 +16,7 @@ from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import GardenaBluetoothConfigEntry
from .coordinator import GardenaBluetoothConfigEntry
from .entity import GardenaBluetoothDescriptorEntity

View File

@ -12,7 +12,7 @@ from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import GardenaBluetoothConfigEntry
from .coordinator import GardenaBluetoothConfigEntry
from .entity import GardenaBluetoothDescriptorEntity

View File

@ -12,6 +12,7 @@ from gardena_bluetooth.exceptions import (
)
from gardena_bluetooth.parse import Characteristic, CharacteristicType
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.device_registry import DeviceInfo
@ -20,6 +21,8 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
SCAN_INTERVAL = timedelta(seconds=60)
LOGGER = logging.getLogger(__name__)
type GardenaBluetoothConfigEntry = ConfigEntry[GardenaBluetoothCoordinator]
class DeviceUnavailable(HomeAssistantError):
"""Raised if device can't be found."""
@ -28,9 +31,12 @@ class DeviceUnavailable(HomeAssistantError):
class GardenaBluetoothCoordinator(DataUpdateCoordinator[dict[str, bytes]]):
"""Class to manage fetching data."""
config_entry: GardenaBluetoothConfigEntry
def __init__(
self,
hass: HomeAssistant,
config_entry: GardenaBluetoothConfigEntry,
logger: logging.Logger,
client: Client,
characteristics: set[str],
@ -41,6 +47,7 @@ class GardenaBluetoothCoordinator(DataUpdateCoordinator[dict[str, bytes]]):
super().__init__(
hass=hass,
logger=logger,
config_entry=config_entry,
name="Gardena Bluetooth Data Update Coordinator",
update_interval=SCAN_INTERVAL,
)

View File

@ -21,8 +21,7 @@ from homeassistant.const import PERCENTAGE, EntityCategory, UnitOfTime
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import GardenaBluetoothConfigEntry
from .coordinator import GardenaBluetoothCoordinator
from .coordinator import GardenaBluetoothConfigEntry, GardenaBluetoothCoordinator
from .entity import GardenaBluetoothDescriptorEntity, GardenaBluetoothEntity

View File

@ -19,8 +19,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util import dt as dt_util
from . import GardenaBluetoothConfigEntry
from .coordinator import GardenaBluetoothCoordinator
from .coordinator import GardenaBluetoothConfigEntry, GardenaBluetoothCoordinator
from .entity import GardenaBluetoothDescriptorEntity, GardenaBluetoothEntity

View File

@ -11,8 +11,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import GardenaBluetoothConfigEntry
from .coordinator import GardenaBluetoothCoordinator
from .coordinator import GardenaBluetoothConfigEntry, GardenaBluetoothCoordinator
from .entity import GardenaBluetoothEntity

View File

@ -10,8 +10,7 @@ from homeassistant.components.valve import ValveEntity, ValveEntityFeature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import GardenaBluetoothConfigEntry
from .coordinator import GardenaBluetoothCoordinator
from .coordinator import GardenaBluetoothConfigEntry, GardenaBluetoothCoordinator
from .entity import GardenaBluetoothEntity
FALLBACK_WATERING_TIME_IN_SECONDS = 60 * 60