From 5323f4ca1076bd10c175f3c42f5839c6bd9e9443 Mon Sep 17 00:00:00 2001 From: Ludy87 Date: Sun, 14 Jan 2024 14:23:33 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20v2.3.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ludy87 --- .github/actions/get_version.py | 6 ++--- custom_components/ecotrend_ista/__init__.py | 3 ++- .../ecotrend_ista/config_flow.py | 12 +++++---- .../ecotrend_ista/const_schema.py | 3 ++- .../ecotrend_ista/coordinator.py | 25 ++++++++++++++----- custom_components/ecotrend_ista/manifest.json | 4 +-- custom_components/ecotrend_ista/sensor.py | 13 +++++++--- hacs.json | 4 +-- pyproject.toml | 3 +++ 9 files changed, 50 insertions(+), 23 deletions(-) diff --git a/.github/actions/get_version.py b/.github/actions/get_version.py index eb4516d..7bd3efc 100644 --- a/.github/actions/get_version.py +++ b/.github/actions/get_version.py @@ -1,11 +1,11 @@ -import json +import json # noqa: D100 import sys -def main(): +def main(): # noqa: D103 with open("./custom_components/ecotrend_ista/manifest.json") as json_file: data = json.load(json_file) - print(data["version"]) + print(data["version"]) # noqa: T201 return 0 diff --git a/custom_components/ecotrend_ista/__init__.py b/custom_components/ecotrend_ista/__init__.py index 23d7bec..ae5dbba 100644 --- a/custom_components/ecotrend_ista/__init__.py +++ b/custom_components/ecotrend_ista/__init__.py @@ -3,12 +3,13 @@ import logging +import voluptuous as vol + from homeassistant import config_entries from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform from homeassistant.core import HomeAssistant from homeassistant.helpers.typing import ConfigType -import voluptuous as vol from .const import DATA_HASS_CONFIG, DOMAIN from .const_schema import DEFAULT_DATA_SCHEMA diff --git a/custom_components/ecotrend_ista/config_flow.py b/custom_components/ecotrend_ista/config_flow.py index 345f4cc..6866327 100644 --- a/custom_components/ecotrend_ista/config_flow.py +++ b/custom_components/ecotrend_ista/config_flow.py @@ -3,8 +3,14 @@ import copy import logging +from types import MappingProxyType from typing import Any +from pyecotrend_ista.exception_classes import LoginError +from pyecotrend_ista.pyecotrend_ista import PyEcotrendIsta +import requests +import voluptuous as vol + from homeassistant import config_entries, core from homeassistant.const import CONF_EMAIL, CONF_PASSWORD from homeassistant.data_entry_flow import FlowResult @@ -13,10 +19,6 @@ NumberSelectorConfig, NumberSelectorMode, ) -from pyecotrend_ista.exception_classes import LoginError -from pyecotrend_ista.pyecotrend_ista import PyEcotrendIsta -import requests -import voluptuous as vol from .const import CONF_MFA, CONF_UPDATE_INTERVAL, CONF_URL, DOMAIN, MANUFACTURER from .const_schema import DATA_SCHEMA_EMAIL, URL_SELECTOR @@ -26,7 +28,7 @@ @staticmethod @core.callback -def login_account(hass: core.HomeAssistant, data: dict, demo: bool = False) -> PyEcotrendIsta: +def login_account(hass: core.HomeAssistant, data: MappingProxyType[str, Any], demo: bool = False) -> PyEcotrendIsta: """Log into an Ecotrend-Ista account and return an account instance.""" account = PyEcotrendIsta( email=data.get(CONF_EMAIL, None), diff --git a/custom_components/ecotrend_ista/const_schema.py b/custom_components/ecotrend_ista/const_schema.py index 76fe48c..b5c5140 100644 --- a/custom_components/ecotrend_ista/const_schema.py +++ b/custom_components/ecotrend_ista/const_schema.py @@ -1,6 +1,8 @@ """Const schema for ista EcoTrend Version 2.""" from __future__ import annotations +import voluptuous as vol + from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, CONF_SCAN_INTERVAL from homeassistant.helpers.selector import ( NumberSelector, @@ -14,7 +16,6 @@ TextSelectorConfig, TextSelectorType, ) -import voluptuous as vol from .const import ( CONF_MFA, diff --git a/custom_components/ecotrend_ista/coordinator.py b/custom_components/ecotrend_ista/coordinator.py index 192117a..f417687 100644 --- a/custom_components/ecotrend_ista/coordinator.py +++ b/custom_components/ecotrend_ista/coordinator.py @@ -8,13 +8,14 @@ import os from typing import Any -from homeassistant.config_entries import ConfigEntry -from homeassistant.core import HomeAssistant -from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from pyecotrend_ista.helper_object_de import CustomRaw from pyecotrend_ista.pyecotrend_ista import PyEcotrendIsta import requests +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.update_coordinator import DataUpdateCoordinator + from .config_flow import login_account from .const import CONF_UPDATE_INTERVAL, DOMAIN @@ -67,7 +68,11 @@ def set_controller(self) -> None: and other necessary configurations. """ data = self._entry.data - self.controller = login_account(self.hass, data, self._entry.options.get("dev_demo", False)) + self.controller = login_account( + self.hass, + data, + self._entry.options.get("dev_demo", False), + ) async def init(self) -> None: """Initialize the controller and perform the login.""" @@ -79,13 +84,21 @@ async def _async_update_data(self): try: await self.init() _consum_raw: dict[str, Any] = await self.hass.async_add_executor_job( - self.controller.consum_raw, [datetime.datetime.now().year] + self.controller.consum_raw, + [ + datetime.datetime.now().year, + datetime.datetime.now().year - 1, + ], ) if not isinstance(_consum_raw, dict): return self.data consum_raw: CustomRaw = CustomRaw.from_dict(_consum_raw) - await create_directory_file(self.hass, consum_raw, self.controller.getSupportCode()) + await create_directory_file( + self.hass, + consum_raw, + self.controller.getSupportCode(), + ) self.data = consum_raw self.async_set_updated_data(self.data) return self.data diff --git a/custom_components/ecotrend_ista/manifest.json b/custom_components/ecotrend_ista/manifest.json index 1b7f6b8..1f342e2 100644 --- a/custom_components/ecotrend_ista/manifest.json +++ b/custom_components/ecotrend_ista/manifest.json @@ -11,9 +11,9 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/Ludy87/ecotrend-ista/issues", "requirements": [ - "pyecotrend_ista==2.2.7", + "pyecotrend_ista==2.3.0", "pyotp==2.8.0", "marshmallow-enum==1.5.1" ], - "version": "v2.2.0" + "version": "v2.3.0" } diff --git a/custom_components/ecotrend_ista/sensor.py b/custom_components/ecotrend_ista/sensor.py index c6eefed..05fbd05 100644 --- a/custom_components/ecotrend_ista/sensor.py +++ b/custom_components/ecotrend_ista/sensor.py @@ -6,6 +6,9 @@ import logging from typing import Any, cast +from pyecotrend_ista.helper_object_de import CustomRaw +from pyecotrend_ista.pyecotrend_ista import PyEcotrendIsta + from homeassistant.components.sensor import RestoreSensor, SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -14,8 +17,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType from homeassistant.helpers.update_coordinator import CoordinatorEntity -from pyecotrend_ista.helper_object_de import CustomRaw -from pyecotrend_ista.pyecotrend_ista import PyEcotrendIsta from .const import ( CONF_TYPE_HEATING_CUSTOM, @@ -134,7 +135,13 @@ async def async_setup_entry( entities: list = [] consum_raw: CustomRaw = CustomRaw.from_dict( - await hass.async_add_executor_job(controller.consum_raw, [datetime.datetime.now().year]) + await hass.async_add_executor_job( + controller.consum_raw, + [ + datetime.datetime.now().year, + datetime.datetime.now().year - 1, + ], + ) ) consum_dict = consum_raw.to_dict() last_value = consum_dict.get("last_value", None) diff --git a/hacs.json b/hacs.json index 58868e8..a16a553 100644 --- a/hacs.json +++ b/hacs.json @@ -3,7 +3,7 @@ "zip_release": true, "country": "DE", "render_readme": true, - "homeassistant": "2023.10.1", + "homeassistant": "2023.12.1", "hacs": "1.33.0", "filename": "ecotrend_ista.zip" -} \ No newline at end of file +} diff --git a/pyproject.toml b/pyproject.toml index cbaf6e2..e616b47 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -94,6 +94,9 @@ ignore = [ ] +[tool.flake8] +max-line-length = 127 + [tool.ruff.flake8-pytest-style] fixture-parentheses = false