Change lib for whois sensor (#21878)

* Change lib for whois sensor

* Change requirements.txt
pull/21891/head
Joakim Sørensen 2019-03-10 10:08:13 +01:00 committed by Fabian Affolter
parent ad73b6eee9
commit 7102e82113
3 changed files with 15 additions and 19 deletions

View File

@ -14,7 +14,7 @@ from homeassistant.const import CONF_NAME
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
REQUIREMENTS = ['pythonwhois==2.4.3'] REQUIREMENTS = ['python-whois==0.7.1']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -37,21 +37,20 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
def setup_platform(hass, config, add_entities, discovery_info=None): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the WHOIS sensor.""" """Set up the WHOIS sensor."""
from pythonwhois import get_whois import whois
from pythonwhois.shared import WhoisException
domain = config.get(CONF_DOMAIN) domain = config.get(CONF_DOMAIN)
name = config.get(CONF_NAME) name = config.get(CONF_NAME)
try: try:
if 'expiration_date' in get_whois(domain, normalized=True): 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 expiration_date", "WHOIS lookup for %s didn't contain expiration_date",
domain) domain)
return return
except WhoisException as ex: except whois.BaseException as ex:
_LOGGER.error( _LOGGER.error(
"Exception %s occurred during WHOIS lookup for %s", ex, domain) "Exception %s occurred during WHOIS lookup for %s", ex, domain)
return return
@ -62,9 +61,9 @@ class WhoisSensor(Entity):
def __init__(self, name, domain): def __init__(self, name, domain):
"""Initialize the sensor.""" """Initialize the sensor."""
from pythonwhois import get_whois import whois
self.whois = get_whois self.whois = whois.whois
self._name = name self._name = name
self._domain = domain self._domain = domain
@ -104,11 +103,11 @@ class WhoisSensor(Entity):
def update(self): def update(self):
"""Get the current WHOIS data for the domain.""" """Get the current WHOIS data for the domain."""
from pythonwhois.shared import WhoisException import whois
try: try:
response = self.whois(self._domain, normalized=True) response = self.whois(self._domain)
except WhoisException as ex: except whois.BaseException as ex:
_LOGGER.error("Exception %s occurred during WHOIS lookup", ex) _LOGGER.error("Exception %s occurred during WHOIS lookup", ex)
self._empty_state_and_attributes() self._empty_state_and_attributes()
return return
@ -128,17 +127,17 @@ class WhoisSensor(Entity):
attrs = {} attrs = {}
expiration_date = response['expiration_date'][0] expiration_date = response['expiration_date']
attrs[ATTR_EXPIRES] = expiration_date.isoformat() attrs[ATTR_EXPIRES] = expiration_date.isoformat()
if 'nameservers' in response: if 'nameservers' in response:
attrs[ATTR_NAME_SERVERS] = ' '.join(response['nameservers']) attrs[ATTR_NAME_SERVERS] = ' '.join(response['nameservers'])
if 'updated_date' in response: if 'updated_date' in response:
attrs[ATTR_UPDATED] = response['updated_date'][0].isoformat() attrs[ATTR_UPDATED] = response['updated_date'].isoformat()
if 'registrar' in response: if 'registrar' in response:
attrs[ATTR_REGISTRAR] = response['registrar'][0] attrs[ATTR_REGISTRAR] = response['registrar']
time_delta = (expiration_date - expiration_date.now()) time_delta = (expiration_date - expiration_date.now())

View File

@ -1402,6 +1402,9 @@ python-velbus==2.0.22
# homeassistant.components.media_player.vlc # homeassistant.components.media_player.vlc
python-vlc==1.1.2 python-vlc==1.1.2
# homeassistant.components.sensor.whois
python-whois==0.7.1
# homeassistant.components.wink # homeassistant.components.wink
python-wink==1.10.3 python-wink==1.10.3
@ -1414,9 +1417,6 @@ python_opendata_transport==0.1.4
# homeassistant.components.egardia # homeassistant.components.egardia
pythonegardia==1.0.39 pythonegardia==1.0.39
# homeassistant.components.sensor.whois
pythonwhois==2.4.3
# homeassistant.components.device_tracker.tile # homeassistant.components.device_tracker.tile
pytile==2.0.6 pytile==2.0.6

View File

@ -245,9 +245,6 @@ python-nest==4.1.0
# homeassistant.components.sensor.awair # homeassistant.components.sensor.awair
python_awair==0.0.3 python_awair==0.0.3
# homeassistant.components.sensor.whois
pythonwhois==2.4.3
# homeassistant.components.tradfri # homeassistant.components.tradfri
pytradfri[async]==6.0.1 pytradfri[async]==6.0.1