Handle exceptions when looking for new version (#48922)

This commit is contained in:
Joakim Sørensen
2021-04-09 18:54:24 +02:00
committed by GitHub
parent f2f0331309
commit af3b18c40a

View File

@@ -1,7 +1,9 @@
"""Sensor that can display the current Home Assistant versions."""
from datetime import timedelta
import logging
from pyhaversion import HaVersion, HaVersionChannel, HaVersionSource
from pyhaversion.exceptions import HaVersionFetchException, HaVersionParseException
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
@@ -59,6 +61,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
}
)
_LOGGER: logging.Logger = logging.getLogger(__name__)
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Version sensor platform."""
@@ -114,7 +118,14 @@ class VersionData:
@Throttle(TIME_BETWEEN_UPDATES)
async def async_update(self):
"""Get the latest version information."""
await self.api.get_version()
try:
await self.api.get_version()
except HaVersionFetchException as exception:
_LOGGER.warning(exception)
except HaVersionParseException as exception:
_LOGGER.warning(
"Could not parse data received for %s - %s", self.api.source, exception
)
class VersionSensor(SensorEntity):