Skip to content

Commit

Permalink
Additional ruff rules
Browse files Browse the repository at this point in the history
  • Loading branch information
pail23 committed Jun 21, 2024
1 parent 4166aa3 commit 190bc2d
Show file tree
Hide file tree
Showing 19 changed files with 669 additions and 588 deletions.
33 changes: 19 additions & 14 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@
target-version = "py312"

lint.select = [
"B007", # Loop control variable {name} not used within loop body
"B014", # Exception handler with duplicate exception
"ASYNC", # async
"B", # Bug Bear
"C", # complexity
"D", # docstrings
"E", # pycodestyle
"F", # pyflakes/autoflake
"ICN001", # import concentions; {name} should be imported as {asname}
"PGH004", # Use specific rule codes when using noqa
"PLC0414", # Useless import alias. Import alias does not rename original package.
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
"SIM117", # Merge with-statements that use the same scope
"SIM118", # Use {key} in {dict} instead of {key} in {dict}.keys()
"SIM201", # Use {left} != {right} instead of not {left} == {right}
"SIM212", # Use {a} if {a} else {b} instead of {b} if not {a} else {a}
"SIM300", # Yoda conditions. Use 'age == 42' instead of '42 == age'.
"SIM401", # Use get from dict with default instead of an if block
"FLY",
"I", # isort
"N", # pep8-naming
"RUF", # ruff rules
"ICN", # import concentions
"PGH", # Use specific rule codes when using noqa
"PL",
"PLC", # Useless import alias.
"PLE", # pylint error
"RET",
"SIM", # simplify
"T20", # flake8-print
"TRY004", # Prefer TypeError exception for invalid type
"RUF006", # Store a reference to the return value of asyncio.create_task
"TRY", # tryceratops
"UP", # pyupgrade
"W", # pycodestyle
"YTT",
]

