Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #462 from DeebotUniverse/entity_description
Browse files Browse the repository at this point in the history
Remove entity description mixin
  • Loading branch information
edenhaus authored Nov 22, 2023
2 parents 02c9866 + 178e646 commit 4efceee
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 50 deletions.
15 changes: 5 additions & 10 deletions custom_components/deebot/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,17 @@
from .entity import DeebotEntity, DeebotEntityDescription, EventT


@dataclass
class DeebotBinarySensorEntityMixin(Generic[EventT]):
"""Deebot binary sensor entity mixin."""

value_fn: Callable[[EventT], bool | None]
icon_fn: Callable[[bool | None], str | None]


@dataclass
@dataclass(kw_only=True)
class DeebotBinarySensorEntityDescription(
BinarySensorEntityDescription, # type: ignore
DeebotEntityDescription,
DeebotBinarySensorEntityMixin[EventT],
Generic[EventT],
):
"""Class describing Deebot binary sensor entity."""

value_fn: Callable[[EventT], bool | None]
icon_fn: Callable[[bool | None], str | None]


ENTITY_DESCRIPTIONS: tuple[DeebotBinarySensorEntityDescription, ...] = (
DeebotBinarySensorEntityDescription[WaterInfoEvent](
Expand Down
2 changes: 1 addition & 1 deletion custom_components/deebot/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .entity import DeebotEntity, DeebotEntityDescription


@dataclass
@dataclass(kw_only=True)
class DeebotButtonEntityDescription(
ButtonEntityDescription, # type: ignore
DeebotEntityDescription,
Expand Down
12 changes: 3 additions & 9 deletions custom_components/deebot/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,15 @@
EventT = TypeVar("EventT", bound=Event)


@dataclass
class DeebotDescription(Generic[CapabilityT]):
"""Deebot description."""

capability_fn: Callable[[Capabilities], CapabilityT | None]


@dataclass
@dataclass(kw_only=True)
class DeebotEntityDescription(
EntityDescription, # type: ignore
DeebotDescription[CapabilityT],
Generic[CapabilityT],
):
"""Deebot Entity Description."""

always_available: bool = False
capability_fn: Callable[[Capabilities], CapabilityT | None]


class DeebotEntity(Entity, Generic[CapabilityT, _EntityDescriptionT]): # type: ignore
Expand Down
14 changes: 4 additions & 10 deletions custom_components/deebot/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,17 @@
from .entity import DeebotEntity, DeebotEntityDescription, EventT


@dataclass
class DeebotNumberEntityMixin(Generic[EventT]):
"""Deebot number entity mixin."""

value_fn: Callable[[EventT], float | None]


@dataclass
@dataclass(kw_only=True)
class DeebotNumberEntityDescription(
NumberEntityDescription, # type: ignore
DeebotEntityDescription,
DeebotNumberEntityMixin[EventT],
Generic[EventT],
):
"""Deebot number entity description."""

native_max_value_fn: Callable[[EventT], float | None] = lambda _: None
icon_fn: Callable[["DeebotNumberEntity"], str | None] = lambda _: None
native_max_value_fn: Callable[[EventT], float | None] = lambda _: None
value_fn: Callable[[EventT], float | None]


def _volume_icon(instance: "DeebotNumberEntity") -> str | None:
Expand Down
15 changes: 5 additions & 10 deletions custom_components/deebot/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,17 @@
from .entity import DeebotEntity, DeebotEntityDescription, EventT


@dataclass
class DeebotSelectEntityMixin(Generic[EventT]):
"""Deebot select entity mixin."""

current_option_fn: Callable[[EventT], str | None]
options_fn: Callable[[CapabilitySetTypes], list[str]]


@dataclass
@dataclass(kw_only=True)
class DeebotSelectEntityDescription(
SelectEntityDescription, # type: ignore
DeebotEntityDescription,
DeebotSelectEntityMixin[EventT],
Generic[EventT],
):
"""Deebot select entity description."""

current_option_fn: Callable[[EventT], str | None]
options_fn: Callable[[CapabilitySetTypes], list[str]]


ENTITY_DESCRIPTIONS: tuple[DeebotSelectEntityDescription, ...] = (
DeebotSelectEntityDescription(
Expand Down
12 changes: 3 additions & 9 deletions custom_components/deebot/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,18 @@
from .entity import DeebotEntity, DeebotEntityDescription, EventT


@dataclass
class DeebotSensorMixin(Generic[EventT]):
"""Deebot sensor mixin."""

value_fn: Callable[[EventT], StateType]


@dataclass
@dataclass(kw_only=True)
class DeebotSensorEntityDescription(
SensorEntityDescription, # type: ignore
DeebotEntityDescription,
DeebotSensorMixin[EventT],
Generic[EventT],
):
"""Deebot sensor entity description."""

extra_state_attributes_fn: Callable[
[EventT], MutableMapping[str, Any]
] | None = None
value_fn: Callable[[EventT], StateType]


def _clean_log_event_value(event: CleanLogEvent) -> str | None:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/deebot/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .entity import DeebotEntity, DeebotEntityDescription


@dataclass
@dataclass(kw_only=True)
class DeebotSwitchEntityDescription(
SwitchEntityDescription, # type: ignore
DeebotEntityDescription,
Expand Down

0 comments on commit 4efceee

Please sign in to comment.