Bump pyecotrend-ista to 3.3.1 (#120037)
parent
5bbc4c80c5
commit
79bc6fc1a8
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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"]
|
||||
}
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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": [
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue