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

Allow inheriting base component entity descriptions in frozen dataclasses #105512

Merged
merged 3 commits into from
Dec 16, 2023
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
4 changes: 1 addition & 3 deletions homeassistant/components/alarm_control_panel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Component to interface with an alarm control panel."""
from __future__ import annotations

from dataclasses import dataclass
from datetime import timedelta
import logging
from typing import Any, Final, final
Expand Down Expand Up @@ -121,8 +120,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class AlarmControlPanelEntityDescription(EntityDescription):
class AlarmControlPanelEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes alarm control panel entities."""


Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/binary_sensor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Component to interface with binary sensors."""
from __future__ import annotations

from dataclasses import dataclass
from datetime import timedelta
from enum import StrEnum
import logging
Expand Down Expand Up @@ -176,8 +175,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class BinarySensorEntityDescription(EntityDescription):
class BinarySensorEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes binary sensor entities."""

device_class: BinarySensorDeviceClass | None = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ def deserialize_entity_description(
descriptions_class: type[EntityDescription], data: dict[str, Any]
) -> EntityDescription:
"""Deserialize an entity description."""
# pylint: disable=protected-access
result: dict[str, Any] = {}
if hasattr(descriptions_class, "_dataclass"):
descriptions_class = descriptions_class._dataclass
for field in cached_fields(descriptions_class):
field_name = field.name
# It would be nice if field.type returned the actual
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/button/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Component to pressing a button as platforms."""
from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime, timedelta
from enum import StrEnum
import logging
Expand Down Expand Up @@ -73,8 +72,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class ButtonEntityDescription(EntityDescription):
class ButtonEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes button entities."""

device_class: ButtonDeviceClass | None = None
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import collections
from collections.abc import Awaitable, Callable, Iterable
from contextlib import suppress
from dataclasses import asdict, dataclass
from dataclasses import asdict
from datetime import datetime, timedelta
from enum import IntFlag
from functools import partial
Expand Down Expand Up @@ -132,8 +132,7 @@ class CameraEntityFeature(IntFlag):
}


@dataclass
class CameraEntityDescription(EntityDescription):
class CameraEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes camera entities."""


Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/climate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Provides functionality to interact with climate devices."""
from __future__ import annotations

from dataclasses import dataclass
from datetime import timedelta
import functools as ft
import logging
Expand Down Expand Up @@ -201,8 +200,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class ClimateEntityDescription(EntityDescription):
class ClimateEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes climate entities."""


Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/cover/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import annotations

from collections.abc import Callable
from dataclasses import dataclass
from datetime import timedelta
from enum import IntFlag, StrEnum
import functools as ft
Expand Down Expand Up @@ -212,8 +211,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class CoverEntityDescription(EntityDescription):
class CoverEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes cover entities."""

device_class: CoverDeviceClass | None = None
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/date/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Component to allow setting date as platforms."""
from __future__ import annotations

from dataclasses import dataclass
from datetime import date, timedelta
import logging
from typing import final
Expand Down Expand Up @@ -62,8 +61,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class DateEntityDescription(EntityDescription):
class DateEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes date entities."""


Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/datetime/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Component to allow setting date/time as platforms."""
from __future__ import annotations

from dataclasses import dataclass
from datetime import UTC, datetime, timedelta
import logging
from typing import final
Expand Down Expand Up @@ -71,8 +70,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class DateTimeEntityDescription(EntityDescription):
class DateTimeEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes date/time entities."""


Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/event/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class EventEntityDescription(EntityDescription):
class EventEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes event entities."""

device_class: EventDeviceClass | None = None
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/fan/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Provides functionality to interact with fans."""
from __future__ import annotations

from dataclasses import dataclass
from datetime import timedelta
from enum import IntFlag
import functools as ft
Expand Down Expand Up @@ -187,8 +186,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class FanEntityDescription(ToggleEntityDescription):
class FanEntityDescription(ToggleEntityDescription, frozen_or_thawed=True):
"""A class that describes fan entities."""


Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/humidifier/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Provides functionality to interact with humidifier devices."""
from __future__ import annotations

from dataclasses import dataclass
from datetime import timedelta
from enum import StrEnum
import logging
Expand Down Expand Up @@ -124,8 +123,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class HumidifierEntityDescription(ToggleEntityDescription):
class HumidifierEntityDescription(ToggleEntityDescription, frozen_or_thawed=True):
"""A class that describes humidifier entities."""

device_class: HumidifierDeviceClass | None = None
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
GET_IMAGE_TIMEOUT: Final = 10


@dataclass
class ImageEntityDescription(EntityDescription):
class ImageEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes image entities."""


Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/image_processing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import annotations

