mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Explicitly pass in the config_entry in ipp coordinator (#138138)
explicitly pass in the config_entry in coordinator
This commit is contained in:
parent
427013124c
commit
08dbd83a55
@ -2,39 +2,17 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_PORT,
|
||||
CONF_SSL,
|
||||
CONF_VERIFY_SSL,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import CONF_BASE_PATH
|
||||
from .coordinator import IPPDataUpdateCoordinator
|
||||
from .coordinator import IPPConfigEntry, IPPDataUpdateCoordinator
|
||||
|
||||
PLATFORMS = [Platform.SENSOR]
|
||||
|
||||
type IPPConfigEntry = ConfigEntry[IPPDataUpdateCoordinator]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: IPPConfigEntry) -> bool:
|
||||
"""Set up IPP from a config entry."""
|
||||
# config flow sets this to either UUID, serial number or None
|
||||
if (device_id := entry.unique_id) is None:
|
||||
device_id = entry.entry_id
|
||||
|
||||
coordinator = IPPDataUpdateCoordinator(
|
||||
hass,
|
||||
host=entry.data[CONF_HOST],
|
||||
port=entry.data[CONF_PORT],
|
||||
base_path=entry.data[CONF_BASE_PATH],
|
||||
tls=entry.data[CONF_SSL],
|
||||
verify_ssl=entry.data[CONF_VERIFY_SSL],
|
||||
device_id=device_id,
|
||||
)
|
||||
coordinator = IPPDataUpdateCoordinator(hass, entry)
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
entry.runtime_data = coordinator
|
||||
@ -44,6 +22,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: IPPConfigEntry) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: IPPConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
@ -7,45 +7,42 @@ import logging
|
||||
|
||||
from pyipp import IPP, IPPError, Printer as IPPPrinter
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_SSL, CONF_VERIFY_SSL
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .const import DOMAIN
|
||||
from .const import CONF_BASE_PATH, DOMAIN
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=60)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
type IPPConfigEntry = ConfigEntry[IPPDataUpdateCoordinator]
|
||||
|
||||
|
||||
class IPPDataUpdateCoordinator(DataUpdateCoordinator[IPPPrinter]):
|
||||
"""Class to manage fetching IPP data from single endpoint."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
*,
|
||||
host: str,
|
||||
port: int,
|
||||
base_path: str,
|
||||
tls: bool,
|
||||
verify_ssl: bool,
|
||||
device_id: str,
|
||||
) -> None:
|
||||
config_entry: IPPConfigEntry
|
||||
|
||||
def __init__(self, hass: HomeAssistant, config_entry: IPPConfigEntry) -> None:
|
||||
"""Initialize global IPP data updater."""
|
||||
self.device_id = device_id
|
||||
self.device_id = config_entry.unique_id or config_entry.entry_id
|
||||
self.ipp = IPP(
|
||||
host=host,
|
||||
port=port,
|
||||
base_path=base_path,
|
||||
tls=tls,
|
||||
verify_ssl=verify_ssl,
|
||||
session=async_get_clientsession(hass, verify_ssl),
|
||||
host=config_entry.data[CONF_HOST],
|
||||
port=config_entry.data[CONF_PORT],
|
||||
base_path=config_entry.data[CONF_BASE_PATH],
|
||||
tls=config_entry.data[CONF_SSL],
|
||||
verify_ssl=config_entry.data[CONF_VERIFY_SSL],
|
||||
session=async_get_clientsession(hass, config_entry.data[CONF_VERIFY_SSL]),
|
||||
)
|
||||
|
||||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
config_entry=config_entry,
|
||||
name=DOMAIN,
|
||||
update_interval=SCAN_INTERVAL,
|
||||
)
|
||||
|
@ -6,7 +6,7 @@ from typing import Any
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import IPPConfigEntry
|
||||
from .coordinator import IPPConfigEntry
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
|
@ -20,7 +20,6 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from . import IPPConfigEntry
|
||||
from .const import (
|
||||
ATTR_COMMAND_SET,
|
||||
ATTR_INFO,
|
||||
@ -32,6 +31,7 @@ from .const import (
|
||||
ATTR_STATE_REASON,
|
||||
ATTR_URI_SUPPORTED,
|
||||
)
|
||||
from .coordinator import IPPConfigEntry
|
||||
from .entity import IPPEntity
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user