diff --git a/homeassistant/components/growatt_server/__init__.py b/homeassistant/components/growatt_server/__init__.py index d20dd55bf74..350614fffbe 100644 --- a/homeassistant/components/growatt_server/__init__.py +++ b/homeassistant/components/growatt_server/__init__.py @@ -1,9 +1,11 @@ """The Growatt server PV inverter sensor integration.""" from collections.abc import Mapping +from json import JSONDecodeError import logging import growattServer +from requests import RequestException from homeassistant.const import CONF_PASSWORD, CONF_TOKEN, CONF_URL, CONF_USERNAME from homeassistant.core import HomeAssistant @@ -35,8 +37,7 @@ def get_device_list_classic( # Log in to api and fetch first plant if no plant id is defined. try: login_response = api.login(config[CONF_USERNAME], config[CONF_PASSWORD]) - # DEBUG: Log the actual response structure - except Exception as ex: + except (RequestException, JSONDecodeError) as ex: raise ConfigEntryError( f"Error communicating with Growatt API during login: {ex}" ) from ex @@ -53,7 +54,7 @@ def get_device_list_classic( if plant_id == DEFAULT_PLANT_ID: try: plant_info = api.plant_list(user_id) - except Exception as ex: + except (RequestException, JSONDecodeError) as ex: raise ConfigEntryError( f"Error communicating with Growatt API during plant list: {ex}" ) from ex @@ -64,7 +65,7 @@ def get_device_list_classic( # Get a list of devices for specified plant to add sensors for. try: devices = api.device_list(plant_id) - except Exception as ex: + except (RequestException, JSONDecodeError) as ex: raise ConfigEntryError( f"Error communicating with Growatt API during device list: {ex}" ) from ex diff --git a/homeassistant/components/growatt_server/quality_scale.yaml b/homeassistant/components/growatt_server/quality_scale.yaml index f49f109fcfb..f1af1216a47 100644 --- a/homeassistant/components/growatt_server/quality_scale.yaml +++ b/homeassistant/components/growatt_server/quality_scale.yaml @@ -28,9 +28,7 @@ rules: status: todo comment: Update server URL dropdown to show regional descriptions (e.g., 'China', 'United States') instead of raw URLs. docs-installation-parameters: todo - entity-unavailable: - status: todo - comment: Replace bare Exception catches in __init__.py with specific growattServer exceptions. + entity-unavailable: done integration-owner: done log-when-unavailable: done parallel-updates: done