mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Move gogogate2 coordinator to separate module (#117433)
This commit is contained in:
parent
07d289d1c6
commit
8bbac8040f
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Awaitable, Callable, Mapping
|
from collections.abc import Mapping
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, NamedTuple
|
from typing import Any, NamedTuple
|
||||||
@ -24,16 +24,12 @@ from homeassistant.const import (
|
|||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.debounce import Debouncer
|
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.httpx_client import get_async_client
|
from homeassistant.helpers.httpx_client import get_async_client
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity, UpdateFailed
|
||||||
CoordinatorEntity,
|
|
||||||
DataUpdateCoordinator,
|
|
||||||
UpdateFailed,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .const import DATA_UPDATE_COORDINATOR, DEVICE_TYPE_ISMARTGATE, DOMAIN, MANUFACTURER
|
from .const import DATA_UPDATE_COORDINATOR, DEVICE_TYPE_ISMARTGATE, DOMAIN, MANUFACTURER
|
||||||
|
from .coordinator import DeviceDataUpdateCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -46,38 +42,6 @@ class StateData(NamedTuple):
|
|||||||
door: AbstractDoor | None
|
door: AbstractDoor | None
|
||||||
|
|
||||||
|
|
||||||
class DeviceDataUpdateCoordinator(
|
|
||||||
DataUpdateCoordinator[GogoGate2InfoResponse | ISmartGateInfoResponse]
|
|
||||||
): # pylint: disable=hass-enforce-coordinator-module
|
|
||||||
"""Manages polling for state changes from the device."""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
hass: HomeAssistant,
|
|
||||||
logger: logging.Logger,
|
|
||||||
api: AbstractGateApi,
|
|
||||||
*,
|
|
||||||
name: str,
|
|
||||||
update_interval: timedelta,
|
|
||||||
update_method: Callable[
|
|
||||||
[], Awaitable[GogoGate2InfoResponse | ISmartGateInfoResponse]
|
|
||||||
]
|
|
||||||
| None = None,
|
|
||||||
request_refresh_debouncer: Debouncer | None = None,
|
|
||||||
) -> None:
|
|
||||||
"""Initialize the data update coordinator."""
|
|
||||||
DataUpdateCoordinator.__init__(
|
|
||||||
self,
|
|
||||||
hass,
|
|
||||||
logger,
|
|
||||||
name=name,
|
|
||||||
update_interval=update_interval,
|
|
||||||
update_method=update_method,
|
|
||||||
request_refresh_debouncer=request_refresh_debouncer,
|
|
||||||
)
|
|
||||||
self.api = api
|
|
||||||
|
|
||||||
|
|
||||||
class GoGoGate2Entity(CoordinatorEntity[DeviceDataUpdateCoordinator]):
|
class GoGoGate2Entity(CoordinatorEntity[DeviceDataUpdateCoordinator]):
|
||||||
"""Base class for gogogate2 entities."""
|
"""Base class for gogogate2 entities."""
|
||||||
|
|
||||||
|
45
homeassistant/components/gogogate2/coordinator.py
Normal file
45
homeassistant/components/gogogate2/coordinator.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
"""Coordinator for GogoGate2 component."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Awaitable, Callable
|
||||||
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from ismartgate import AbstractGateApi, GogoGate2InfoResponse, ISmartGateInfoResponse
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.debounce import Debouncer
|
||||||
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceDataUpdateCoordinator(
|
||||||
|
DataUpdateCoordinator[GogoGate2InfoResponse | ISmartGateInfoResponse]
|
||||||
|
):
|
||||||
|
"""Manages polling for state changes from the device."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
logger: logging.Logger,
|
||||||
|
api: AbstractGateApi,
|
||||||
|
*,
|
||||||
|
name: str,
|
||||||
|
update_interval: timedelta,
|
||||||
|
update_method: Callable[
|
||||||
|
[], Awaitable[GogoGate2InfoResponse | ISmartGateInfoResponse]
|
||||||
|
]
|
||||||
|
| None = None,
|
||||||
|
request_refresh_debouncer: Debouncer | None = None,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the data update coordinator."""
|
||||||
|
DataUpdateCoordinator.__init__(
|
||||||
|
self,
|
||||||
|
hass,
|
||||||
|
logger,
|
||||||
|
name=name,
|
||||||
|
update_interval=update_interval,
|
||||||
|
update_method=update_method,
|
||||||
|
request_refresh_debouncer=request_refresh_debouncer,
|
||||||
|
)
|
||||||
|
self.api = api
|
@ -20,12 +20,8 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
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 .common import (
|
from .common import GoGoGate2Entity, cover_unique_id, get_data_update_coordinator
|
||||||
DeviceDataUpdateCoordinator,
|
from .coordinator import DeviceDataUpdateCoordinator
|
||||||
GoGoGate2Entity,
|
|
||||||
cover_unique_id,
|
|
||||||
get_data_update_coordinator,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
@ -16,12 +16,8 @@ from homeassistant.const import PERCENTAGE, EntityCategory, UnitOfTemperature
|
|||||||
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 .common import (
|
from .common import GoGoGate2Entity, get_data_update_coordinator, sensor_unique_id
|
||||||
DeviceDataUpdateCoordinator,
|
from .coordinator import DeviceDataUpdateCoordinator
|
||||||
GoGoGate2Entity,
|
|
||||||
get_data_update_coordinator,
|
|
||||||
sensor_unique_id,
|
|
||||||
)
|
|
||||||
|
|
||||||
SENSOR_ID_WIRED = "WIRE"
|
SENSOR_ID_WIRED = "WIRE"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user