Bump pyecotrend-ista to 3.3.1 (#120037)
parent
5bbc4c80c5
commit
79bc6fc1a8
|
@ -4,14 +4,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pyecotrend_ista.exception_classes import (
|
from pyecotrend_ista import KeycloakError, LoginError, PyEcotrendIsta, ServerError
|
||||||
InternalServerError,
|
|
||||||
KeycloakError,
|
|
||||||
LoginError,
|
|
||||||
ServerError,
|
|
||||||
)
|
|
||||||
from pyecotrend_ista.pyecotrend_ista import PyEcotrendIsta
|
|
||||||
from requests.exceptions import RequestException
|
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
|
||||||
|
@ -37,7 +30,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: IstaConfigEntry) -> bool
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
await hass.async_add_executor_job(ista.login)
|
await hass.async_add_executor_job(ista.login)
|
||||||
except (ServerError, InternalServerError, RequestException, TimeoutError) as e:
|
except ServerError as e:
|
||||||
raise ConfigEntryNotReady(
|
raise ConfigEntryNotReady(
|
||||||
translation_domain=DOMAIN,
|
translation_domain=DOMAIN,
|
||||||
translation_key="connection_exception",
|
translation_key="connection_exception",
|
||||||
|
|
|
@ -3,15 +3,9 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from pyecotrend_ista.exception_classes import (
|
from pyecotrend_ista import KeycloakError, LoginError, PyEcotrendIsta, ServerError
|
||||||
InternalServerError,
|
|
||||||
KeycloakError,
|
|
||||||
LoginError,
|
|
||||||
ServerError,
|
|
||||||
)
|
|
||||||
from pyecotrend_ista.pyecotrend_ista import PyEcotrendIsta
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||||
|
@ -60,7 +54,8 @@ class IstaConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
await self.hass.async_add_executor_job(ista.login)
|
await self.hass.async_add_executor_job(ista.login)
|
||||||
except (ServerError, InternalServerError):
|
info = ista.get_account()
|
||||||
|
except ServerError:
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
except (LoginError, KeycloakError):
|
except (LoginError, KeycloakError):
|
||||||
errors["base"] = "invalid_auth"
|
errors["base"] = "invalid_auth"
|
||||||
|
@ -68,8 +63,10 @@ class IstaConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
_LOGGER.exception("Unexpected exception")
|
_LOGGER.exception("Unexpected exception")
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
else:
|
else:
|
||||||
title = f"{ista._a_firstName} {ista._a_lastName}".strip() # noqa: SLF001
|
if TYPE_CHECKING:
|
||||||
await self.async_set_unique_id(ista._uuid) # noqa: SLF001
|
assert info
|
||||||
|
title = f"{info["firstName"]} {info["lastName"]}".strip()
|
||||||
|
await self.async_set_unique_id(info["activeConsumptionUnit"])
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=title or "ista EcoTrend", data=user_input
|
title=title or "ista EcoTrend", data=user_input
|
||||||
|
|
|
@ -6,14 +6,7 @@ from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from pyecotrend_ista.exception_classes import (
|
from pyecotrend_ista import KeycloakError, LoginError, PyEcotrendIsta, ServerError
|
||||||
InternalServerError,
|
|
||||||
KeycloakError,
|
|
||||||
LoginError,
|
|
||||||
ServerError,
|
|
||||||
)
|
|
||||||
from pyecotrend_ista.pyecotrend_ista import PyEcotrendIsta
|
|
||||||
from requests.exceptions import RequestException
|
|
||||||
|
|
||||||
from homeassistant.const import CONF_EMAIL
|
from homeassistant.const import CONF_EMAIL
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -47,12 +40,7 @@ class IstaCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return await self.hass.async_add_executor_job(self.get_consumption_data)
|
return await self.hass.async_add_executor_job(self.get_consumption_data)
|
||||||
except (
|
except ServerError as e:
|
||||||
ServerError,
|
|
||||||
InternalServerError,
|
|
||||||
RequestException,
|
|
||||||
TimeoutError,
|
|
||||||
) as e:
|
|
||||||
raise UpdateFailed(
|
raise UpdateFailed(
|
||||||
"Unable to connect and retrieve data from ista EcoTrend, try again later"
|
"Unable to connect and retrieve data from ista EcoTrend, try again later"
|
||||||
) from e
|
) from e
|
||||||
|
@ -67,8 +55,8 @@ class IstaCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
"""Get raw json data for all consumption units."""
|
"""Get raw json data for all consumption units."""
|
||||||
|
|
||||||
return {
|
return {
|
||||||
consumption_unit: self.ista.get_raw(consumption_unit)
|
consumption_unit: self.ista.get_consumption_data(consumption_unit)
|
||||||
for consumption_unit in self.ista.getUUIDs()
|
for consumption_unit in self.ista.get_uuids()
|
||||||
}
|
}
|
||||||
|
|
||||||
async def async_get_details(self) -> dict[str, Any]:
|
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(
|
result = await self.hass.async_add_executor_job(
|
||||||
self.ista.get_consumption_unit_details
|
self.ista.get_consumption_unit_details
|
||||||
)
|
)
|
||||||
except (
|
except ServerError as e:
|
||||||
ServerError,
|
|
||||||
InternalServerError,
|
|
||||||
RequestException,
|
|
||||||
TimeoutError,
|
|
||||||
) as e:
|
|
||||||
raise UpdateFailed(
|
raise UpdateFailed(
|
||||||
"Unable to connect and retrieve data from ista EcoTrend, try again later"
|
"Unable to connect and retrieve data from ista EcoTrend, try again later"
|
||||||
) from e
|
) from e
|
||||||
|
@ -99,5 +82,5 @@ class IstaCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
for details in result["consumptionUnits"]
|
for details in result["consumptionUnits"]
|
||||||
if details["id"] == consumption_unit
|
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,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/ista_ecotrend",
|
"documentation": "https://www.home-assistant.io/integrations/ista_ecotrend",
|
||||||
"iot_class": "cloud_polling",
|
"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 dataclasses import dataclass
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
|
@ -23,6 +24,8 @@ from .const import DOMAIN
|
||||||
from .coordinator import IstaCoordinator
|
from .coordinator import IstaCoordinator
|
||||||
from .util import IstaConsumptionType, IstaValueType, get_native_value
|
from .util import IstaConsumptionType, IstaValueType, get_native_value
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@dataclass(kw_only=True, frozen=True)
|
@dataclass(kw_only=True, frozen=True)
|
||||||
class IstaSensorEntityDescription(SensorEntityDescription):
|
class IstaSensorEntityDescription(SensorEntityDescription):
|
||||||
|
|
|
@ -1815,7 +1815,7 @@ pyecoforest==0.4.0
|
||||||
pyeconet==0.1.22
|
pyeconet==0.1.22
|
||||||
|
|
||||||
# homeassistant.components.ista_ecotrend
|
# homeassistant.components.ista_ecotrend
|
||||||
pyecotrend-ista==3.2.0
|
pyecotrend-ista==3.3.1
|
||||||
|
|
||||||
# homeassistant.components.edimax
|
# homeassistant.components.edimax
|
||||||
pyedimax==0.2.1
|
pyedimax==0.2.1
|
||||||
|
|
|
@ -1429,7 +1429,7 @@ pyecoforest==0.4.0
|
||||||
pyeconet==0.1.22
|
pyeconet==0.1.22
|
||||||
|
|
||||||
# homeassistant.components.ista_ecotrend
|
# homeassistant.components.ista_ecotrend
|
||||||
pyecotrend-ista==3.2.0
|
pyecotrend-ista==3.3.1
|
||||||
|
|
||||||
# homeassistant.components.efergy
|
# homeassistant.components.efergy
|
||||||
pyefergy==22.5.0
|
pyefergy==22.5.0
|
||||||
|
|
|
@ -53,9 +53,11 @@ def mock_ista() -> Generator[MagicMock]:
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
client = mock_client.return_value
|
client = mock_client.return_value
|
||||||
client._uuid = "26e93f1a-c828-11ea-87d0-0242ac130003"
|
client.get_account.return_value = {
|
||||||
client._a_firstName = "Max"
|
"firstName": "Max",
|
||||||
client._a_lastName = "Istamann"
|
"lastName": "Istamann",
|
||||||
|
"activeConsumptionUnit": "26e93f1a-c828-11ea-87d0-0242ac130003",
|
||||||
|
}
|
||||||
client.get_consumption_unit_details.return_value = {
|
client.get_consumption_unit_details.return_value = {
|
||||||
"consumptionUnits": [
|
"consumptionUnits": [
|
||||||
{
|
{
|
||||||
|
@ -74,17 +76,17 @@ def mock_ista() -> Generator[MagicMock]:
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
client.getUUIDs.return_value = [
|
client.get_uuids.return_value = [
|
||||||
"26e93f1a-c828-11ea-87d0-0242ac130003",
|
"26e93f1a-c828-11ea-87d0-0242ac130003",
|
||||||
"eaf5c5c8-889f-4a3c-b68c-e9a676505762",
|
"eaf5c5c8-889f-4a3c-b68c-e9a676505762",
|
||||||
]
|
]
|
||||||
client.get_raw = get_raw
|
client.get_consumption_data = get_consumption_data
|
||||||
|
|
||||||
yield client
|
yield client
|
||||||
|
|
||||||
|
|
||||||
def get_raw(obj_uuid: str | None = None) -> dict[str, Any]:
|
def get_consumption_data(obj_uuid: str | None = None) -> dict[str, Any]:
|
||||||
"""Mock function get_raw."""
|
"""Mock function get_consumption_data."""
|
||||||
return {
|
return {
|
||||||
"consumptionUnitId": obj_uuid,
|
"consumptionUnitId": obj_uuid,
|
||||||
"consumptions": [
|
"consumptions": [
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
from unittest.mock import AsyncMock, MagicMock
|
from unittest.mock import AsyncMock, MagicMock
|
||||||
|
|
||||||
from pyecotrend_ista.exception_classes import LoginError, ServerError
|
from pyecotrend_ista import LoginError, ServerError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.ista_ecotrend.const import DOMAIN
|
from homeassistant.components.ista_ecotrend.const import DOMAIN
|
||||||
|
|
|
@ -2,14 +2,8 @@
|
||||||
|
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from pyecotrend_ista.exception_classes import (
|
from pyecotrend_ista import KeycloakError, LoginError, ParserError, ServerError
|
||||||
InternalServerError,
|
|
||||||
KeycloakError,
|
|
||||||
LoginError,
|
|
||||||
ServerError,
|
|
||||||
)
|
|
||||||
import pytest
|
import pytest
|
||||||
from requests.exceptions import RequestException
|
|
||||||
from syrupy.assertion import SnapshotAssertion
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
|
@ -39,12 +33,7 @@ async def test_entry_setup_unload(
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("side_effect"),
|
("side_effect"),
|
||||||
[
|
[ServerError, ParserError],
|
||||||
ServerError,
|
|
||||||
InternalServerError(None),
|
|
||||||
RequestException,
|
|
||||||
TimeoutError,
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
async def test_config_entry_not_ready(
|
async def test_config_entry_not_ready(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
@ -63,7 +52,7 @@ async def test_config_entry_not_ready(
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("side_effect"),
|
("side_effect"),
|
||||||
[LoginError(None), KeycloakError],
|
[LoginError, KeycloakError],
|
||||||
)
|
)
|
||||||
async def test_config_entry_error(
|
async def test_config_entry_error(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
|
|
@ -12,7 +12,7 @@ from homeassistant.components.ista_ecotrend.util import (
|
||||||
last_day_of_month,
|
last_day_of_month,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .conftest import get_raw
|
from .conftest import get_consumption_data
|
||||||
|
|
||||||
|
|
||||||
def test_as_number() -> None:
|
def test_as_number() -> None:
|
||||||
|
@ -86,7 +86,7 @@ def test_get_values_by_type(snapshot: SnapshotAssertion) -> None:
|
||||||
|
|
||||||
def test_get_native_value() -> None:
|
def test_get_native_value() -> None:
|
||||||
"""Test getting native value for sensor states."""
|
"""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.HEATING) == 35
|
||||||
assert get_native_value(test_data, IstaConsumptionType.HOT_WATER) == 1.0
|
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:
|
def test_get_statistics(snapshot: SnapshotAssertion) -> None:
|
||||||
"""Test get_statistics function."""
|
"""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:
|
for consumption_type in IstaConsumptionType:
|
||||||
assert get_statistics(test_data, consumption_type) == snapshot
|
assert get_statistics(test_data, consumption_type) == snapshot
|
||||||
assert get_statistics({"consumptions": None}, consumption_type) is None
|
assert get_statistics({"consumptions": None}, consumption_type) is None
|
||||||
|
|
Loading…
Reference in New Issue