Skip to content

Commit 2beb551

Browse files
authored
Replace bare Exception with specific exceptions in Growatt (home-assistant#157790)
1 parent 90cea03 commit 2beb551

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

homeassistant/components/growatt_server/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""The Growatt server PV inverter sensor integration."""
22

33
from collections.abc import Mapping
4+
from json import JSONDecodeError
45
import logging
56

67
import growattServer
8+
from requests import RequestException
79

810
from homeassistant.const import CONF_PASSWORD, CONF_TOKEN, CONF_URL, CONF_USERNAME
911
from 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

homeassistant/components/growatt_server/quality_scale.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ rules:
2828
status: todo
2929
comment: Update server URL dropdown to show regional descriptions (e.g., 'China', 'United States') instead of raw URLs.
3030
docs-installation-parameters: todo
31-
entity-unavailable:
32-
status: todo
33-
comment: Replace bare Exception catches in __init__.py with specific growattServer exceptions.
31+
entity-unavailable: done
3432
integration-owner: done
3533
log-when-unavailable: done
3634
parallel-updates: done

0 commit comments

Comments
 (0)