mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +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 __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.const import Platform
|
||||||
from homeassistant.const import (
|
|
||||||
CONF_HOST,
|
|
||||||
CONF_PORT,
|
|
||||||
CONF_SSL,
|
|
||||||
CONF_VERIFY_SSL,
|
|
||||||
Platform,
|
|
||||||
)
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .const import CONF_BASE_PATH
|
from .coordinator import IPPConfigEntry, IPPDataUpdateCoordinator
|
||||||
from .coordinator import IPPDataUpdateCoordinator
|
|
||||||
|
|
||||||
PLATFORMS = [Platform.SENSOR]
|
PLATFORMS = [Platform.SENSOR]
|
||||||
|
|
||||||
type IPPConfigEntry = ConfigEntry[IPPDataUpdateCoordinator]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: IPPConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: IPPConfigEntry) -> bool:
|
||||||
"""Set up IPP from a config entry."""
|
"""Set up IPP from a config entry."""
|
||||||
# config flow sets this to either UUID, serial number or None
|
coordinator = IPPDataUpdateCoordinator(hass, entry)
|
||||||
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,
|
|
||||||
)
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
entry.runtime_data = coordinator
|
entry.runtime_data = coordinator
|
||||||
@ -44,6 +22,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: IPPConfigEntry) -> bool:
|
|||||||
return True
|
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."""
|
"""Unload a config entry."""
|
||||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
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 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.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import CONF_BASE_PATH, DOMAIN
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=60)
|
SCAN_INTERVAL = timedelta(seconds=60)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type IPPConfigEntry = ConfigEntry[IPPDataUpdateCoordinator]
|
||||||
|
|
||||||
|
|
||||||
class IPPDataUpdateCoordinator(DataUpdateCoordinator[IPPPrinter]):
|
class IPPDataUpdateCoordinator(DataUpdateCoordinator[IPPPrinter]):
|
||||||
"""Class to manage fetching IPP data from single endpoint."""
|
"""Class to manage fetching IPP data from single endpoint."""
|
||||||
|
|
||||||
def __init__(
|
config_entry: IPPConfigEntry
|
||||||
self,
|
|
||||||
hass: HomeAssistant,
|
def __init__(self, hass: HomeAssistant, config_entry: IPPConfigEntry) -> None:
|
||||||
*,
|
|
||||||
host: str,
|
|
||||||
port: int,
|
|
||||||
base_path: str,
|
|
||||||
tls: bool,
|
|
||||||
verify_ssl: bool,
|
|
||||||
device_id: str,
|
|
||||||
) -> None:
|
|
||||||
"""Initialize global IPP data updater."""
|
"""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(
|
self.ipp = IPP(
|
||||||
host=host,
|
host=config_entry.data[CONF_HOST],
|
||||||
port=port,
|
port=config_entry.data[CONF_PORT],
|
||||||
base_path=base_path,
|
base_path=config_entry.data[CONF_BASE_PATH],
|
||||||
tls=tls,
|
tls=config_entry.data[CONF_SSL],
|
||||||
verify_ssl=verify_ssl,
|
verify_ssl=config_entry.data[CONF_VERIFY_SSL],
|
||||||
session=async_get_clientsession(hass, verify_ssl),
|
session=async_get_clientsession(hass, config_entry.data[CONF_VERIFY_SSL]),
|
||||||
)
|
)
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name=DOMAIN,
|
name=DOMAIN,
|
||||||
update_interval=SCAN_INTERVAL,
|
update_interval=SCAN_INTERVAL,
|
||||||
)
|
)
|
||||||
|
@ -6,7 +6,7 @@ from typing import Any
|
|||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import IPPConfigEntry
|
from .coordinator import IPPConfigEntry
|
||||||
|
|
||||||
|
|
||||||
async def async_get_config_entry_diagnostics(
|
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.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from . import IPPConfigEntry
|
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_COMMAND_SET,
|
ATTR_COMMAND_SET,
|
||||||
ATTR_INFO,
|
ATTR_INFO,
|
||||||
@ -32,6 +31,7 @@ from .const import (
|
|||||||
ATTR_STATE_REASON,
|
ATTR_STATE_REASON,
|
||||||
ATTR_URI_SUPPORTED,
|
ATTR_URI_SUPPORTED,
|
||||||
)
|
)
|
||||||
|
from .coordinator import IPPConfigEntry
|
||||||
from .entity import IPPEntity
|
from .entity import IPPEntity
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user