Change lib for whois sensor (#21878)
* Change lib for whois sensor * Change requirements.txtpull/21891/head
parent
ad73b6eee9
commit
7102e82113
|
@ -14,7 +14,7 @@ from homeassistant.const import CONF_NAME
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
REQUIREMENTS = ['pythonwhois==2.4.3']
|
||||
REQUIREMENTS = ['python-whois==0.7.1']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -37,21 +37,20 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the WHOIS sensor."""
|
||||
from pythonwhois import get_whois
|
||||
from pythonwhois.shared import WhoisException
|
||||
import whois
|
||||
|
||||
domain = config.get(CONF_DOMAIN)
|
||||
name = config.get(CONF_NAME)
|
||||
|
||||
try:
|
||||
if 'expiration_date' in get_whois(domain, normalized=True):
|
||||
if 'expiration_date' in whois.whois(domain):
|
||||
add_entities([WhoisSensor(name, domain)], True)
|
||||
else:
|
||||
_LOGGER.error(
|
||||
"WHOIS lookup for %s didn't contain expiration_date",
|
||||
domain)
|
||||
return
|
||||
except WhoisException as ex:
|
||||
except whois.BaseException as ex:
|
||||
_LOGGER.error(
|
||||
"Exception %s occurred during WHOIS lookup for %s", ex, domain)
|
||||
return
|
||||
|
@ -62,9 +61,9 @@ class WhoisSensor(Entity):
|
|||
|
||||
def __init__(self, name, domain):
|
||||
"""Initialize the sensor."""
|
||||
from pythonwhois import get_whois
|
||||
import whois
|
||||
|
||||
self.whois = get_whois
|
||||
self.whois = whois.whois
|
||||
|
||||
self._name = name
|
||||
self._domain = domain
|
||||
|
@ -104,11 +103,11 @@ class WhoisSensor(Entity):
|
|||
|
||||
def update(self):
|
||||
"""Get the current WHOIS data for the domain."""
|
||||
from pythonwhois.shared import WhoisException
|
||||
import whois
|
||||
|
||||
try:
|
||||
response = self.whois(self._domain, normalized=True)
|
||||
except WhoisException as ex:
|
||||
response = self.whois(self._domain)
|
||||
except whois.BaseException as ex:
|
||||
_LOGGER.error("Exception %s occurred during WHOIS lookup", ex)
|
||||
self._empty_state_and_attributes()
|
||||
return
|
||||
|
@ -128,17 +127,17 @@ class WhoisSensor(Entity):
|
|||
|
||||
attrs = {}
|
||||
|
||||
expiration_date = response['expiration_date'][0]
|
||||
expiration_date = response['expiration_date']
|
||||
attrs[ATTR_EXPIRES] = expiration_date.isoformat()
|
||||
|
||||
if 'nameservers' in response:
|
||||
attrs[ATTR_NAME_SERVERS] = ' '.join(response['nameservers'])
|
||||
|
||||
if 'updated_date' in response:
|
||||
attrs[ATTR_UPDATED] = response['updated_date'][0].isoformat()
|
||||
attrs[ATTR_UPDATED] = response['updated_date'].isoformat()
|
||||
|
||||
if 'registrar' in response:
|
||||
attrs[ATTR_REGISTRAR] = response['registrar'][0]
|
||||
attrs[ATTR_REGISTRAR] = response['registrar']
|
||||
|
||||
time_delta = (expiration_date - expiration_date.now())
|
||||
|
||||
|
|
|
@ -1402,6 +1402,9 @@ python-velbus==2.0.22
|
|||
# homeassistant.components.media_player.vlc
|
||||
python-vlc==1.1.2
|
||||
|
||||
# homeassistant.components.sensor.whois
|
||||
python-whois==0.7.1
|
||||
|
||||
# homeassistant.components.wink
|
||||
python-wink==1.10.3
|
||||
|
||||
|
@ -1414,9 +1417,6 @@ python_opendata_transport==0.1.4
|
|||
# homeassistant.components.egardia
|
||||
pythonegardia==1.0.39
|
||||
|
||||
# homeassistant.components.sensor.whois
|
||||
pythonwhois==2.4.3
|
||||
|
||||
# homeassistant.components.device_tracker.tile
|
||||
pytile==2.0.6
|
||||
|
||||
|
|
|
@ -245,9 +245,6 @@ python-nest==4.1.0
|
|||
# homeassistant.components.sensor.awair
|
||||
python_awair==0.0.3
|
||||
|
||||
# homeassistant.components.sensor.whois
|
||||
pythonwhois==2.4.3
|
||||
|
||||
# homeassistant.components.tradfri
|
||||
pytradfri[async]==6.0.1
|
||||
|
||||
|
|
Loading…
Reference in New Issue