mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 15:57:06 +00:00
Explicitly pass in the config_entry in gardena_bluetooth coordinator (#137830)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
4893cdaa80
commit
a797b09bcb
@ -10,7 +10,6 @@ from gardena_bluetooth.const import DeviceConfiguration, DeviceInformation
|
|||||||
from gardena_bluetooth.exceptions import CommunicationFailure
|
from gardena_bluetooth.exceptions import CommunicationFailure
|
||||||
|
|
||||||
from homeassistant.components import bluetooth
|
from homeassistant.components import bluetooth
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import CONF_ADDRESS, Platform
|
from homeassistant.const import CONF_ADDRESS, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
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 homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import DeviceUnavailable, GardenaBluetoothCoordinator
|
from .coordinator import (
|
||||||
|
DeviceUnavailable,
|
||||||
|
GardenaBluetoothConfigEntry,
|
||||||
|
GardenaBluetoothCoordinator,
|
||||||
|
)
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [
|
PLATFORMS: list[Platform] = [
|
||||||
Platform.BINARY_SENSOR,
|
Platform.BINARY_SENSOR,
|
||||||
@ -32,8 +35,6 @@ LOGGER = logging.getLogger(__name__)
|
|||||||
TIMEOUT = 20.0
|
TIMEOUT = 20.0
|
||||||
DISCONNECT_DELAY = 5
|
DISCONNECT_DELAY = 5
|
||||||
|
|
||||||
type GardenaBluetoothConfigEntry = ConfigEntry[GardenaBluetoothCoordinator]
|
|
||||||
|
|
||||||
|
|
||||||
def get_connection(hass: HomeAssistant, address: str) -> CachedConnection:
|
def get_connection(hass: HomeAssistant, address: str) -> CachedConnection:
|
||||||
"""Set up a cached client that keeps connection after last use."""
|
"""Set up a cached client that keeps connection after last use."""
|
||||||
@ -80,7 +81,7 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
coordinator = GardenaBluetoothCoordinator(
|
coordinator = GardenaBluetoothCoordinator(
|
||||||
hass, LOGGER, client, uuids, device, address
|
hass, entry, LOGGER, client, uuids, device, address
|
||||||
)
|
)
|
||||||
|
|
||||||
entry.runtime_data = coordinator
|
entry.runtime_data = coordinator
|
||||||
|
@ -16,7 +16,7 @@ from homeassistant.const import EntityCategory
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import GardenaBluetoothConfigEntry
|
from .coordinator import GardenaBluetoothConfigEntry
|
||||||
from .entity import GardenaBluetoothDescriptorEntity
|
from .entity import GardenaBluetoothDescriptorEntity
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ from homeassistant.const import EntityCategory
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import GardenaBluetoothConfigEntry
|
from .coordinator import GardenaBluetoothConfigEntry
|
||||||
from .entity import GardenaBluetoothDescriptorEntity
|
from .entity import GardenaBluetoothDescriptorEntity
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ from gardena_bluetooth.exceptions import (
|
|||||||
)
|
)
|
||||||
from gardena_bluetooth.parse import Characteristic, CharacteristicType
|
from gardena_bluetooth.parse import Characteristic, CharacteristicType
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
@ -20,6 +21,8 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
|
|||||||
SCAN_INTERVAL = timedelta(seconds=60)
|
SCAN_INTERVAL = timedelta(seconds=60)
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type GardenaBluetoothConfigEntry = ConfigEntry[GardenaBluetoothCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class DeviceUnavailable(HomeAssistantError):
|
class DeviceUnavailable(HomeAssistantError):
|
||||||
"""Raised if device can't be found."""
|
"""Raised if device can't be found."""
|
||||||
@ -28,9 +31,12 @@ class DeviceUnavailable(HomeAssistantError):
|
|||||||
class GardenaBluetoothCoordinator(DataUpdateCoordinator[dict[str, bytes]]):
|
class GardenaBluetoothCoordinator(DataUpdateCoordinator[dict[str, bytes]]):
|
||||||
"""Class to manage fetching data."""
|
"""Class to manage fetching data."""
|
||||||
|
|
||||||
|
config_entry: GardenaBluetoothConfigEntry
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
config_entry: GardenaBluetoothConfigEntry,
|
||||||
logger: logging.Logger,
|
logger: logging.Logger,
|
||||||
client: Client,
|
client: Client,
|
||||||
characteristics: set[str],
|
characteristics: set[str],
|
||||||
@ -41,6 +47,7 @@ class GardenaBluetoothCoordinator(DataUpdateCoordinator[dict[str, bytes]]):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
hass=hass,
|
hass=hass,
|
||||||
logger=logger,
|
logger=logger,
|
||||||
|
config_entry=config_entry,
|
||||||
name="Gardena Bluetooth Data Update Coordinator",
|
name="Gardena Bluetooth Data Update Coordinator",
|
||||||
update_interval=SCAN_INTERVAL,
|
update_interval=SCAN_INTERVAL,
|
||||||
)
|
)
|
||||||
|
@ -21,8 +21,7 @@ from homeassistant.const import PERCENTAGE, EntityCategory, UnitOfTime
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import GardenaBluetoothConfigEntry
|
from .coordinator import GardenaBluetoothConfigEntry, GardenaBluetoothCoordinator
|
||||||
from .coordinator import GardenaBluetoothCoordinator
|
|
||||||
from .entity import GardenaBluetoothDescriptorEntity, GardenaBluetoothEntity
|
from .entity import GardenaBluetoothDescriptorEntity, GardenaBluetoothEntity
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,8 +19,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from . import GardenaBluetoothConfigEntry
|
from .coordinator import GardenaBluetoothConfigEntry, GardenaBluetoothCoordinator
|
||||||
from .coordinator import GardenaBluetoothCoordinator
|
|
||||||
from .entity import GardenaBluetoothDescriptorEntity, GardenaBluetoothEntity
|
from .entity import GardenaBluetoothDescriptorEntity, GardenaBluetoothEntity
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,8 +11,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import GardenaBluetoothConfigEntry
|
from .coordinator import GardenaBluetoothConfigEntry, GardenaBluetoothCoordinator
|
||||||
from .coordinator import GardenaBluetoothCoordinator
|
|
||||||
from .entity import GardenaBluetoothEntity
|
from .entity import GardenaBluetoothEntity
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,8 +10,7 @@ from homeassistant.components.valve import ValveEntity, ValveEntityFeature
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import GardenaBluetoothConfigEntry
|
from .coordinator import GardenaBluetoothConfigEntry, GardenaBluetoothCoordinator
|
||||||
from .coordinator import GardenaBluetoothCoordinator
|
|
||||||
from .entity import GardenaBluetoothEntity
|
from .entity import GardenaBluetoothEntity
|
||||||
|
|
||||||
FALLBACK_WATERING_TIME_IN_SECONDS = 60 * 60
|
FALLBACK_WATERING_TIME_IN_SECONDS = 60 * 60
|
||||||
|
Loading…
x
Reference in New Issue
Block a user