Skip to content

Commit

Permalink
🐛 Fix linting issues
Browse files Browse the repository at this point in the history
- Update import statements in multiple files
- Modify error handling in config_flow.py
- Adjust Ruff configuration in pyproject.toml
- Update pylint settings and disable rules
- Refactor tests for improved readability
  • Loading branch information
hyperb1iss committed Aug 12, 2024
1 parent 7354534 commit f330c12
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 28 deletions.
4 changes: 2 additions & 2 deletions custom_components/signalrgb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
PLATFORMS: list[Platform] = [Platform.LIGHT]


async def async_setup(hass: HomeAssistant, config: dict) -> bool:
async def async_setup(hass: HomeAssistant, _config: dict) -> bool:
"""Set up the SignalRGB component."""
hass.data.setdefault(DOMAIN, {})
return True
Expand Down Expand Up @@ -57,4 +57,4 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"Failed to unload SignalRGB integration for %s", entry.data[CONF_HOST]
)

return unload_ok
return bool(unload_ok)
20 changes: 10 additions & 10 deletions custom_components/signalrgb/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from typing import Any

import voluptuous as vol
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.config_entries import ConfigFlow
from homeassistant.const import CONF_HOST, CONF_PORT
from homeassistant.data_entry_flow import FlowResult
from homeassistant.exceptions import HomeAssistantError
from signalrgb.client import SignalRGBClient, SignalRGBException
from signalrgb.client import SignalRGBClient

from .const import DEFAULT_PORT, DOMAIN
from .const import DEFAULT_PORT

DATA_SCHEMA = vol.Schema(
{
Expand All @@ -21,7 +21,7 @@
)


class SignalRGBConfigFlow(ConfigFlow, domain=DOMAIN):
class SignalRGBConfigFlow(ConfigFlow):
"""Handle a config flow for SignalRGB."""

VERSION = 1
Expand All @@ -40,11 +40,11 @@ async def async_step_user(
try:
client = SignalRGBClient(user_input[CONF_HOST], user_input[CONF_PORT])
await self.hass.async_add_executor_job(client.get_current_effect)
except InvalidAuth:
except InvalidAuthError:
errors["base"] = "invalid_auth"
except InvalidHost:
except InvalidHostError:
errors["base"] = "invalid_host"
except CannotConnect:
except CannotConnectError:
errors["base"] = "cannot_connect"
except Exception: # pylint: disable=broad-except
errors["base"] = "unknown"
Expand All @@ -60,13 +60,13 @@ async def async_step_user(
)


class CannotConnect(HomeAssistantError):
class CannotConnectError(HomeAssistantError):
"""Error to indicate we cannot connect."""


class InvalidAuth(HomeAssistantError):
class InvalidAuthError(HomeAssistantError):
"""Error to indicate there is invalid auth."""


class InvalidHost(HomeAssistantError):
class InvalidHostError(HomeAssistantError):
"""Error to indicate there is an invalid host."""
7 changes: 4 additions & 3 deletions custom_components/signalrgb/light.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
"""Support for SignalRGB lights."""

# pylint: disable=too-many-instance-attributes, abstract-method

from __future__ import annotations

import asyncio
from datetime import timedelta
from typing import Any

from signalrgb.client import SignalRGBClient, SignalRGBException
from signalrgb.model import Effect

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_EFFECT,
Expand All @@ -25,6 +24,8 @@
CoordinatorEntity,
DataUpdateCoordinator,
)
from signalrgb.client import SignalRGBClient, SignalRGBException
from signalrgb.model import Effect

from .const import (
DEFAULT_EFFECT,
Expand Down
11 changes: 6 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ ignore_missing_imports = true
[tool.pylint]
max-line-length = 88
disable = [
"C0103", # invalid-name
"C0111", # missing-docstring
"W0611", # unused-import
"W0212",
"W0621",

]

[tool.ruff]
select = ["E", "F", "B", "I", "N", "W", "C"]
ignore = ["E501"]
line-length = 88
target-version = "py312"

[tool.ruff.lint]
select = ["E", "F", "B", "I", "N", "W", "C"]
ignore = ["E501"]
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Pytest configuration file for the tests directory."""

import os
import sys
from pathlib import Path
from unittest import mock

import pytest
from pytest_homeassistant_custom_component.common import load_fixture

# Add the project root directory to the Python path
project_root = Path(__file__).parent.parent
Expand All @@ -17,6 +17,6 @@


@pytest.fixture(autouse=True)
def auto_enable_custom_integrations(enable_custom_integrations):
def auto_enable_custom_integrations(_enable_custom_integrations):
"""Enable custom integrations in Home Assistant."""
yield
7 changes: 2 additions & 5 deletions tests/test_light.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
"""Unit tests for the SignalRGB component."""

import asyncio
# pylint: disable=protected-access, redefined-outer-name

from unittest.mock import AsyncMock, MagicMock, patch

import pytest

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_EFFECT,
ColorMode,
LightEntityFeature,
)
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from custom_components.signalrgb import async_setup_entry, async_unload_entry
from custom_components.signalrgb.const import (
DEFAULT_EFFECT,
DEFAULT_PORT,
DOMAIN,
)
Expand Down

0 comments on commit f330c12

Please sign in to comment.