Skip to content

Commit

Permalink
style: apply stricter style guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger committed Aug 15, 2023
1 parent 37ed3c3 commit ebf2d1b
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 29 deletions.
3 changes: 0 additions & 3 deletions .codespell
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
hass
Adresse
oder
ist
adresse
adres
numer
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ repos:
exclude: |
(?x)^(
rye.lock|
custom_components/foldingathomecontrol/translations/de.json|
custom_components/foldingathomecontrol/translations/nb.json|
custom_components/foldingathomecontrol/translations/pl.json|
custom_components/foldingathomecontrol/translations/pt.json
Expand Down
1 change: 1 addition & 0 deletions custom_components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Custom components for Home Assistant."""
4 changes: 1 addition & 3 deletions custom_components/foldingathomecontrol/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Component to integrate with PyFoldingAtHomeControl.
"""
"""Component to integrate with PyFoldingAtHomeControl."""

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
Expand Down
3 changes: 1 addition & 2 deletions custom_components/foldingathomecontrol/button.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Support for foldingathomecontrol button entities."""
from __future__ import annotations

from typing import List

from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -50,7 +49,7 @@ async def async_setup_entry(

@callback
def async_add_buttons(
new_slots: List[str],
new_slots: list[str],
) -> None:
"""Add slot buttons callback."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import asyncio
import datetime
from typing import Any, Dict, List, Optional, Tuple
from typing import Any

from FoldingAtHomeControl import FoldingAtHomeController, PyOnMessageTypes
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
Expand Down Expand Up @@ -35,9 +35,9 @@ def __init__(self, hass: HomeAssistant, config_entry) -> None:
"""Initialize the class."""
self.hass = hass
self.config_entry = config_entry
self._slot_data: Dict[str, Dict[str, str | None]] = {}
self.slots: List[str] = []
self.options_data: Dict[str, str | None] = {}
self._slot_data: dict[str, dict[str, str | None]] = {}
self.slots: list[str] = []
self.options_data: dict[str, str | None] = {}
self._available = False
self.add_options()
self.client = FoldingAtHomeController(
Expand All @@ -54,7 +54,7 @@ def __init__(self, hass: HomeAssistant, config_entry) -> None:
self.client.on_disconnect(self.on_disconnect_callback)
self._tasks = self._start_background_tasks()

def _start_background_tasks(self) -> List[asyncio.Task[None]]:
def _start_background_tasks(self) -> list[asyncio.Task[None]]:
"""Start all background tasks."""

tasks = []
Expand Down Expand Up @@ -108,7 +108,7 @@ def set_read_timeout(self, read_timeout: int) -> None:

@callback
def data_received_callback(self, message_type: str, data: Any) -> None:
"""Called when data is received from the Folding@Home client."""
"""Handle data received from the Folding@Home client."""
self._available = True
if message_type == PyOnMessageTypes.SLOTS.value:
self.handle_slots_data_received(data)
Expand All @@ -122,7 +122,7 @@ def data_received_callback(self, message_type: str, data: Any) -> None:

@callback
def on_disconnect_callback(self) -> None:
"""Called when data is received from the Folding@Home client."""
"""Handle disconnection of the Folding@Home client."""
if self._available:
self._available = False
_LOGGER.error(
Expand Down Expand Up @@ -216,7 +216,7 @@ def handle_slots_data_received(self, slots_data: Any) -> None:
del self._slot_data[slot]
self.slots.remove(slot)

def calculate_slot_changes(self, slots: dict) -> Tuple[List[Any], List[str]]:
def calculate_slot_changes(self, slots: dict) -> tuple[list[Any], list[str]]:
"""Get added and removed slots."""
added = [slot["id"] for slot in slots if slot["id"] not in self.slots]
removed = [
Expand All @@ -234,8 +234,9 @@ def update_slots_data(self, data: Any) -> None:
self._slot_data[slot["id"]]["Idle"] = slot.get("idle")

@property
def slot_data(self) -> Dict[str, Dict[str, str | None]]:
def slot_data(self) -> dict[str, dict[str, str | None]]:
"""Slot for which slot data has been received.
Sometimes unit data does arrive before slots data.
Such a slot is not fully ready to be used.
"""
Expand Down Expand Up @@ -277,7 +278,7 @@ def sensor_removed_identifer(self) -> str:
return f"{SENSOR_REMOVED}_{self.address}"


def convert_eta_to_timestamp(eta: Optional[str]) -> Optional[datetime.datetime]:
def convert_eta_to_timestamp(eta: str | None) -> datetime.datetime | None:
"""Convert relative eta to a timestamp."""
if eta is None:
return None
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Base class for FoldingAtHomeControl devices."""
from typing import Callable, List
from collections.abc import Callable

from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import DeviceInfo, Entity, EntityDescription
Expand All @@ -15,7 +15,7 @@ def __init__(
self, client: FoldingAtHomeControlClient, entity_description: EntityDescription
) -> None:
self._client: FoldingAtHomeControlClient = client
self.listeners: List[Callable[[], None]] = []
self.listeners: list[Callable[[], None]] = []
self.entity_description = entity_description
self._attr_name = f"{client.address} {self.entity_description.name}"
self._attr_unique_id = self._attr_name
Expand Down
5 changes: 2 additions & 3 deletions custom_components/foldingathomecontrol/sensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Sensor platform for PyFoldingAtHomeControl."""
from typing import List

from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
from homeassistant.const import PERCENTAGE, TIME_SECONDS
Expand Down Expand Up @@ -132,8 +131,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the PyFoldingAtHomeControl sensors."""

@callback
def async_add_sensors(new_slots: List[str]) -> None:
"""add sensors callback."""
def async_add_sensors(new_slots: list[str]) -> None:
"""Add sensors callback."""

client = hass.data[DOMAIN][config_entry.entry_id][CLIENT]
dev: list = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dev-dependencies = [
]

[tool.pytest.ini_options]
addopts = "--cov --cov-report term-missing --cov=custom_components tests"
addopts = "--cov --cov-report term-missing --asyncio-mode=auto --cov=custom_components tests"

[tool.coverage.report]
show_missing = true
Expand Down
3 changes: 1 addition & 2 deletions tests/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Constants for foldingathomecontrol tests."""
from __future__ import annotations

from typing import Dict

from custom_components.foldingathomecontrol.const import (
CONF_ADDRESS,
Expand All @@ -10,7 +9,7 @@
)

# Mock config data to be used across multiple tests
MOCK_CONFIG: Dict[str, str | int] = {
MOCK_CONFIG: dict[str, str | int] = {
CONF_ADDRESS: "localhost",
CONF_PORT: 36330,
CONF_PASSWORD: "password",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def test_setup_entry_exception(hass):

@pytest.mark.usefixtures("bypass_login")
async def test_import(hass):
"""Test import from configuration.yaml"""
"""Test import from configuration.yaml."""
config = {DOMAIN: MOCK_CONFIG}
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
Expand Down

0 comments on commit ebf2d1b

Please sign in to comment.