Add exception handling to dnsip sensor (#17332)
* Add exception handling to dnsip sensor * Refactor import * Fix exception
This commit is contained in:
1 parent
b2789d9883
commit
241d87e9d3
1 file changed
+7
-2
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user