Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
cyr-ius committed Dec 14, 2024
1 parent 4dbec46 commit ecf2486
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 40 deletions.
19 changes: 14 additions & 5 deletions custom_components/bbox/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@

from __future__ import annotations

import logging
from collections.abc import Callable
from dataclasses import dataclass

from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType

from . import BBoxConfigEntry
from .entity import BboxEntity
from .helpers import BboxBinarySensorDescription, finditem
from .helpers import finditem

_LOGGER = logging.getLogger(__name__)

SENSOR_TYPES: tuple[BboxBinarySensorDescription, ...] = (
@dataclass(frozen=True)
class BboxBinarySensorDescription(BinarySensorEntityDescription):
"""Describes a sensor."""

value_fn: Callable[..., StateType] | None = None


BINARIES_SENSORS: tuple[BboxBinarySensorDescription, ...] = (
BboxBinarySensorDescription(
key="info.device.status",
name="Link status",
Expand All @@ -33,7 +42,7 @@ async def async_setup_entry(
"""Set up sensor."""
coordinator = entry.runtime_data
entities = [
BboxBinarySensor(coordinator, description) for description in SENSOR_TYPES
BboxBinarySensor(coordinator, description) for description in BINARIES_SENSORS
]
async_add_entities(entities)

Expand Down
4 changes: 0 additions & 4 deletions custom_components/bbox/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import logging
from typing import Any

from homeassistant.components.device_tracker import SourceType
Expand All @@ -15,8 +14,6 @@
from .coordinator import BboxDataUpdateCoordinator
from .entity import BboxDeviceEntity

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(
hass: HomeAssistant, entry: BBoxConfigEntry, async_add_entities: AddEntitiesCallback
Expand All @@ -36,7 +33,6 @@ async def async_setup_entry(
class BboxDeviceTracker(BboxDeviceEntity, ScannerEntity):
"""Representation of a tracked device."""

_attr_has_entity_name = True
_attr_entity_registry_enabled_default = False

def __init__(
Expand Down
3 changes: 0 additions & 3 deletions custom_components/bbox/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import logging
from typing import Any

from homeassistant.const import CONF_HOST
Expand All @@ -15,8 +14,6 @@
from .coordinator import BboxDataUpdateCoordinator
from .helpers import finditem

_LOGGER = logging.getLogger(__name__)


class BboxEntity(CoordinatorEntity[BboxDataUpdateCoordinator], Entity):
"""Base class for all Bbox entities."""
Expand Down
25 changes: 4 additions & 21 deletions custom_components/bbox/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,18 @@

from __future__ import annotations

from collections.abc import Callable
from dataclasses import dataclass
from typing import Any

from homeassistant.components.binary_sensor import BinarySensorEntityDescription
from homeassistant.components.sensor import SensorEntityDescription
from homeassistant.helpers.typing import StateType


@dataclass(frozen=True)
class BboxSensorDescription(SensorEntityDescription):
"""Describes a sensor."""

get_value: Callable[..., Any] | None = None
value_fn: Callable[..., StateType] | None = None


@dataclass(frozen=True)
class BboxBinarySensorDescription(BinarySensorEntityDescription):
"""Describes a sensor."""

value_fn: Callable[..., StateType] | None = None


def finditem(data: dict[str, Any], key_chain: str, default: Any = None) -> Any:
"""Get recursive key and return value.
data is a mandatory dictonnary
key , string with dot for key delimited (ex: "key.key.key")
It is possible to integrate an element of an array by indicating its index number
{"a":{"b":[{"c":"value"}]}
key = a.b.0.c
"""
if (keys := key_chain.split(".")) and isinstance(keys, list):
for key in keys:
Expand Down
17 changes: 14 additions & 3 deletions custom_components/bbox/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

from __future__ import annotations

import logging
from collections.abc import Callable
from dataclasses import dataclass
from typing import Any

from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.const import (
Expand All @@ -18,12 +21,20 @@
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType

from . import BBoxConfigEntry
from .entity import BboxEntity
from .helpers import BboxSensorDescription, finditem
from .helpers import finditem


@dataclass(frozen=True)
class BboxSensorDescription(SensorEntityDescription):
"""Describes a sensor."""

get_value: Callable[..., Any] | None = None
value_fn: Callable[..., StateType] | None = None

_LOGGER = logging.getLogger(__name__)

SENSOR_TYPES: tuple[BboxSensorDescription, ...] = (
BboxSensorDescription(
Expand Down
9 changes: 5 additions & 4 deletions custom_components/bbox/switch.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Button for Bbox router."""

import asyncio
import logging
from dataclasses import dataclass
import logging
from typing import Any, Final

from bboxpy.exceptions import BboxException

from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand All @@ -14,8 +15,6 @@
from .entity import BboxDeviceEntity, BboxEntity
from .helpers import finditem

_LOGGER = logging.getLogger(__name__)


@dataclass(frozen=True)
class BboxSwitchEntityDescription(SwitchEntityDescription):
Expand Down Expand Up @@ -87,6 +86,8 @@ class BboxSwitchEntityDescription(SwitchEntityDescription):
turn_off="async_set_device_parental_control_state",
)

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(
hass: HomeAssistant, entry: BBoxConfigEntry, async_add_entities: AddEntitiesCallback
Expand Down Expand Up @@ -157,7 +158,7 @@ class DeviceParentalControlSwitch(BboxDeviceEntity, BboxSwitch):
def __init__(
self,
coordinator: BboxDataUpdateCoordinator,
description: SwitchEntityDescription,
description: BboxSwitchEntityDescription,
device: dict[str, Any],
) -> None:
"""Initialize."""
Expand Down

0 comments on commit ecf2486

Please sign in to comment.