import asyncio
from dataclasses import dataclass
from datetime import timedelta
from enum import StrEnum
import logging
Expand Down Expand Up @@ -120,8 +119,7 @@ async def async_scan_service(service: ServiceCall) -> None:
return True


@dataclass
class ImageProcessingEntityDescription(EntityDescription):
class ImageProcessingEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes sensor entities."""

device_class: ImageProcessingDeviceClass | None = None
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/lawn_mower/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""The lawn mower integration."""
from __future__ import annotations

from dataclasses import dataclass
from datetime import timedelta
import logging
from typing import final
Expand Down Expand Up @@ -65,8 +64,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class LawnMowerEntityEntityDescription(EntityDescription):
class LawnMowerEntityEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes lawn mower entities."""


Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/light/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,7 @@ def apply_profile(self, name: str, params: dict[str, Any]) -> None:
params.setdefault(ATTR_TRANSITION, profile.transition)


@dataclasses.dataclass
class LightEntityDescription(ToggleEntityDescription):
class LightEntityDescription(ToggleEntityDescription, frozen_or_thawed=True):
"""A class that describes binary sensor entities."""


Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/lock/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Component to interface with locks that can be controlled remotely."""
from __future__ import annotations

from dataclasses import dataclass
from datetime import timedelta
from enum import IntFlag
import functools as ft
Expand Down Expand Up @@ -101,8 +100,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class LockEntityDescription(EntityDescription):
class LockEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes lock entities."""


Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/media_player/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import collections
from collections.abc import Callable
from contextlib import suppress
from dataclasses import dataclass
import datetime as dt
from enum import StrEnum
import functools as ft
Expand Down Expand Up @@ -449,8 +448,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class MediaPlayerEntityDescription(EntityDescription):
class MediaPlayerEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes media player entities."""

device_class: MediaPlayerDeviceClass | None = None
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/number/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclasses.dataclass
class NumberEntityDescription(EntityDescription):
class NumberEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes number entities."""

device_class: NumberDeviceClass | None = None
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/remote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import annotations

from collections.abc import Iterable
from dataclasses import dataclass
from datetime import timedelta
from enum import IntFlag
import functools as ft
Expand Down Expand Up @@ -155,8 +154,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class RemoteEntityDescription(ToggleEntityDescription):
class RemoteEntityDescription(ToggleEntityDescription, frozen_or_thawed=True):
"""A class that describes remote entities."""


Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/select/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Component to allow selecting an option from a list as platforms."""
from __future__ import annotations

from dataclasses import dataclass
from datetime import timedelta
import logging
from typing import Any, final
Expand Down Expand Up @@ -118,8 +117,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class SelectEntityDescription(EntityDescription):
class SelectEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes select entities."""

options: list[str] | None = None
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class SensorEntityDescription(EntityDescription):
class SensorEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes sensor entities."""

device_class: SensorDeviceClass | None = None
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/siren/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Component to interface with various sirens/chimes."""
from __future__ import annotations

from dataclasses import dataclass
from datetime import timedelta
import logging
from typing import Any, TypedDict, cast, final
Expand Down Expand Up @@ -149,8 +148,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class SirenEntityDescription(ToggleEntityDescription):
class SirenEntityDescription(ToggleEntityDescription, frozen_or_thawed=True):
"""A class that describes siren entities."""

available_tones: list[int | str] | dict[int, str] | None = None
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/switch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Component to interface with switches that can be controlled remotely."""
from __future__ import annotations

from dataclasses import dataclass
from datetime import timedelta
from enum import StrEnum
import logging
Expand Down Expand Up @@ -89,8 +88,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return await component.async_unload_entry(entry)


@dataclass
class SwitchEntityDescription(ToggleEntityDescription):
class SwitchEntityDescription(ToggleEntityDescription, frozen_or_thawed=True):
"""A class that describes switch entities."""

device_class: SwitchDeviceClass | None = None
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ class TextMode(StrEnum):
TEXT = "text"


@dataclass
class TextEntityDescription(EntityDescription):
class TextEntityDescription(EntityDescription, frozen_or_thawed=True):
"""A class that describes text entities."""

native_min: int = 0
Expand Down
Loading