From 2d362254053ad0225adc9526fe015d7b6e9d34fd Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Wed, 15 Nov 2023 09:16:47 +0100 Subject: [PATCH] Remove Reolink entity descriptions required fields mixins (#104006) --- .../components/reolink/binary_sensor.py | 16 +++------- homeassistant/components/reolink/button.py | 28 ++++------------ homeassistant/components/reolink/light.py | 18 +++-------- homeassistant/components/reolink/number.py | 20 ++++-------- homeassistant/components/reolink/select.py | 16 +++------- homeassistant/components/reolink/sensor.py | 14 ++------ homeassistant/components/reolink/switch.py | 32 +++++-------------- 7 files changed, 37 insertions(+), 107 deletions(-) diff --git a/homeassistant/components/reolink/binary_sensor.py b/homeassistant/components/reolink/binary_sensor.py index 7f2ff3e0053..bbf72056c9b 100644 --- a/homeassistant/components/reolink/binary_sensor.py +++ b/homeassistant/components/reolink/binary_sensor.py @@ -28,22 +28,14 @@ from .const import DOMAIN from .entity import ReolinkChannelCoordinatorEntity -@dataclass -class ReolinkBinarySensorEntityDescriptionMixin: - """Mixin values for Reolink binary sensor entities.""" - - value: Callable[[Host, int], bool] - - -@dataclass -class ReolinkBinarySensorEntityDescription( - BinarySensorEntityDescription, ReolinkBinarySensorEntityDescriptionMixin -): +@dataclass(kw_only=True) +class ReolinkBinarySensorEntityDescription(BinarySensorEntityDescription): """A class that describes binary sensor entities.""" - icon: str = "mdi:motion-sensor" icon_off: str = "mdi:motion-sensor-off" + icon: str = "mdi:motion-sensor" supported: Callable[[Host, int], bool] = lambda host, ch: True + value: Callable[[Host, int], bool] BINARY_SENSORS = ( diff --git a/homeassistant/components/reolink/button.py b/homeassistant/components/reolink/button.py index f1797527914..e0e067bd5f8 100644 --- a/homeassistant/components/reolink/button.py +++ b/homeassistant/components/reolink/button.py @@ -22,36 +22,22 @@ from .const import DOMAIN from .entity import ReolinkChannelCoordinatorEntity, ReolinkHostCoordinatorEntity -@dataclass -class ReolinkButtonEntityDescriptionMixin: - """Mixin values for Reolink button entities for a camera channel.""" - - method: Callable[[Host, int], Any] - - -@dataclass +@dataclass(kw_only=True) class ReolinkButtonEntityDescription( - ButtonEntityDescription, ReolinkButtonEntityDescriptionMixin + ButtonEntityDescription, ): """A class that describes button entities for a camera channel.""" - supported: Callable[[Host, int], bool] = lambda api, ch: True enabled_default: Callable[[Host, int], bool] | None = None + method: Callable[[Host, int], Any] + supported: Callable[[Host, int], bool] = lambda api, ch: True -@dataclass -class ReolinkHostButtonEntityDescriptionMixin: - """Mixin values for Reolink button entities for the host.""" - - method: Callable[[Host], Any] - - -@dataclass -class ReolinkHostButtonEntityDescription( - ButtonEntityDescription, ReolinkHostButtonEntityDescriptionMixin -): +@dataclass(kw_only=True) +class ReolinkHostButtonEntityDescription(ButtonEntityDescription): """A class that describes button entities for the host.""" + method: Callable[[Host], Any] supported: Callable[[Host], bool] = lambda api: True diff --git a/homeassistant/components/reolink/light.py b/homeassistant/components/reolink/light.py index 938093df4a3..2f00245a0de 100644 --- a/homeassistant/components/reolink/light.py +++ b/homeassistant/components/reolink/light.py @@ -23,23 +23,15 @@ from .const import DOMAIN from .entity import ReolinkChannelCoordinatorEntity -@dataclass -class ReolinkLightEntityDescriptionMixin: - """Mixin values for Reolink light entities.""" - - is_on_fn: Callable[[Host, int], bool] - turn_on_off_fn: Callable[[Host, int, bool], Any] - - -@dataclass -class ReolinkLightEntityDescription( - LightEntityDescription, ReolinkLightEntityDescriptionMixin -): +@dataclass(kw_only=True) +class ReolinkLightEntityDescription(LightEntityDescription): """A class that describes light entities.""" - supported_fn: Callable[[Host, int], bool] = lambda api, ch: True get_brightness_fn: Callable[[Host, int], int | None] | None = None + is_on_fn: Callable[[Host, int], bool] set_brightness_fn: Callable[[Host, int, int], Any] | None = None + supported_fn: Callable[[Host, int], bool] = lambda api, ch: True + turn_on_off_fn: Callable[[Host, int, bool], Any] LIGHT_ENTITIES = ( diff --git a/homeassistant/components/reolink/number.py b/homeassistant/components/reolink/number.py index 6be0cef1670..7e3f6483fb3 100644 --- a/homeassistant/components/reolink/number.py +++ b/homeassistant/components/reolink/number.py @@ -22,24 +22,16 @@ from .const import DOMAIN from .entity import ReolinkChannelCoordinatorEntity -@dataclass -class ReolinkNumberEntityDescriptionMixin: - """Mixin values for Reolink number entities.""" - - value: Callable[[Host, int], float | None] - method: Callable[[Host, int, float], Any] - - -@dataclass -class ReolinkNumberEntityDescription( - NumberEntityDescription, ReolinkNumberEntityDescriptionMixin -): +@dataclass(kw_only=True) +class ReolinkNumberEntityDescription(NumberEntityDescription): """A class that describes number entities.""" + get_max_value: Callable[[Host, int], float] | None = None + get_min_value: Callable[[Host, int], float] | None = None + method: Callable[[Host, int, float], Any] mode: NumberMode = NumberMode.AUTO supported: Callable[[Host, int], bool] = lambda api, ch: True - get_min_value: Callable[[Host, int], float] | None = None - get_max_value: Callable[[Host, int], float] | None = None + value: Callable[[Host, int], float | None] NUMBER_ENTITIES = ( diff --git a/homeassistant/components/reolink/select.py b/homeassistant/components/reolink/select.py index fd42e69268d..6cf2bf9f332 100644 --- a/homeassistant/components/reolink/select.py +++ b/homeassistant/components/reolink/select.py @@ -27,20 +27,12 @@ from .entity import ReolinkChannelCoordinatorEntity _LOGGER = logging.getLogger(__name__) -@dataclass -class ReolinkSelectEntityDescriptionMixin: - """Mixin values for Reolink select entities.""" - - method: Callable[[Host, int, str], Any] - get_options: list[str] | Callable[[Host, int], list[str]] - - -@dataclass -class ReolinkSelectEntityDescription( - SelectEntityDescription, ReolinkSelectEntityDescriptionMixin -): +@dataclass(kw_only=True) +class ReolinkSelectEntityDescription(SelectEntityDescription): """A class that describes select entities.""" + get_options: list[str] | Callable[[Host, int], list[str]] + method: Callable[[Host, int, str], Any] supported: Callable[[Host, int], bool] = lambda api, ch: True value: Callable[[Host, int], str] | None = None diff --git a/homeassistant/components/reolink/sensor.py b/homeassistant/components/reolink/sensor.py index b9e8ddb8e73..9a03f497944 100644 --- a/homeassistant/components/reolink/sensor.py +++ b/homeassistant/components/reolink/sensor.py @@ -24,20 +24,12 @@ from .const import DOMAIN from .entity import ReolinkChannelCoordinatorEntity, ReolinkHostCoordinatorEntity -@dataclass -class ReolinkSensorEntityDescriptionMixin: - """Mixin values for Reolink sensor entities for a camera channel.""" - - value: Callable[[Host, int], int] - - -@dataclass -class ReolinkSensorEntityDescription( - SensorEntityDescription, ReolinkSensorEntityDescriptionMixin -): +@dataclass(kw_only=True) +class ReolinkSensorEntityDescription(SensorEntityDescription): """A class that describes sensor entities for a camera channel.""" supported: Callable[[Host, int], bool] = lambda api, ch: True + value: Callable[[Host, int], int] @dataclass diff --git a/homeassistant/components/reolink/switch.py b/homeassistant/components/reolink/switch.py index f07db00e720..0dc46d22330 100644 --- a/homeassistant/components/reolink/switch.py +++ b/homeassistant/components/reolink/switch.py @@ -18,38 +18,22 @@ from .const import DOMAIN from .entity import ReolinkChannelCoordinatorEntity, ReolinkHostCoordinatorEntity -@dataclass -class ReolinkSwitchEntityDescriptionMixin: - """Mixin values for Reolink switch entities.""" - - value: Callable[[Host, int], bool] - method: Callable[[Host, int, bool], Any] - - -@dataclass -class ReolinkSwitchEntityDescription( - SwitchEntityDescription, ReolinkSwitchEntityDescriptionMixin -): +@dataclass(kw_only=True) +class ReolinkSwitchEntityDescription(SwitchEntityDescription): """A class that describes switch entities.""" + method: Callable[[Host, int, bool], Any] supported: Callable[[Host, int], bool] = lambda api, ch: True + value: Callable[[Host, int], bool] -@dataclass -class ReolinkNVRSwitchEntityDescriptionMixin: - """Mixin values for Reolink NVR switch entities.""" - - value: Callable[[Host], bool] - method: Callable[[Host, bool], Any] - - -@dataclass -class ReolinkNVRSwitchEntityDescription( - SwitchEntityDescription, ReolinkNVRSwitchEntityDescriptionMixin -): +@dataclass(kw_only=True) +class ReolinkNVRSwitchEntityDescription(SwitchEntityDescription): """A class that describes NVR switch entities.""" + method: Callable[[Host, bool], Any] supported: Callable[[Host], bool] = lambda api: True + value: Callable[[Host], bool] SWITCH_ENTITIES = (