Add exception handling to dnsip sensor (#17332)

* Add exception handling to dnsip sensor

* Refactor import

* Fix exception
This commit is contained in:
Daniel Perna authored and Pascal Vizeli committed 2018-10-12 09:30:35 +02:00
1 parent b2789d9883
commit 241d87e9d3
1 file changed
+7 -2
+7 -2
View File
@@ -87,8 +87,13 @@ class WanIpSensor(Entity):
async def async_update(self):
"""Get the current DNS IP address for hostname."""
response = await self.resolver.query(self.hostname,
self.querytype)
from aiodns.error import DNSError
try:
response = await self.resolver.query(self.hostname,
self.querytype)
except DNSError as err:
_LOGGER.warning("Exception while resolving host: %s", err)
response = None
if response:
self._state = response[0].host
else: