11"""The Growatt server PV inverter sensor integration."""
22
33from collections .abc import Mapping
4+ from json import JSONDecodeError
45import logging
56
67import growattServer
8+ from requests import RequestException
79
810from homeassistant .const import CONF_PASSWORD , CONF_TOKEN , CONF_URL , CONF_USERNAME
911from homeassistant .core import HomeAssistant
@@ -35,8 +37,7 @@ def get_device_list_classic(
3537 # Log in to api and fetch first plant if no plant id is defined.
3638 try :
3739 login_response = api .login (config [CONF_USERNAME ], config [CONF_PASSWORD ])
38- # DEBUG: Log the actual response structure
39- except Exception as ex :
40+ except (RequestException , JSONDecodeError ) as ex :
4041 raise ConfigEntryError (
4142 f"Error communicating with Growatt API during login: { ex } "
4243 ) from ex
@@ -53,7 +54,7 @@ def get_device_list_classic(
5354 if plant_id == DEFAULT_PLANT_ID :
5455 try :
5556 plant_info = api .plant_list (user_id )
56- except Exception as ex :
57+ except ( RequestException , JSONDecodeError ) as ex :
5758 raise ConfigEntryError (
5859 f"Error communicating with Growatt API during plant list: { ex } "
5960 ) from ex
@@ -64,7 +65,7 @@ def get_device_list_classic(
6465 # Get a list of devices for specified plant to add sensors for.
6566 try :
6667 devices = api .device_list (plant_id )
67- except Exception as ex :
68+ except ( RequestException , JSONDecodeError ) as ex :
6869 raise ConfigEntryError (
6970 f"Error communicating with Growatt API during device list: { ex } "
7071 ) from ex
0 commit comments