diff --git a/custom_components/askoheat/__init__.py b/custom_components/askoheat/__init__.py index ca6692e..775f1f6 100644 --- a/custom_components/askoheat/__init__.py +++ b/custom_components/askoheat/__init__.py @@ -12,6 +12,7 @@ from homeassistant.const import CONF_HOST, CONF_PORT, Platform from homeassistant.loader import async_get_loaded_integration +from .api import AskoHeatModbusApiClient from .coordinator import ( AskoheatConfigDataUpdateCoordinator, AskoheatEMADataUpdateCoordinator, @@ -20,8 +21,6 @@ ) from .data import AskoheatData -from .api import AskoHeatModbusApiClient - if TYPE_CHECKING: from homeassistant.core import HomeAssistant diff --git a/custom_components/askoheat/api.py b/custom_components/askoheat/api.py index c6452ce..2b7b224 100644 --- a/custom_components/askoheat/api.py +++ b/custom_components/askoheat/api.py @@ -2,15 +2,13 @@ from __future__ import annotations +import struct from datetime import time from enum import ReprEnum -from struct import unpack -import struct -from tracemalloc import start from typing import TYPE_CHECKING, Any, TypeVar, cast import numpy as np -from numpy import byte, number +from numpy import number from pymodbus.client import AsyncModbusTcpClient as ModbusClient from custom_components.askoheat.api_conf_desc import CONF_REGISTER_BLOCK_DESCRIPTOR @@ -31,7 +29,7 @@ ) from custom_components.askoheat.api_ema_desc import EMA_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.api_op_desc import DATA_REGISTER_BLOCK_DESCRIPTOR -from custom_components.askoheat.api_par_desc import PARAMETER_REGISTER_BLOCK_DESCRIPTOR +from custom_components.askoheat.api_par_desc import PARAM_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.const import ( LOGGER, ) @@ -103,11 +101,11 @@ async def async_write_ema_data( async def async_read_par_data(self) -> AskoheatDataBlock: """Read PAR states.""" data = await self.__async_read_input_registers_data( - PARAMETER_REGISTER_BLOCK_DESCRIPTOR.starting_register, - PARAMETER_REGISTER_BLOCK_DESCRIPTOR.number_of_registers, + PARAM_REGISTER_BLOCK_DESCRIPTOR.starting_register, + PARAM_REGISTER_BLOCK_DESCRIPTOR.number_of_registers, ) LOGGER.debug("async_read_par_data %s", data) - return self.__map_data(PARAMETER_REGISTER_BLOCK_DESCRIPTOR, data) + return self.__map_data(PARAM_REGISTER_BLOCK_DESCRIPTOR, data) async def async_read_config_data(self) -> AskoheatDataBlock: """Read EMA states.""" diff --git a/custom_components/askoheat/api_desc.py b/custom_components/askoheat/api_desc.py index a7be48a..e88187a 100644 --- a/custom_components/askoheat/api_desc.py +++ b/custom_components/askoheat/api_desc.py @@ -2,8 +2,6 @@ from __future__ import annotations -import ctypes -from struct import pack import typing from abc import ABC from dataclasses import dataclass, field diff --git a/custom_components/askoheat/api_par_desc.py b/custom_components/askoheat/api_par_desc.py index 4924f16..9bb6b87 100644 --- a/custom_components/askoheat/api_par_desc.py +++ b/custom_components/askoheat/api_par_desc.py @@ -28,7 +28,7 @@ AskoheatSensorEntityDescription, ) -PARAMETER_REGISTER_BLOCK_DESCRIPTOR = RegisterBlockDescriptor( +PARAM_REGISTER_BLOCK_DESCRIPTOR = RegisterBlockDescriptor( starting_register=400, number_of_registers=56, sensors=[ diff --git a/custom_components/askoheat/binary_sensor.py b/custom_components/askoheat/binary_sensor.py index 2571a9b..d141500 100644 --- a/custom_components/askoheat/binary_sensor.py +++ b/custom_components/askoheat/binary_sensor.py @@ -13,7 +13,7 @@ from custom_components.askoheat.api_conf_desc import CONF_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.api_ema_desc import EMA_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.api_op_desc import DATA_REGISTER_BLOCK_DESCRIPTOR -from custom_components.askoheat.api_par_desc import PARAMETER_REGISTER_BLOCK_DESCRIPTOR +from custom_components.askoheat.api_par_desc import PARAM_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.model import AskoheatBinarySensorEntityDescription from .entity import AskoheatEntity @@ -41,7 +41,7 @@ async def async_setup_entry( for entity_description, coordinator in { **{ entity_description: entry.runtime_data.par_coordinator - for entity_description in PARAMETER_REGISTER_BLOCK_DESCRIPTOR.binary_sensors # noqa: E501 + for entity_description in PARAM_REGISTER_BLOCK_DESCRIPTOR.binary_sensors }, **{ entity_description: entry.runtime_data.ema_coordinator diff --git a/custom_components/askoheat/config_flow.py b/custom_components/askoheat/config_flow.py index 673dbef..756367e 100644 --- a/custom_components/askoheat/config_flow.py +++ b/custom_components/askoheat/config_flow.py @@ -17,7 +17,6 @@ AskoheatModbusApiClientError, ) from .const import ( - CONF_DEVICE_UNIQUE_ID, DEFAULT_HOST, DEFAULT_PORT, DOMAIN, @@ -71,7 +70,8 @@ async def async_step_user( _errors["base"] = "unknown" else: LOGGER.debug( - "Successfully connected to askoheat instance, received parameters: %s", + "Successfully connected to askoheat instance, " + "received parameters: %s", parameters, ) article_name = parameters[f"sensor.{SensorAttrKey.PAR_ARTICLE_NAME}"] diff --git a/custom_components/askoheat/coordinator.py b/custom_components/askoheat/coordinator.py index 87b9ad7..eff8549 100644 --- a/custom_components/askoheat/coordinator.py +++ b/custom_components/askoheat/coordinator.py @@ -16,8 +16,8 @@ DOMAIN, LOGGER, SCAN_INTERVAL_CONFIG, - SCAN_INTERVAL_OP_DATA, SCAN_INTERVAL_EMA, + SCAN_INTERVAL_OP_DATA, ) if TYPE_CHECKING: @@ -156,7 +156,8 @@ async def load_parameters(self, client: AskoHeatModbusApiClient) -> dict[str, An async def async_write(self, _: RegisterInputDescriptor, __: object) -> None: """Write parameter par block of Askoheat.""" - raise UpdateFailed("Writing values to parameters not allowed") + msg = "Writing values to parameters not allowed" + raise UpdateFailed(msg) class AskoheatOperationDataUpdateCoordinator(AskoheatDataUpdateCoordinator): @@ -177,7 +178,8 @@ async def _async_update_data(self) -> dict[str, Any]: async def async_write(self, _: RegisterInputDescriptor, __: object) -> None: """Write parameter data block of Askoheat.""" - raise UpdateFailed("Writing values to data block not allowed") + msg = "Writing values to data block not allowed" + raise UpdateFailed(msg) def _map_data_block_to_dict(data: AskoheatDataBlock) -> dict[str, Any]: diff --git a/custom_components/askoheat/entity.py b/custom_components/askoheat/entity.py index 0389ead..b99d994 100644 --- a/custom_components/askoheat/entity.py +++ b/custom_components/askoheat/entity.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import TypeVar +from typing import TYPE_CHECKING, TypeVar from homeassistant.core import callback from homeassistant.helpers.device_registry import DeviceInfo @@ -10,9 +10,11 @@ from custom_components.askoheat.model import AskoheatEntityDescription -from .const import ATTRIBUTION, CONF_DEVICE_UNIQUE_ID, LOGGER, DeviceKey +from .const import ATTRIBUTION, DeviceKey from .coordinator import AskoheatDataUpdateCoordinator -from .data import AskoheatConfigEntry + +if TYPE_CHECKING: + from .data import AskoheatConfigEntry E = TypeVar("E", bound=AskoheatEntityDescription) diff --git a/custom_components/askoheat/number.py b/custom_components/askoheat/number.py index c6c3e7d..943f0f8 100644 --- a/custom_components/askoheat/number.py +++ b/custom_components/askoheat/number.py @@ -9,7 +9,7 @@ from custom_components.askoheat.api_conf_desc import CONF_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.api_ema_desc import EMA_REGISTER_BLOCK_DESCRIPTOR -from custom_components.askoheat.api_par_desc import PARAMETER_REGISTER_BLOCK_DESCRIPTOR +from custom_components.askoheat.api_par_desc import PARAM_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.const import LOGGER from custom_components.askoheat.model import ( AskoheatNumberEntityDescription, @@ -40,7 +40,7 @@ async def async_setup_entry( for entity_description, coordinator in { **{ entity_description: entry.runtime_data.par_coordinator - for entity_description in PARAMETER_REGISTER_BLOCK_DESCRIPTOR.number_inputs + for entity_description in PARAM_REGISTER_BLOCK_DESCRIPTOR.number_inputs }, **{ entity_description: entry.runtime_data.ema_coordinator diff --git a/custom_components/askoheat/select.py b/custom_components/askoheat/select.py index aaf8301..41868f9 100644 --- a/custom_components/askoheat/select.py +++ b/custom_components/askoheat/select.py @@ -8,7 +8,7 @@ from custom_components.askoheat.api_conf_desc import CONF_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.api_ema_desc import EMA_REGISTER_BLOCK_DESCRIPTOR -from custom_components.askoheat.api_par_desc import PARAMETER_REGISTER_BLOCK_DESCRIPTOR +from custom_components.askoheat.api_par_desc import PARAM_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.const import LOGGER from custom_components.askoheat.coordinator import AskoheatDataUpdateCoordinator from custom_components.askoheat.model import ( @@ -34,7 +34,7 @@ async def async_setup_entry( for entity_description, coordinator in { **{ entity_description: entry.runtime_data.par_coordinator - for entity_description in PARAMETER_REGISTER_BLOCK_DESCRIPTOR.select_inputs + for entity_description in PARAM_REGISTER_BLOCK_DESCRIPTOR.select_inputs }, **{ entity_description: entry.runtime_data.ema_coordinator diff --git a/custom_components/askoheat/sensor.py b/custom_components/askoheat/sensor.py index 2df0af9..791c480 100644 --- a/custom_components/askoheat/sensor.py +++ b/custom_components/askoheat/sensor.py @@ -2,8 +2,6 @@ from __future__ import annotations -from datetime import date, datetime -from decimal import Decimal from typing import TYPE_CHECKING, Any import numpy as np @@ -14,16 +12,18 @@ from custom_components.askoheat.api_conf_desc import CONF_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.api_ema_desc import EMA_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.api_op_desc import DATA_REGISTER_BLOCK_DESCRIPTOR -from custom_components.askoheat.api_par_desc import PARAMETER_REGISTER_BLOCK_DESCRIPTOR +from custom_components.askoheat.api_par_desc import PARAM_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.model import ( AskoheatDurationSensorEntityDescription, AskoheatSensorEntityDescription, ) from .entity import AskoheatEntity -from custom_components.askoheat import entity if TYPE_CHECKING: + from datetime import date, datetime + from decimal import Decimal + from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType @@ -67,7 +67,7 @@ async def async_setup_entry( for entity_description, coordinator in { **{ entity_description: entry.runtime_data.par_coordinator - for entity_description in PARAMETER_REGISTER_BLOCK_DESCRIPTOR.sensors + for entity_description in PARAM_REGISTER_BLOCK_DESCRIPTOR.sensors }, **{ entity_description: entry.runtime_data.ema_coordinator diff --git a/custom_components/askoheat/switch.py b/custom_components/askoheat/switch.py index f4a37d5..7690f9d 100644 --- a/custom_components/askoheat/switch.py +++ b/custom_components/askoheat/switch.py @@ -9,7 +9,7 @@ from custom_components.askoheat.api_conf_desc import CONF_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.api_ema_desc import EMA_REGISTER_BLOCK_DESCRIPTOR -from custom_components.askoheat.api_par_desc import PARAMETER_REGISTER_BLOCK_DESCRIPTOR +from custom_components.askoheat.api_par_desc import PARAM_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.const import LOGGER from custom_components.askoheat.model import AskoheatSwitchEntityDescription @@ -38,7 +38,7 @@ async def async_setup_entry( for entity_description, coordinator in { **{ entity_description: entry.runtime_data.par_coordinator - for entity_description in PARAMETER_REGISTER_BLOCK_DESCRIPTOR.switches + for entity_description in PARAM_REGISTER_BLOCK_DESCRIPTOR.switches }, **{ entity_description: entry.runtime_data.ema_coordinator diff --git a/custom_components/askoheat/text.py b/custom_components/askoheat/text.py index 3d3f4af..3deadcf 100644 --- a/custom_components/askoheat/text.py +++ b/custom_components/askoheat/text.py @@ -6,7 +6,7 @@ from custom_components.askoheat.api_conf_desc import CONF_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.api_ema_desc import EMA_REGISTER_BLOCK_DESCRIPTOR -from custom_components.askoheat.api_par_desc import PARAMETER_REGISTER_BLOCK_DESCRIPTOR +from custom_components.askoheat.api_par_desc import PARAM_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.const import LOGGER from custom_components.askoheat.coordinator import AskoheatDataUpdateCoordinator from custom_components.askoheat.model import ( @@ -32,7 +32,7 @@ async def async_setup_entry( for entity_description, coordinator in { **{ entity_description: entry.runtime_data.par_coordinator - for entity_description in PARAMETER_REGISTER_BLOCK_DESCRIPTOR.text_inputs + for entity_description in PARAM_REGISTER_BLOCK_DESCRIPTOR.text_inputs }, **{ entity_description: entry.runtime_data.ema_coordinator diff --git a/custom_components/askoheat/time.py b/custom_components/askoheat/time.py index 4f71ba5..d49a4f0 100644 --- a/custom_components/askoheat/time.py +++ b/custom_components/askoheat/time.py @@ -8,7 +8,7 @@ from custom_components.askoheat.api_conf_desc import CONF_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.api_ema_desc import EMA_REGISTER_BLOCK_DESCRIPTOR -from custom_components.askoheat.api_par_desc import PARAMETER_REGISTER_BLOCK_DESCRIPTOR +from custom_components.askoheat.api_par_desc import PARAM_REGISTER_BLOCK_DESCRIPTOR from custom_components.askoheat.const import LOGGER from custom_components.askoheat.coordinator import AskoheatDataUpdateCoordinator from custom_components.askoheat.model import AskoheatTimeEntityDescription @@ -32,7 +32,7 @@ async def async_setup_entry( for entity_description, coordinator in { **{ entity_description: entry.runtime_data.par_coordinator - for entity_description in PARAMETER_REGISTER_BLOCK_DESCRIPTOR.time_inputs + for entity_description in PARAM_REGISTER_BLOCK_DESCRIPTOR.time_inputs }, **{ entity_description: entry.runtime_data.ema_coordinator