From 0a6f541b27a5fdeef1081986f45bb2f394a39a73 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 18 Dec 2023 19:14:10 +0100 Subject: [PATCH] Avoid mutating entity descriptions in screenlogic (#105983) --- .../components/screenlogic/binary_sensor.py | 10 ++++++---- homeassistant/components/screenlogic/sensor.py | 12 +++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/screenlogic/binary_sensor.py b/homeassistant/components/screenlogic/binary_sensor.py index 9192458dde4..eb808835c58 100644 --- a/homeassistant/components/screenlogic/binary_sensor.py +++ b/homeassistant/components/screenlogic/binary_sensor.py @@ -1,6 +1,6 @@ """Support for a ScreenLogic Binary Sensor.""" from copy import copy -from dataclasses import dataclass +import dataclasses import logging from screenlogicpy.const.common import ON_OFF @@ -32,14 +32,14 @@ from .util import cleanup_excluded_entity _LOGGER = logging.getLogger(__name__) -@dataclass +@dataclasses.dataclass class ScreenLogicBinarySensorDescription( BinarySensorEntityDescription, ScreenLogicEntityDescription ): """A class that describes ScreenLogic binary sensor eneites.""" -@dataclass +@dataclasses.dataclass class ScreenLogicPushBinarySensorDescription( ScreenLogicBinarySensorDescription, ScreenLogicPushEntityDescription ): @@ -261,5 +261,7 @@ class ScreenLogicPumpBinarySensor(ScreenLogicBinarySensor): pump_index: int, ) -> None: """Initialize of the entity.""" - entity_description.data_root = (DEVICE.PUMP, pump_index) + entity_description = dataclasses.replace( + entity_description, data_root=(DEVICE.PUMP, pump_index) + ) super().__init__(coordinator, entity_description) diff --git a/homeassistant/components/screenlogic/sensor.py b/homeassistant/components/screenlogic/sensor.py index 5d4efc55883..4cd14fb7a16 100644 --- a/homeassistant/components/screenlogic/sensor.py +++ b/homeassistant/components/screenlogic/sensor.py @@ -1,7 +1,7 @@ """Support for a ScreenLogic Sensor.""" from collections.abc import Callable from copy import copy -from dataclasses import dataclass +import dataclasses import logging from screenlogicpy.const.data import ATTR, DEVICE, GROUP, VALUE @@ -35,21 +35,21 @@ from .util import cleanup_excluded_entity, get_ha_unit _LOGGER = logging.getLogger(__name__) -@dataclass +@dataclasses.dataclass class ScreenLogicSensorMixin: """Mixin for SecreenLogic sensor entity.""" value_mod: Callable[[int | str], int | str] | None = None -@dataclass +@dataclasses.dataclass class ScreenLogicSensorDescription( ScreenLogicSensorMixin, SensorEntityDescription, ScreenLogicEntityDescription ): """Describes a ScreenLogic sensor.""" -@dataclass +@dataclasses.dataclass class ScreenLogicPushSensorDescription( ScreenLogicSensorDescription, ScreenLogicPushEntityDescription ): @@ -336,7 +336,9 @@ class ScreenLogicPumpSensor(ScreenLogicSensor): pump_type: int, ) -> None: """Initialize of the entity.""" - entity_description.data_root = (DEVICE.PUMP, pump_index) + entity_description = dataclasses.replace( + entity_description, data_root=(DEVICE.PUMP, pump_index) + ) super().__init__(coordinator, entity_description) if entity_description.enabled_lambda: self._attr_entity_registry_enabled_default = (