mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Fix uncaught exception in sense and retry later (#58623)
This commit is contained in:
parent
05353f8e13
commit
5f36fd2a80
@ -3,11 +3,7 @@ import asyncio
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from sense_energy import (
|
from sense_energy import ASyncSenseable, SenseAuthenticationException
|
||||||
ASyncSenseable,
|
|
||||||
SenseAPITimeoutException,
|
|
||||||
SenseAuthenticationException,
|
|
||||||
)
|
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -30,6 +26,7 @@ from .const import (
|
|||||||
SENSE_DEVICE_UPDATE,
|
SENSE_DEVICE_UPDATE,
|
||||||
SENSE_DEVICES_DATA,
|
SENSE_DEVICES_DATA,
|
||||||
SENSE_DISCOVERED_DEVICES_DATA,
|
SENSE_DISCOVERED_DEVICES_DATA,
|
||||||
|
SENSE_EXCEPTIONS,
|
||||||
SENSE_TIMEOUT_EXCEPTIONS,
|
SENSE_TIMEOUT_EXCEPTIONS,
|
||||||
SENSE_TRENDS_COORDINATOR,
|
SENSE_TRENDS_COORDINATOR,
|
||||||
)
|
)
|
||||||
@ -76,14 +73,22 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
_LOGGER.error("Could not authenticate with sense server")
|
_LOGGER.error("Could not authenticate with sense server")
|
||||||
return False
|
return False
|
||||||
except SENSE_TIMEOUT_EXCEPTIONS as err:
|
except SENSE_TIMEOUT_EXCEPTIONS as err:
|
||||||
raise ConfigEntryNotReady from err
|
raise ConfigEntryNotReady(
|
||||||
|
str(err) or "Timed out during authentication"
|
||||||
|
) from err
|
||||||
|
except SENSE_EXCEPTIONS as err:
|
||||||
|
raise ConfigEntryNotReady(str(err) or "Error during authentication") from err
|
||||||
|
|
||||||
sense_devices_data = SenseDevicesData()
|
sense_devices_data = SenseDevicesData()
|
||||||
try:
|
try:
|
||||||
sense_discovered_devices = await gateway.get_discovered_device_data()
|
sense_discovered_devices = await gateway.get_discovered_device_data()
|
||||||
await gateway.update_realtime()
|
await gateway.update_realtime()
|
||||||
except SENSE_TIMEOUT_EXCEPTIONS as err:
|
except SENSE_TIMEOUT_EXCEPTIONS as err:
|
||||||
raise ConfigEntryNotReady from err
|
raise ConfigEntryNotReady(
|
||||||
|
str(err) or "Timed out during realtime update"
|
||||||
|
) from err
|
||||||
|
except SENSE_EXCEPTIONS as err:
|
||||||
|
raise ConfigEntryNotReady(str(err) or "Error during realtime update") from err
|
||||||
|
|
||||||
trends_coordinator = DataUpdateCoordinator(
|
trends_coordinator = DataUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
@ -114,8 +119,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
try:
|
try:
|
||||||
await gateway.update_realtime()
|
await gateway.update_realtime()
|
||||||
except SenseAPITimeoutException:
|
except SENSE_TIMEOUT_EXCEPTIONS as ex:
|
||||||
_LOGGER.error("Timeout retrieving data")
|
_LOGGER.error("Timeout retrieving data: %s", ex)
|
||||||
|
except SENSE_EXCEPTIONS as ex:
|
||||||
|
_LOGGER.error("Failed to update data: %s", ex)
|
||||||
|
|
||||||
data = gateway.get_realtime()
|
data = gateway.get_realtime()
|
||||||
if "devices" in data:
|
if "devices" in data:
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
"""Constants for monitoring a Sense energy sensor."""
|
"""Constants for monitoring a Sense energy sensor."""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import socket
|
||||||
|
|
||||||
from sense_energy import SenseAPITimeoutException
|
from sense_energy import SenseAPITimeoutException
|
||||||
|
from sense_energy.sense_exceptions import SenseWebsocketException
|
||||||
|
|
||||||
DOMAIN = "sense"
|
DOMAIN = "sense"
|
||||||
DEFAULT_TIMEOUT = 10
|
DEFAULT_TIMEOUT = 10
|
||||||
@ -37,6 +39,7 @@ SOLAR_POWERED_ID = "solar_powered"
|
|||||||
ICON = "mdi:flash"
|
ICON = "mdi:flash"
|
||||||
|
|
||||||
SENSE_TIMEOUT_EXCEPTIONS = (asyncio.TimeoutError, SenseAPITimeoutException)
|
SENSE_TIMEOUT_EXCEPTIONS = (asyncio.TimeoutError, SenseAPITimeoutException)
|
||||||
|
SENSE_EXCEPTIONS = (socket.gaierror, SenseWebsocketException)
|
||||||
|
|
||||||
MDI_ICONS = {
|
MDI_ICONS = {
|
||||||
"ac": "air-conditioner",
|
"ac": "air-conditioner",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user