Skip to content

Commit

Permalink
Enable ruff linter
Browse files Browse the repository at this point in the history
  • Loading branch information
masaccio committed Oct 19, 2023
1 parent 1203f99 commit f7507d6
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 45 deletions.
21 changes: 14 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
"[python]": {
"editor.formatOnSave": true,
"editor.wordWrap": "wordWrapColumn",
"editor.wordWrapColumn": 120,
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.wordWrapColumn": 100,
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
}
},
"python.formatting.provider": "none",
"python.linting.enabled": true,
"python.linting.lintOnSave": true,
"black-formatter.args": [],
"black-formatter.args": [
"--line-length",
"100"
],
"python.testing.pytestArgs": [
"tests"
],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false
"python.testing.unittestEnabled": false,
"ruff.lint.args": [
"--config=pyproject.toml"
],
}
20 changes: 11 additions & 9 deletions custom_components/kingspan_watchman_sensit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .api import SENSiTApiClient, APIError
from .api import APIError, SENSiTApiClient
from .const import (
CONF_KINGSPAN_DEBUG,
CONF_PASSWORD,
CONF_USERNAME,
CONF_USAGE_WINDOW,
CONF_UPDATE_INTERVAL,
DOMAIN,
PLATFORMS,
CONF_USAGE_WINDOW,
CONF_USERNAME,
DEFAULT_UPDATE_INTERVAL,
DEFAULT_USAGE_WINDOW,
DOMAIN,
PLATFORMS,
)

_LOGGER: logging.Logger = logging.getLogger(__package__)
Expand All @@ -41,20 +42,21 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
username = entry.data.get(CONF_USERNAME)
password = entry.data.get(CONF_PASSWORD)
usage_window = entry.options.get(CONF_USAGE_WINDOW, DEFAULT_USAGE_WINDOW)
kingspan_debug = entry.options.get(CONF_KINGSPAN_DEBUG, False)

if username is None or not username:
raise ConfigEntryAuthFailed(f"Credentials not set")
raise ConfigEntryAuthFailed("Credentials not set")

client = SENSiTApiClient(username, password, usage_window)
client = SENSiTApiClient(username, password, usage_window, kingspan_debug)
try:
_ = await client.check_credentials()
except APIError as e:
_LOGGER.debug("Credentials check for username '%s' failed: %s", username, e)
raise ConfigEntryAuthFailed(f"Credentials invalid") from e
raise ConfigEntryAuthFailed("Credentials invalid") from e
except TimeoutError as e:
_LOGGER.debug("Credentials check for username '%s' timed out: %s", username, e)
raise ConfigEntryNotReady(
f"Timed out while connecting to Kingspan service"
"Timed out while connecting to Kingspan service"
) from e

coordinator = SENSiTDataUpdateCoordinator(
Expand Down
8 changes: 4 additions & 4 deletions custom_components/kingspan_watchman_sensit/sensor.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""Sensor platform for Kingspan Watchman SENSiT."""
import logging

from decimal import Decimal
from datetime import timedelta
from decimal import Decimal

from homeassistant.components.sensor import (
SensorDeviceClass,
SensorStateClass,
SensorEntity,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, TIME_DAYS, UnitOfVolume
from homeassistant.core import HomeAssistant
from homeassistant.const import PERCENTAGE, UnitOfVolume, TIME_DAYS
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN
Expand Down
29 changes: 28 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 40 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ name = "ha-kingspan-connect-sensor"
packages = [{include = "custom_components/kingspan_watchman_sensit"}]
readme = "README.md"
repository = "https://github.com/masaccio/ha-kingspan-connect-sensor"
version = "1.4.5"
version = "1.5.0"

[tool.poetry.dependencies]
async-timeout = "^4.0.2"
Expand All @@ -32,6 +32,7 @@ pytest-mock = "^3.9.0"
toml = "^0.10.2"
pygithub = "^1.58.0"
pandas = "^2.0.2"
ruff = "^0.1.0"

[build-system]
build-backend = "poetry.core.masonry.api"
Expand All @@ -44,7 +45,7 @@ branch = true
directory = "coverage_html_report"

[tool.pytest.ini_options]
addopts = "-W ignore::DeprecationWarning --cov=custom_components/kingspan_watchman_sensit"
addopts = "-W ignore::DeprecationWarning --cov-report=html --cov-report=term-missing:skip-covered --cov-context=test --cov=custom_components/kingspan_watchman_sensit"
minversion = 6.0
asyncio_mode = "auto"
testpaths = ["tests"]
Expand All @@ -60,18 +61,43 @@ commands_pre = poetry install --no-root --sync
commands = poetry run -vvv pytest --import-mode importlib
"""

# linter settings
[tool.pylama]
linters = "pylint,mccabe,pyflakes"
max_line_length = 100
skip = ".tox/*"
[tool.isort]
profile = "black"

[tool.pylama.linter.pycodestyle]
format = "pylint"
ignore = "E203,E231,W503"
[tool.ruff]
exclude = [
# Machine-generated files
".bootstrap/*",
"src/numbers_parser/generated/*",
# Third-party files not to lint
"src/debug/lldbutil.py", # Tox
".tox/*",
]
fix = true
ignore = [
"PLR2004", # Allow constant values
]
line-length = 100
select = [
# Pyflakes including bugbears
"F",
"B", # Pycodestyle
"E",
"W", # isort
"I", # PEP naming
"N", # pyupgrade
"UP", # Pylama
"PL",
]
src = ["src", "tests"]
target-version = "py38"
unfixable = [
"ERA", # do not autoremove commented out code
]

[tool.pylama.linter.mccabe]
max-complexity = 15
[tool.ruff.pylint]
max-statements = 100
max-branches = 20

[tool.pylama.linter.pyflakes]
builtins = "_"
[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"
2 changes: 0 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from datetime import datetime, timezone

import pandas as pd
import pytest
from connectsensor import APIError

from custom_components.kingspan_watchman_sensit.api import SENSiTApiClient

from .const import (
Expand Down
9 changes: 4 additions & 5 deletions tests/test_init.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
"""Test Kingspan Watchman SENSiT setup process."""
import pytest

from homeassistant.exceptions import ConfigEntryNotReady, ConfigEntryAuthFailed
from pytest_homeassistant_custom_component.common import MockConfigEntry

from custom_components.kingspan_watchman_sensit import (
SENSiTDataUpdateCoordinator,
async_reload_entry,
async_setup_entry,
async_unload_entry,
SENSiTDataUpdateCoordinator,
)
from custom_components.kingspan_watchman_sensit.const import DOMAIN
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from pytest_homeassistant_custom_component.common import MockConfigEntry

from .const import MOCK_CONFIG


Expand Down
5 changes: 2 additions & 3 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
from datetime import datetime, timezone

import pytest
from custom_components.kingspan_watchman_sensit import async_unload_entry
from custom_components.kingspan_watchman_sensit.const import DOMAIN
from homeassistant.const import ATTR_ICON
from homeassistant.helpers import device_registry as dr
from pytest_homeassistant_custom_component.common import MockConfigEntry

from custom_components.kingspan_watchman_sensit import async_unload_entry
from custom_components.kingspan_watchman_sensit.const import DOMAIN

from .const import (
MOCK_CONFIG,
MOCK_TANK_CAPACITY,
Expand Down

0 comments on commit f7507d6

Please sign in to comment.