Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly set up ruff as the formatter #755

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ repos:
rev: v0.9.4
hooks:
- id: ruff
- id: ruff-format
args: [--check]
# Temporarily disabled due to crash, probably caused by us having to use HA stubs which are out of date?
# See https://github.com/nathanmarlor/foxess_modbus/actions/runs/12610946302/job/35146070831?pr=720
# - repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"[python]": {
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"editor.defaultFormatter": "charliermarsh.ruff"
}
},
"python.analysis.extraPaths": [
"./custom_components/foxess_modbus/vendor/pymodbus/pymodbus-3.6.9"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def read(self, size: int = 1) -> bytes:
result == _PollResult.TIMEOUT
or result == _PollResult.ABORT
or timeout.expired()
or ((self._inter_byte_timeout is not None and self._inter_byte_timeout > 0)
and not buf)
or ((self._inter_byte_timeout is not None and self._inter_byte_timeout > 0) and not buf)
):
break # early abort on timeout
return bytes(read)
Expand Down
3 changes: 2 additions & 1 deletion custom_components/foxess_modbus/common/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""""Unsupported inverter exception"""
""" "Unsupported inverter exception"""

import logging


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unload controller"""

import logging
from typing import Callable

Expand Down
1 change: 1 addition & 0 deletions custom_components/foxess_modbus/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Adds config flow for foxess_modbus."""

import logging

from .const import DOMAIN
Expand Down
1 change: 1 addition & 0 deletions custom_components/foxess_modbus/entities/base_validator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Validation"""

from abc import ABC
from abc import abstractmethod

Expand Down
12 changes: 6 additions & 6 deletions custom_components/foxess_modbus/entities/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def _address_for_inverter_model(
if addresses is not None:
assert len(addresses) == 1, f"{self}: != 1 addresses defined for ({inverter_model}, {register_type})"
# We shouldn't get more than one spec which matches
assert (
result is None
), f"{self}: more than one address spec defined for ({inverter_model}, {register_type})"
assert result is None, (
f"{self}: more than one address spec defined for ({inverter_model}, {register_type})"
)
result = addresses[0]
return result

Expand All @@ -111,9 +111,9 @@ def _addresses_for_inverter_model(
addresses = spec.addresses_for_inverter_model(register_type=register_type, models=inverter_model)
if addresses is not None:
# We shouldn't get more than one spec which matches
assert (
result is None
), f"{self}: more than one address spec defined for ({inverter_model}, {register_type})"
assert result is None, (
f"{self}: more than one address spec defined for ({inverter_model}, {register_type})"
)
result = addresses
return result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ def create_charge_period_config_if_supported(
if inverter_model in address_spec.models:
address_config = address_spec.register_types.get(register_type)
if address_config is not None:
assert (
result is None
), f"{self}: multiple charge periods defined for ({inverter_model}, {register_type})"
assert result is None, (
f"{self}: multiple charge periods defined for ({inverter_model}, {register_type})"
)

start_id = get_entity_id(controller, Platform.SENSOR, self._period_start_key)
end_id = get_entity_id(controller, Platform.SENSOR, self._period_end_key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ def create_entity_if_supported(
other_address = self._address_for_inverter_model(self.other_address, inverter_model, register_type)

if address is None:
assert (
other_address is None
), f"{self}: address is None but other_address is {other_address} for ({inverter_model}, {register_type})"
assert other_address is None, (
f"{self}: address is None but other_address is {other_address} for ({inverter_model}, {register_type})"
)
return None

assert (
other_address is not None
), f"{self}: address is {address} but other_address is None for ({inverter_model}, {register_type})"
assert other_address is not None, (
f"{self}: address is {address} but other_address is None for ({inverter_model}, {register_type})"
)
return ModbusChargePeriodStartEndSensor(controller, self, address, other_address)

def serialize(self, inverter_model: Inv) -> dict[str, Any] | None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ def create_if_supported(
if inverter_model in address_spec.models:
address_config = address_spec.register_types.get(register_type)
if address_config is not None:
assert (
result is None
), f"{self}: multiple remote control addresses defined for ({inverter_model}, {register_type})"
assert result is None, (
f"{self}: multiple remote control addresses defined for ({inverter_model}, {register_type})"
)

result = address_config
return result
1 change: 1 addition & 0 deletions custom_components/foxess_modbus/entities/validation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Validation"""

from .base_validator import BaseValidator
from .modbus_charge_period_sensors import is_time_value_valid

Expand Down