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

build: use ruff as linter and formatter #91

Merged
merged 4 commits into from
Mar 8, 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
1 change: 1 addition & 0 deletions .github/scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Module of scripts."""
11 changes: 4 additions & 7 deletions .github/scripts/update_hacs_manifest.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
"""Update the manifest file."""

import json
import os
import sys


def update_manifest():
def update_manifest() -> None:
"""Update the manifest file."""
version = "0.0.0"
for index, value in enumerate(sys.argv):
if value in ["--version", "-V"]:
version = sys.argv[index + 1]

with open(
f"{os.getcwd()}/custom_components/dijnet/manifest.json"
) as manifestfile:
with open(f"{os.getcwd()}/custom_components/dijnet/manifest.json") as manifestfile:
manifest = json.load(manifestfile)

manifest["version"] = version

with open(
f"{os.getcwd()}/custom_components/dijnet/manifest.json", "w"
) as manifestfile:
with open(f"{os.getcwd()}/custom_components/dijnet/manifest.json", "w") as manifestfile:
manifestfile.write(json.dumps(manifest, indent=4, sort_keys=True))


Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI
on:
push:
pull_request:
workflow_dispatch:

jobs:
linters:
name: Linters
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: pip3 install homeassistant
- run: pip3 install ruff
- run: ruff check
- run: ruff format
13 changes: 13 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
ruff = "*"

[dev-packages]
ruff = "*"

[requires]
python_version = "3.12"
72 changes: 72 additions & 0 deletions Pipfile.lock

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

77 changes: 41 additions & 36 deletions custom_components/dijnet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,54 @@
'''Dijnet component.'''
"""Dijnet component."""

import logging

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.helpers.typing import ConfigType, HomeAssistantType

from .const import (CONF_DOWNLOAD_DIR,
CONF_ENCASHMENT_REPORTED_AS_PAID_AFTER_DEADLINE,
DATA_CONTROLLER, DOMAIN)
from .const import (
CONF_DOWNLOAD_DIR,
CONF_ENCASHMENT_REPORTED_AS_PAID_AFTER_DEADLINE,
DATA_CONTROLLER,
DOMAIN,
)
from .controller import DijnetController, is_controller_exists, set_controller

_LOGGER = logging.getLogger(__name__)

# pylint: disable=unused-argument

async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: # noqa: ARG001
"""
Sets up the Dijnet component.

async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
'''
Set up the Dijnet component.

Parameters
----------
hass: homeassistant.helpers.typing.HomeAssistantType
Args:
hass:
The Home Assistant instance.
config: homeassistant.helpers.typing.ConfigType
config:
The configuration.

Returns
-------
bool
The value indicates whether the setup succeeded.
'''
Returns:
The value indicates whether the setup succeeded.

"""
hass.data[DOMAIN] = {DATA_CONTROLLER: {}}
return True


async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry) -> bool:
'''
Initialize the sensors based on the config entry.
"""
Initializes the sensors based on the config entry.

Parameters
----------
hass: homeassistant.helpers.typing.HomeAssistantType
Args:
hass:
The Home Assistant instance.
config_entry: homeassistant.config_entries.ConfigEntry
config_entry:
The config entry which contains information gathered by the config flow.

Returns
-------
bool
The value indicates whether the setup succeeded.
'''
Returns:
The value indicates whether the setup succeeded.

"""
if not is_controller_exists(hass, config_entry.data[CONF_USERNAME]):
set_controller(
hass,
Expand All @@ -61,19 +57,28 @@ async def async_setup_entry(hass: HomeAssistantType, config_entry: ConfigEntry)
config_entry.data[CONF_USERNAME],
config_entry.data[CONF_PASSWORD],
config_entry.data[CONF_DOWNLOAD_DIR],
config_entry.data[CONF_ENCASHMENT_REPORTED_AS_PAID_AFTER_DEADLINE]
)
config_entry.data[CONF_ENCASHMENT_REPORTED_AS_PAID_AFTER_DEADLINE],
),
)

hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config_entry, 'sensor')
)
hass.async_create_task(hass.config_entries.async_forward_entry_setup(config_entry, "sensor"))

return True


async def async_migrate_entry(hass: HomeAssistantType, config_entry: ConfigEntry):
"""Migrate old entry."""
async def async_migrate_entry(hass: HomeAssistantType, config_entry: ConfigEntry) -> bool:
"""
Migrates old entry.

Args:
hass:
The Home Assistant instance.
config_entry:
The config entry to migrate.

Returns:
The value indicates whether the migration succeeded.
"""
_LOGGER.debug("Migrating from version %s", config_entry.version)

if config_entry.version == 1:
Expand Down
Loading