mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Handle exceptions when looking for new version (#48922)
This commit is contained in:
parent
f2f0331309
commit
af3b18c40a
@ -1,7 +1,9 @@
|
|||||||
"""Sensor that can display the current Home Assistant versions."""
|
"""Sensor that can display the current Home Assistant versions."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
|
|
||||||
from pyhaversion import HaVersion, HaVersionChannel, HaVersionSource
|
from pyhaversion import HaVersion, HaVersionChannel, HaVersionSource
|
||||||
|
from pyhaversion.exceptions import HaVersionFetchException, HaVersionParseException
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
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):
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||||
"""Set up the Version sensor platform."""
|
"""Set up the Version sensor platform."""
|
||||||
@ -114,7 +118,14 @@ class VersionData:
|
|||||||
@Throttle(TIME_BETWEEN_UPDATES)
|
@Throttle(TIME_BETWEEN_UPDATES)
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Get the latest version information."""
|
"""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):
|
class VersionSensor(SensorEntity):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user