1 """The Whois integration."""
3 from __future__
import annotations
5 from whois
import Domain, query
as whois_query
6 from whois.exceptions
import (
7 FailedParsingWhoisOutput,
18 from .const
import DOMAIN, LOGGER, PLATFORMS, SCAN_INTERVAL
22 """Set up from a config entry."""
24 async
def _async_query_domain() -> Domain | None:
25 """Query WHOIS for domain information."""
27 return await hass.async_add_executor_job(
28 whois_query, entry.data[CONF_DOMAIN]
30 except UnknownTld
as ex:
31 raise UpdateFailed(
"Could not set up whois, TLD is unknown")
from ex
32 except (FailedParsingWhoisOutput, WhoisCommandFailed, UnknownDateFormat)
as ex:
33 raise UpdateFailed(
"An error occurred during WHOIS lookup")
from ex
40 update_interval=SCAN_INTERVAL,
41 update_method=_async_query_domain,
43 await coordinator.async_config_entry_first_refresh()
44 hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
46 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
52 """Unload a config entry."""
53 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
55 del hass.data[DOMAIN][entry.entry_id]
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)