mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Introduce const file in Whois (#63051)
This commit is contained in:
parent
792d9196df
commit
bbb652304e
16
homeassistant/components/whois/const.py
Normal file
16
homeassistant/components/whois/const.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
"""Constants for the Whois integration."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from typing import Final
|
||||||
|
|
||||||
|
DOMAIN: Final = "whois"
|
||||||
|
|
||||||
|
LOGGER = logging.getLogger(__package__)
|
||||||
|
|
||||||
|
DEFAULT_NAME = "Whois"
|
||||||
|
|
||||||
|
ATTR_EXPIRES = "expires"
|
||||||
|
ATTR_NAME_SERVERS = "name_servers"
|
||||||
|
ATTR_REGISTRAR = "registrar"
|
||||||
|
ATTR_UPDATED = "updated"
|
@ -2,7 +2,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
import whois
|
import whois
|
||||||
@ -14,16 +13,16 @@ import homeassistant.helpers.config_validation as cv
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
from .const import (
|
||||||
|
ATTR_EXPIRES,
|
||||||
|
ATTR_NAME_SERVERS,
|
||||||
|
ATTR_REGISTRAR,
|
||||||
|
ATTR_UPDATED,
|
||||||
|
DEFAULT_NAME,
|
||||||
|
LOGGER,
|
||||||
|
)
|
||||||
|
|
||||||
DEFAULT_NAME = "Whois"
|
SCANTERVAL = timedelta(hours=24)
|
||||||
|
|
||||||
ATTR_EXPIRES = "expires"
|
|
||||||
ATTR_NAME_SERVERS = "name_servers"
|
|
||||||
ATTR_REGISTRAR = "registrar"
|
|
||||||
ATTR_UPDATED = "updated"
|
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(hours=24)
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
@ -47,12 +46,12 @@ def setup_platform(
|
|||||||
if "expiration_date" in whois.whois(domain):
|
if "expiration_date" in whois.whois(domain):
|
||||||
add_entities([WhoisSensor(name, domain)], True)
|
add_entities([WhoisSensor(name, domain)], True)
|
||||||
else:
|
else:
|
||||||
_LOGGER.error(
|
LOGGER.error(
|
||||||
"WHOIS lookup for %s didn't contain an expiration date", domain
|
"WHOIS lookup for %s didn't contain an expiration date", domain
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
except whois.BaseException as ex: # pylint: disable=broad-except
|
except whois.BaseException as ex: # pylint: disable=broad-except
|
||||||
_LOGGER.error("Exception %s occurred during WHOIS lookup for %s", ex, domain)
|
LOGGER.error("Exception %s occurred during WHOIS lookup for %s", ex, domain)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
@ -78,13 +77,13 @@ class WhoisSensor(SensorEntity):
|
|||||||
try:
|
try:
|
||||||
response = self.whois(self._domain)
|
response = self.whois(self._domain)
|
||||||
except whois.BaseException as ex: # pylint: disable=broad-except
|
except whois.BaseException as ex: # pylint: disable=broad-except
|
||||||
_LOGGER.error("Exception %s occurred during WHOIS lookup", ex)
|
LOGGER.error("Exception %s occurred during WHOIS lookup", ex)
|
||||||
self._empty_value_and_attributes()
|
self._empty_value_and_attributes()
|
||||||
return
|
return
|
||||||
|
|
||||||
if response:
|
if response:
|
||||||
if "expiration_date" not in response:
|
if "expiration_date" not in response:
|
||||||
_LOGGER.error(
|
LOGGER.error(
|
||||||
"Failed to find expiration_date in whois lookup response. "
|
"Failed to find expiration_date in whois lookup response. "
|
||||||
"Did find: %s",
|
"Did find: %s",
|
||||||
", ".join(response.keys()),
|
", ".join(response.keys()),
|
||||||
@ -93,7 +92,7 @@ class WhoisSensor(SensorEntity):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if not response["expiration_date"]:
|
if not response["expiration_date"]:
|
||||||
_LOGGER.error("Whois response contains empty expiration_date")
|
LOGGER.error("Whois response contains empty expiration_date")
|
||||||
self._empty_value_and_attributes()
|
self._empty_value_and_attributes()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user