mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Explicitly pass in the config_entry in ruuvi_gateway coordinator (#137964)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
71d47aef2e
commit
5464e245a2
@ -5,11 +5,10 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_HOST, CONF_TOKEN
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .bluetooth import async_connect_scanner
|
from .bluetooth import async_connect_scanner
|
||||||
from .const import DOMAIN, SCAN_INTERVAL
|
from .const import DOMAIN
|
||||||
from .coordinator import RuuviGatewayUpdateCoordinator
|
from .coordinator import RuuviGatewayUpdateCoordinator
|
||||||
from .models import RuuviGatewayRuntimeData
|
from .models import RuuviGatewayRuntimeData
|
||||||
|
|
||||||
@ -18,14 +17,7 @@ _LOGGER = logging.getLogger(DOMAIN)
|
|||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up Ruuvi Gateway from a config entry."""
|
"""Set up Ruuvi Gateway from a config entry."""
|
||||||
coordinator = RuuviGatewayUpdateCoordinator(
|
coordinator = RuuviGatewayUpdateCoordinator(hass, entry, _LOGGER)
|
||||||
hass,
|
|
||||||
logger=_LOGGER,
|
|
||||||
name=entry.title,
|
|
||||||
update_interval=SCAN_INTERVAL,
|
|
||||||
host=entry.data[CONF_HOST],
|
|
||||||
token=entry.data[CONF_TOKEN],
|
|
||||||
)
|
|
||||||
scanner, unload_scanner = async_connect_scanner(hass, entry, coordinator)
|
scanner, unload_scanner = async_connect_scanner(hass, entry, coordinator)
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = RuuviGatewayRuntimeData(
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = RuuviGatewayRuntimeData(
|
||||||
update_coordinator=coordinator,
|
update_coordinator=coordinator,
|
||||||
|
@ -2,34 +2,41 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from aioruuvigateway.api import get_gateway_history_data
|
from aioruuvigateway.api import get_gateway_history_data
|
||||||
from aioruuvigateway.models import TagData
|
from aioruuvigateway.models import TagData
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import CONF_HOST, CONF_TOKEN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.httpx_client import get_async_client
|
from homeassistant.helpers.httpx_client import get_async_client
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
|
from .const import SCAN_INTERVAL
|
||||||
|
|
||||||
|
|
||||||
class RuuviGatewayUpdateCoordinator(DataUpdateCoordinator[list[TagData]]):
|
class RuuviGatewayUpdateCoordinator(DataUpdateCoordinator[list[TagData]]):
|
||||||
"""Polls the gateway for data and returns a list of TagData objects that have changed since the last poll."""
|
"""Polls the gateway for data and returns a list of TagData objects that have changed since the last poll."""
|
||||||
|
|
||||||
|
config_entry: ConfigEntry
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
logger: logging.Logger,
|
logger: logging.Logger,
|
||||||
*,
|
|
||||||
name: str,
|
|
||||||
update_interval: timedelta | None = None,
|
|
||||||
host: str,
|
|
||||||
token: str,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the coordinator using the given configuration (host, token)."""
|
"""Initialize the coordinator using the given configuration (host, token)."""
|
||||||
super().__init__(hass, logger, name=name, update_interval=update_interval)
|
super().__init__(
|
||||||
self.host = host
|
hass,
|
||||||
self.token = token
|
logger,
|
||||||
|
config_entry=config_entry,
|
||||||
|
name=config_entry.title,
|
||||||
|
update_interval=SCAN_INTERVAL,
|
||||||
|
)
|
||||||
|
self.host = config_entry.data[CONF_HOST]
|
||||||
|
self.token = config_entry.data[CONF_TOKEN]
|
||||||
self.last_tag_datas: dict[str, TagData] = {}
|
self.last_tag_datas: dict[str, TagData] = {}
|
||||||
|
|
||||||
async def _async_update_data(self) -> list[TagData]:
|
async def _async_update_data(self) -> list[TagData]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user