From 79bc6fc1a8fc0abd92c4bf9d0c6667fd40366c10 Mon Sep 17 00:00:00 2001 From: "Mr. Bubbles" Date: Fri, 21 Jun 2024 12:14:44 +0200 Subject: [PATCH] Bump pyecotrend-ista to 3.3.1 (#120037) --- .../components/ista_ecotrend/__init__.py | 11 ++----- .../components/ista_ecotrend/config_flow.py | 19 +++++------- .../components/ista_ecotrend/coordinator.py | 29 ++++--------------- .../components/ista_ecotrend/manifest.json | 3 +- .../components/ista_ecotrend/sensor.py | 3 ++ requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/ista_ecotrend/conftest.py | 16 +++++----- .../ista_ecotrend/test_config_flow.py | 2 +- tests/components/ista_ecotrend/test_init.py | 17 ++--------- tests/components/ista_ecotrend/test_util.py | 6 ++-- 11 files changed, 39 insertions(+), 71 deletions(-) diff --git a/homeassistant/components/ista_ecotrend/__init__.py b/homeassistant/components/ista_ecotrend/__init__.py index e1be000ccc4..5c1099f9d67 100644 --- a/homeassistant/components/ista_ecotrend/__init__.py +++ b/homeassistant/components/ista_ecotrend/__init__.py @@ -4,14 +4,7 @@ from __future__ import annotations import logging -from pyecotrend_ista.exception_classes import ( - InternalServerError, - KeycloakError, - LoginError, - ServerError, -) -from pyecotrend_ista.pyecotrend_ista import PyEcotrendIsta -from requests.exceptions import RequestException +from pyecotrend_ista import KeycloakError, LoginError, PyEcotrendIsta, ServerError from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform @@ -37,7 +30,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: IstaConfigEntry) -> bool ) try: await hass.async_add_executor_job(ista.login) - except (ServerError, InternalServerError, RequestException, TimeoutError) as e: + except ServerError as e: raise ConfigEntryNotReady( translation_domain=DOMAIN, translation_key="connection_exception", diff --git a/homeassistant/components/ista_ecotrend/config_flow.py b/homeassistant/components/ista_ecotrend/config_flow.py index 0bf1685eff4..86696950484 100644 --- a/homeassistant/components/ista_ecotrend/config_flow.py +++ b/homeassistant/components/ista_ecotrend/config_flow.py @@ -3,15 +3,9 @@ from __future__ import annotations import logging -from typing import Any +from typing import TYPE_CHECKING, Any -from pyecotrend_ista.exception_classes import ( - InternalServerError, - KeycloakError, - LoginError, - ServerError, -) -from pyecotrend_ista.pyecotrend_ista import PyEcotrendIsta +from pyecotrend_ista import KeycloakError, LoginError, PyEcotrendIsta, ServerError import voluptuous as vol from homeassistant.config_entries import ConfigFlow, ConfigFlowResult @@ -60,7 +54,8 @@ class IstaConfigFlow(ConfigFlow, domain=DOMAIN): ) try: await self.hass.async_add_executor_job(ista.login) - except (ServerError, InternalServerError): + info = ista.get_account() + except ServerError: errors["base"] = "cannot_connect" except (LoginError, KeycloakError): errors["base"] = "invalid_auth" @@ -68,8 +63,10 @@ class IstaConfigFlow(ConfigFlow, domain=DOMAIN): _LOGGER.exception("Unexpected exception") errors["base"] = "unknown" else: - title = f"{ista._a_firstName} {ista._a_lastName}".strip() # noqa: SLF001 - await self.async_set_unique_id(ista._uuid) # noqa: SLF001 + if TYPE_CHECKING: + assert info + title = f"{info["firstName"]} {info["lastName"]}".strip() + await self.async_set_unique_id(info["activeConsumptionUnit"]) self._abort_if_unique_id_configured() return self.async_create_entry( title=title or "ista EcoTrend", data=user_input diff --git a/homeassistant/components/ista_ecotrend/coordinator.py b/homeassistant/components/ista_ecotrend/coordinator.py index 78a31d560dd..b3be5883136 100644 --- a/homeassistant/components/ista_ecotrend/coordinator.py +++ b/homeassistant/components/ista_ecotrend/coordinator.py @@ -6,14 +6,7 @@ from datetime import timedelta import logging from typing import Any -from pyecotrend_ista.exception_classes import ( - InternalServerError, - KeycloakError, - LoginError, - ServerError, -) -from pyecotrend_ista.pyecotrend_ista import PyEcotrendIsta -from requests.exceptions import RequestException +from pyecotrend_ista import KeycloakError, LoginError, PyEcotrendIsta, ServerError from homeassistant.const import CONF_EMAIL from homeassistant.core import HomeAssistant @@ -47,12 +40,7 @@ class IstaCoordinator(DataUpdateCoordinator[dict[str, Any]]): try: return await self.hass.async_add_executor_job(self.get_consumption_data) - except ( - ServerError, - InternalServerError, - RequestException, - TimeoutError, - ) as e: + except ServerError as e: raise UpdateFailed( "Unable to connect and retrieve data from ista EcoTrend, try again later" ) from e @@ -67,8 +55,8 @@ class IstaCoordinator(DataUpdateCoordinator[dict[str, Any]]): """Get raw json data for all consumption units.""" return { - consumption_unit: self.ista.get_raw(consumption_unit) - for consumption_unit in self.ista.getUUIDs() + consumption_unit: self.ista.get_consumption_data(consumption_unit) + for consumption_unit in self.ista.get_uuids() } async def async_get_details(self) -> dict[str, Any]: @@ -77,12 +65,7 @@ class IstaCoordinator(DataUpdateCoordinator[dict[str, Any]]): result = await self.hass.async_add_executor_job( self.ista.get_consumption_unit_details ) - except ( - ServerError, - InternalServerError, - RequestException, - TimeoutError, - ) as e: + except ServerError as e: raise UpdateFailed( "Unable to connect and retrieve data from ista EcoTrend, try again later" ) from e @@ -99,5 +82,5 @@ class IstaCoordinator(DataUpdateCoordinator[dict[str, Any]]): for details in result["consumptionUnits"] if details["id"] == consumption_unit ) - for consumption_unit in self.ista.getUUIDs() + for consumption_unit in self.ista.get_uuids() } diff --git a/homeassistant/components/ista_ecotrend/manifest.json b/homeassistant/components/ista_ecotrend/manifest.json index 497d3d4a984..23d60a0a5bb 100644 --- a/homeassistant/components/ista_ecotrend/manifest.json +++ b/homeassistant/components/ista_ecotrend/manifest.json @@ -5,5 +5,6 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/ista_ecotrend", "iot_class": "cloud_polling", - "requirements": ["pyecotrend-ista==3.2.0"] + "loggers": ["pyecotrend_ista"], + "requirements": ["pyecotrend-ista==3.3.1"] } diff --git a/homeassistant/components/ista_ecotrend/sensor.py b/homeassistant/components/ista_ecotrend/sensor.py index 844b86e1689..c50f322c356 100644 --- a/homeassistant/components/ista_ecotrend/sensor.py +++ b/homeassistant/components/ista_ecotrend/sensor.py @@ -4,6 +4,7 @@ from __future__ import annotations from dataclasses import dataclass from enum import StrEnum +import logging from homeassistant.components.sensor import ( SensorDeviceClass, @@ -23,6 +24,8 @@ from .const import DOMAIN from .coordinator import IstaCoordinator from .util import IstaConsumptionType, IstaValueType, get_native_value +_LOGGER = logging.getLogger(__name__) + @dataclass(kw_only=True, frozen=True) class IstaSensorEntityDescription(SensorEntityDescription): diff --git a/requirements_all.txt b/requirements_all.txt index f949d864f54..c1568ac6056 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1815,7 +1815,7 @@ pyecoforest==0.4.0 pyeconet==0.1.22 # homeassistant.components.ista_ecotrend -pyecotrend-ista==3.2.0 +pyecotrend-ista==3.3.1 # homeassistant.components.edimax pyedimax==0.2.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index face667ccc5..7995497972c 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1429,7 +1429,7 @@ pyecoforest==0.4.0 pyeconet==0.1.22 # homeassistant.components.ista_ecotrend -pyecotrend-ista==3.2.0 +pyecotrend-ista==3.3.1 # homeassistant.components.efergy pyefergy==22.5.0 diff --git a/tests/components/ista_ecotrend/conftest.py b/tests/components/ista_ecotrend/conftest.py index a9eee5cd026..2218ef05ba7 100644 --- a/tests/components/ista_ecotrend/conftest.py +++ b/tests/components/ista_ecotrend/conftest.py @@ -53,9 +53,11 @@ def mock_ista() -> Generator[MagicMock]: ), ): client = mock_client.return_value - client._uuid = "26e93f1a-c828-11ea-87d0-0242ac130003" - client._a_firstName = "Max" - client._a_lastName = "Istamann" + client.get_account.return_value = { + "firstName": "Max", + "lastName": "Istamann", + "activeConsumptionUnit": "26e93f1a-c828-11ea-87d0-0242ac130003", + } client.get_consumption_unit_details.return_value = { "consumptionUnits": [ { @@ -74,17 +76,17 @@ def mock_ista() -> Generator[MagicMock]: }, ] } - client.getUUIDs.return_value = [ + client.get_uuids.return_value = [ "26e93f1a-c828-11ea-87d0-0242ac130003", "eaf5c5c8-889f-4a3c-b68c-e9a676505762", ] - client.get_raw = get_raw + client.get_consumption_data = get_consumption_data yield client -def get_raw(obj_uuid: str | None = None) -> dict[str, Any]: - """Mock function get_raw.""" +def get_consumption_data(obj_uuid: str | None = None) -> dict[str, Any]: + """Mock function get_consumption_data.""" return { "consumptionUnitId": obj_uuid, "consumptions": [ diff --git a/tests/components/ista_ecotrend/test_config_flow.py b/tests/components/ista_ecotrend/test_config_flow.py index e465d85e517..3375394f3f6 100644 --- a/tests/components/ista_ecotrend/test_config_flow.py +++ b/tests/components/ista_ecotrend/test_config_flow.py @@ -2,7 +2,7 @@ from unittest.mock import AsyncMock, MagicMock -from pyecotrend_ista.exception_classes import LoginError, ServerError +from pyecotrend_ista import LoginError, ServerError import pytest from homeassistant.components.ista_ecotrend.const import DOMAIN diff --git a/tests/components/ista_ecotrend/test_init.py b/tests/components/ista_ecotrend/test_init.py index 13b17333bbe..642afc820dd 100644 --- a/tests/components/ista_ecotrend/test_init.py +++ b/tests/components/ista_ecotrend/test_init.py @@ -2,14 +2,8 @@ from unittest.mock import MagicMock -from pyecotrend_ista.exception_classes import ( - InternalServerError, - KeycloakError, - LoginError, - ServerError, -) +from pyecotrend_ista import KeycloakError, LoginError, ParserError, ServerError import pytest -from requests.exceptions import RequestException from syrupy.assertion import SnapshotAssertion from homeassistant.config_entries import ConfigEntryState @@ -39,12 +33,7 @@ async def test_entry_setup_unload( @pytest.mark.parametrize( ("side_effect"), - [ - ServerError, - InternalServerError(None), - RequestException, - TimeoutError, - ], + [ServerError, ParserError], ) async def test_config_entry_not_ready( hass: HomeAssistant, @@ -63,7 +52,7 @@ async def test_config_entry_not_ready( @pytest.mark.parametrize( ("side_effect"), - [LoginError(None), KeycloakError], + [LoginError, KeycloakError], ) async def test_config_entry_error( hass: HomeAssistant, diff --git a/tests/components/ista_ecotrend/test_util.py b/tests/components/ista_ecotrend/test_util.py index e2e799aa78b..616abdea8d6 100644 --- a/tests/components/ista_ecotrend/test_util.py +++ b/tests/components/ista_ecotrend/test_util.py @@ -12,7 +12,7 @@ from homeassistant.components.ista_ecotrend.util import ( last_day_of_month, ) -from .conftest import get_raw +from .conftest import get_consumption_data def test_as_number() -> None: @@ -86,7 +86,7 @@ def test_get_values_by_type(snapshot: SnapshotAssertion) -> None: def test_get_native_value() -> None: """Test getting native value for sensor states.""" - test_data = get_raw("26e93f1a-c828-11ea-87d0-0242ac130003") + test_data = get_consumption_data("26e93f1a-c828-11ea-87d0-0242ac130003") assert get_native_value(test_data, IstaConsumptionType.HEATING) == 35 assert get_native_value(test_data, IstaConsumptionType.HOT_WATER) == 1.0 @@ -123,7 +123,7 @@ def test_get_native_value() -> None: def test_get_statistics(snapshot: SnapshotAssertion) -> None: """Test get_statistics function.""" - test_data = get_raw("26e93f1a-c828-11ea-87d0-0242ac130003") + test_data = get_consumption_data("26e93f1a-c828-11ea-87d0-0242ac130003") for consumption_type in IstaConsumptionType: assert get_statistics(test_data, consumption_type) == snapshot assert get_statistics({"consumptions": None}, consumption_type) is None