diff --git a/homeassistant/components/sense/__init__.py b/homeassistant/components/sense/__init__.py index 5c8028f2525866a343bffa9265ab308b52def78a..92a4e29108c022f2c82bad1a77b1d07d5102833b 100644 --- a/homeassistant/components/sense/__init__.py +++ b/homeassistant/components/sense/__init__.py @@ -3,11 +3,7 @@ import asyncio from datetime import timedelta import logging -from sense_energy import ( - ASyncSenseable, - SenseAPITimeoutException, - SenseAuthenticationException, -) +from sense_energy import ASyncSenseable, SenseAuthenticationException from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( @@ -30,6 +26,7 @@ from .const import ( SENSE_DEVICE_UPDATE, SENSE_DEVICES_DATA, SENSE_DISCOVERED_DEVICES_DATA, + SENSE_EXCEPTIONS, SENSE_TIMEOUT_EXCEPTIONS, 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") return False 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() try: sense_discovered_devices = await gateway.get_discovered_device_data() await gateway.update_realtime() 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( hass, @@ -114,8 +119,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Retrieve latest state.""" try: await gateway.update_realtime() - except SenseAPITimeoutException: - _LOGGER.error("Timeout retrieving data") + except SENSE_TIMEOUT_EXCEPTIONS as ex: + _LOGGER.error("Timeout retrieving data: %s", ex) + except SENSE_EXCEPTIONS as ex: + _LOGGER.error("Failed to update data: %s", ex) data = gateway.get_realtime() if "devices" in data: diff --git a/homeassistant/components/sense/const.py b/homeassistant/components/sense/const.py index af8454bbeab7485a5408913bd56bdc8fb8b1081f..bb323151950a1af1225799a801fab535d989b434 100644 --- a/homeassistant/components/sense/const.py +++ b/homeassistant/components/sense/const.py @@ -1,8 +1,10 @@ """Constants for monitoring a Sense energy sensor.""" import asyncio +import socket from sense_energy import SenseAPITimeoutException +from sense_energy.sense_exceptions import SenseWebsocketException DOMAIN = "sense" DEFAULT_TIMEOUT = 10 @@ -37,6 +39,7 @@ SOLAR_POWERED_ID = "solar_powered" ICON = "mdi:flash" SENSE_TIMEOUT_EXCEPTIONS = (asyncio.TimeoutError, SenseAPITimeoutException) +SENSE_EXCEPTIONS = (socket.gaierror, SenseWebsocketException) MDI_ICONS = { "ac": "air-conditioner",