lint.ignore = [
Expand All @@ -36,6 +37,10 @@ lint.ignore = [
"D411", # Missing blank line before section
"E501", # line too long
"E731", # do not assign a lambda expression, use a def
"PLR2004",
"PLR0912",
"PLR0913",
"PLR0915",
]

[lint.flake8-pytest-style]
Expand Down
60 changes: 34 additions & 26 deletions custom_components/stiebel_eltron_isg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,26 @@
https://github.com/pail23/stiebel_eltron_isg
"""

from datetime import timedelta
import logging


import voluptuous as vol

from pymodbus.client import AsyncModbusTcpClient
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder
from datetime import timedelta

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, CONF_SCAN_INTERVAL
from homeassistant.core import Config, HomeAssistant
from homeassistant.const import CONF_NAME, CONF_HOST, CONF_PORT, CONF_SCAN_INTERVAL
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.loader import async_get_loaded_integration
from pymodbus.client import AsyncModbusTcpClient
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder

from custom_components.stiebel_eltron_isg.data import (
StiebEltronISGIntegrationData,
StiebelEltronISGIntegrationConfigEntry,
StiebEltronISGIntegrationData,
)
from custom_components.stiebel_eltron_isg.lwz_coordinator import (
StiebelEltronModbusLWZDataCoordinator,
)

from custom_components.stiebel_eltron_isg.wpm_coordinator import (
StiebelEltronModbusWPMDataCoordinator,
)
Expand All @@ -48,20 +44,24 @@
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_PORT): cv.string,
vol.Optional(
CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL
CONF_SCAN_INTERVAL,
default=DEFAULT_SCAN_INTERVAL,
): cv.positive_int,
}
},
)

CONFIG_SCHEMA = vol.Schema(
{DOMAIN: vol.Schema({cv.slug: STIEBEL_ELTRON_ISG_SCHEMA})}, extra=vol.ALLOW_EXTRA
{DOMAIN: vol.Schema({cv.slug: STIEBEL_ELTRON_ISG_SCHEMA})},
extra=vol.ALLOW_EXTRA,
)


class StiebelEltronModbusException(Exception):
class StiebelEltronModbusError(Exception):
"""Exception during modbus communication."""

pass
def __init(self) -> None:
"""Initialize the error."""
super().__init__("Data error on the modbus")


async def get_controller_model(host, port) -> int:
Expand All @@ -74,16 +74,17 @@ async def get_controller_model(host, port) -> int:
try:
await client.connect()
inverter_data = await client.read_input_registers(
address=5001, count=1, slave=1
address=5001,
count=1,
slave=1,
)
if not inverter_data.isError():
decoder = BinaryPayloadDecoder.fromRegisters(
inverter_data.registers, byteorder=Endian.BIG
inverter_data.registers,
byteorder=Endian.BIG,
)
model = decoder.decode_16bit_uint()
return model
else:
raise StiebelEltronModbusException("Data error on the modbus")
return decoder.decode_16bit_uint()
raise StiebelEltronModbusError
finally:
client.close()

Expand All @@ -94,7 +95,8 @@ async def async_setup(hass: HomeAssistant, config: Config):


async def async_setup_entry(
hass: HomeAssistant, entry: StiebelEltronISGIntegrationConfigEntry
hass: HomeAssistant,
entry: StiebelEltronISGIntegrationConfigEntry,
):
"""Set up this integration using UI."""

Expand All @@ -112,7 +114,11 @@ async def async_setup_entry(
StiebelEltronModbusWPMDataCoordinator(hass, name, host, port, scan_interval)
if model >= 390
else StiebelEltronModbusLWZDataCoordinator(
hass, name, host, port, scan_interval
hass,
name,
host,
port,
scan_interval,
)
)

Expand All @@ -132,7 +138,8 @@ async def async_setup_entry(


async def async_unload_entry(
hass: HomeAssistant, entry: StiebelEltronISGIntegrationConfigEntry
hass: HomeAssistant,
entry: StiebelEltronISGIntegrationConfigEntry,
) -> bool:
"""Handle removal of an entry."""
coordinator = entry.runtime_data.coordinator
Expand All @@ -141,7 +148,8 @@ async def async_unload_entry(


async def async_reload_entry(
hass: HomeAssistant, entry: StiebelEltronISGIntegrationConfigEntry
hass: HomeAssistant,
entry: StiebelEltronISGIntegrationConfigEntry,
) -> None:
"""Reload config entry."""
await async_unload_entry(hass, entry)
Expand Down
86 changes: 42 additions & 44 deletions custom_components/stiebel_eltron_isg/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,71 @@
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .entity import StiebelEltronISGEntity
from .const import (
DOMAIN,
IS_HEATING,
IS_COOLING,
IS_HEATING_WATER,
IS_SUMMER_MODE,
PUMP_ON_HK1,
PUMP_ON_HK2,
COMPRESSOR_ON,
SWITCHING_PROGRAM_ENABLED,
ELECTRIC_REHEATING,
SERVICE,
POWER_OFF,
FILTER,
VENTILATION,
EVAPORATOR_DEFROST,
FILTER_EXTRACT_AIR,
FILTER_VENTILATION_AIR,
HEAT_UP_PROGRAM,
NHZ_STAGES_RUNNING,
ERROR_STATUS,
HEATING_CIRCUIT_1_PUMP,
HEATING_CIRCUIT_2_PUMP,
HEATING_CIRCUIT_3_PUMP,
HEATING_CIRCUIT_4_PUMP,
HEATING_CIRCUIT_5_PUMP,
BUFFER_1_CHARGING_PUMP,
BUFFER_2_CHARGING_PUMP,
BUFFER_3_CHARGING_PUMP,
BUFFER_4_CHARGING_PUMP,
BUFFER_5_CHARGING_PUMP,
BUFFER_6_CHARGING_PUMP,
COMPRESSOR_ON,
COOLING_MODE,
DHW_CHARGING_PUMP,
SOURCE_PUMP,
DIFF_CONTROLLER_1_PUMP,
DIFF_CONTROLLER_2_PUMP,
POOL_PRIMARY_PUMP,
POOL_SECONDARY_PUMP,
DOMAIN,
ELECTRIC_REHEATING,
EMERGENCY_HEATING_1,
EMERGENCY_HEATING_1_2,
EMERGENCY_HEATING_2,
ERROR_STATUS,
EVAPORATOR_DEFROST,
FILTER,
FILTER_EXTRACT_AIR,
FILTER_VENTILATION_AIR,
HEAT_PUMP_1_ON,
HEAT_PUMP_2_ON,
HEAT_PUMP_3_ON,
HEAT_PUMP_4_ON,
HEAT_PUMP_5_ON,
HEAT_PUMP_6_ON,
SECOND_GENERATOR_DHW,
SECOND_GENERATOR_HEATING,
COOLING_MODE,
MIXER_OPEN_HTG_CIRCUIT_2,
MIXER_OPEN_HTG_CIRCUIT_3,
MIXER_OPEN_HTG_CIRCUIT_4,
MIXER_OPEN_HTG_CIRCUIT_5,
HEAT_UP_PROGRAM,
HEATING_CIRCUIT_1_PUMP,
HEATING_CIRCUIT_2_PUMP,
HEATING_CIRCUIT_3_PUMP,
HEATING_CIRCUIT_4_PUMP,
HEATING_CIRCUIT_5_PUMP,
IS_COOLING,
IS_HEATING,
IS_HEATING_WATER,
IS_SUMMER_MODE,
MIXER_CLOSE_HTG_CIRCUIT_2,
MIXER_CLOSE_HTG_CIRCUIT_3,
MIXER_CLOSE_HTG_CIRCUIT_4,
MIXER_CLOSE_HTG_CIRCUIT_5,
EMERGENCY_HEATING_1,
EMERGENCY_HEATING_2,
EMERGENCY_HEATING_1_2,
MIXER_OPEN_HTG_CIRCUIT_2,
MIXER_OPEN_HTG_CIRCUIT_3,
MIXER_OPEN_HTG_CIRCUIT_4,
MIXER_OPEN_HTG_CIRCUIT_5,
NHZ_STAGES_RUNNING,
POOL_PRIMARY_PUMP,
POOL_SECONDARY_PUMP,
POWER_OFF,
PUMP_ON_HK1,
PUMP_ON_HK2,
SECOND_GENERATOR_DHW,
SECOND_GENERATOR_HEATING,
SERVICE,
SOURCE_PUMP,
SWITCHING_PROGRAM_ENABLED,
VENTILATION,
)

from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .data import StiebelEltronISGIntegrationConfigEntry
from .entity import StiebelEltronISGEntity

BINARY_SENSOR_TYPES = [
BinarySensorEntityDescription(
Expand Down Expand Up @@ -414,7 +412,7 @@


async def async_setup_entry(
hass: HomeAssistant, # noqa: ARG001 Unused function argument: `hass`
hass: HomeAssistant, # Unused function argument: `hass`
entry: StiebelEltronISGIntegrationConfigEntry,
async_add_devices: AddEntitiesCallback,
):
Expand Down
18 changes: 7 additions & 11 deletions custom_components/stiebel_eltron_isg/button.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
"""Button platform for stiebel_eltron_isg."""

import logging

from collections.abc import Callable, Coroutine
from dataclasses import dataclass


from homeassistant.components.button import (
ButtonEntity,
ButtonEntityDescription,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN, RESET_HEATPUMP
from .entity import StiebelEltronISGEntity
from .coordinator import StiebelEltronModbusDataCoordinator

from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .data import StiebelEltronISGIntegrationConfigEntry

from .entity import StiebelEltronISGEntity

_LOGGER = logging.getLogger(__name__)

Expand All @@ -34,7 +29,8 @@ class StiebelEltronISGButtonDescriptionMixin:

@dataclass
class StiebelEltronISGButtonDescription(
ButtonEntityDescription, StiebelEltronISGButtonDescriptionMixin
ButtonEntityDescription,
StiebelEltronISGButtonDescriptionMixin,
):
"""Stiebel Eltron ISG button description."""

Expand All @@ -45,12 +41,12 @@ class StiebelEltronISGButtonDescription(
name="Reset Heatpump",
entity_category=EntityCategory.DIAGNOSTIC,
press_action=lambda coordinator: coordinator.async_reset_heatpump(),
)
),
]


async def async_setup_entry(
hass: HomeAssistant, # noqa: ARG001 Unused function argument: `hass`
hass: HomeAssistant, # Unused function argument: `hass`
entry: StiebelEltronISGIntegrationConfigEntry,
async_add_devices: AddEntitiesCallback,
):
Expand Down
Loading

0 comments on commit 190bc2d

Please sign in to comment.