|
6 | 6 | from typing import TYPE_CHECKING, Any |
7 | 7 |
|
8 | 8 | import growattServer |
| 9 | +from growattServer import GrowattV1ApiErrorCode |
9 | 10 | from requests import RequestException |
10 | 11 |
|
11 | 12 | from homeassistant.components.sensor import SensorStateClass |
|
27 | 28 | DEFAULT_URL, |
28 | 29 | DOMAIN, |
29 | 30 | LOGIN_INVALID_AUTH_CODE, |
30 | | - V1_API_ERROR_NO_PRIVILEGE, |
31 | 31 | V1_DEVICE_TYPES, |
32 | 32 | ) |
33 | 33 | from .models import GrowattRuntimeData |
@@ -113,7 +113,7 @@ def _sync_fetch_device_list(self) -> None: |
113 | 113 | if device.get("type") in V1_DEVICE_TYPES |
114 | 114 | ] |
115 | 115 | except growattServer.GrowattV1ApiError as err: |
116 | | - if err.error_code == V1_API_ERROR_NO_PRIVILEGE: |
| 116 | + if err.error_code == GrowattV1ApiErrorCode.NO_PRIVILEGE: |
117 | 117 | raise ConfigEntryAuthFailed( |
118 | 118 | f"Authentication failed for Growatt API: {err.error_msg or str(err)}" |
119 | 119 | ) from err |
@@ -179,7 +179,7 @@ def _sync_update_data(self) -> dict[str, Any]: |
179 | 179 | try: |
180 | 180 | total_info = self.api.plant_energy_overview(self.plant_id) |
181 | 181 | except growattServer.GrowattV1ApiError as err: |
182 | | - if err.error_code == V1_API_ERROR_NO_PRIVILEGE: |
| 182 | + if err.error_code == GrowattV1ApiErrorCode.NO_PRIVILEGE: |
183 | 183 | raise ConfigEntryAuthFailed( |
184 | 184 | "Authentication failed for Growatt API:" |
185 | 185 | f" {err.error_msg or str(err)}" |
@@ -212,7 +212,7 @@ def _sync_update_data(self) -> dict[str, Any]: |
212 | 212 | min_settings = self.api.min_settings(self.device_id) |
213 | 213 | min_energy = self.api.min_energy(self.device_id) |
214 | 214 | except growattServer.GrowattV1ApiError as err: |
215 | | - if err.error_code == V1_API_ERROR_NO_PRIVILEGE: |
| 215 | + if err.error_code == GrowattV1ApiErrorCode.NO_PRIVILEGE: |
216 | 216 | raise ConfigEntryAuthFailed( |
217 | 217 | "Authentication failed for Growatt API:" |
218 | 218 | f" {err.error_msg or str(err)}" |
@@ -240,7 +240,7 @@ def _sync_update_data(self) -> dict[str, Any]: |
240 | 240 | sph_detail = self.api.sph_detail(self.device_id) |
241 | 241 | sph_energy = self.api.sph_energy(self.device_id) |
242 | 242 | except growattServer.GrowattV1ApiError as err: |
243 | | - if err.error_code == V1_API_ERROR_NO_PRIVILEGE: |
| 243 | + if err.error_code == GrowattV1ApiErrorCode.NO_PRIVILEGE: |
244 | 244 | raise ConfigEntryAuthFailed( |
245 | 245 | "Authentication failed for Growatt API:" |
246 | 246 | f" {err.error_msg or str(err)}" |
|
0 commit comments