From e31a9167625625f00b214bf400221cf0b2ea55cd Mon Sep 17 00:00:00 2001 From: Antony Male Date: Sat, 23 Dec 2023 21:54:30 +0000 Subject: [PATCH] Make dataclasses frozen HA is moving to a model where dataclasses need to be frozen (to aid caching), and will start logging depreciation warnings in 2024.x. Let's get ahead of the game. See https://github.com/home-assistant/core/pull/105211 --- .../foxess_modbus/entities/modbus_battery_sensor.py | 2 +- .../foxess_modbus/entities/modbus_binary_sensor.py | 2 +- .../foxess_modbus/entities/modbus_charge_period_config.py | 6 +++--- .../foxess_modbus/entities/modbus_charge_period_sensors.py | 4 ++-- .../foxess_modbus/entities/modbus_fault_sensor.py | 2 +- .../foxess_modbus/entities/modbus_inverter_state_sensor.py | 2 +- .../foxess_modbus/entities/modbus_lambda_sensor.py | 2 +- custom_components/foxess_modbus/entities/modbus_number.py | 2 +- custom_components/foxess_modbus/entities/modbus_sensor.py | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/custom_components/foxess_modbus/entities/modbus_battery_sensor.py b/custom_components/foxess_modbus/entities/modbus_battery_sensor.py index 79bb672c..3977f651 100644 --- a/custom_components/foxess_modbus/entities/modbus_battery_sensor.py +++ b/custom_components/foxess_modbus/entities/modbus_battery_sensor.py @@ -16,7 +16,7 @@ from .modbus_sensor import ModbusSensorDescription -@dataclass(kw_only=True) +@dataclass(kw_only=True, frozen=True) class ModbusBatterySensorDescription(ModbusSensorDescription): """Description for ModbusBatterySensor""" diff --git a/custom_components/foxess_modbus/entities/modbus_binary_sensor.py b/custom_components/foxess_modbus/entities/modbus_binary_sensor.py index afb3db99..a985d703 100644 --- a/custom_components/foxess_modbus/entities/modbus_binary_sensor.py +++ b/custom_components/foxess_modbus/entities/modbus_binary_sensor.py @@ -23,7 +23,7 @@ _LOGGER = logging.getLogger(__name__) -@dataclass(kw_only=True) +@dataclass(kw_only=True, frozen=True) class ModbusBinarySensorDescription(BinarySensorEntityDescription, EntityFactory): """Description for ModbusBinarySensor""" diff --git a/custom_components/foxess_modbus/entities/modbus_charge_period_config.py b/custom_components/foxess_modbus/entities/modbus_charge_period_config.py index ad0c9a7d..481ca6d2 100644 --- a/custom_components/foxess_modbus/entities/modbus_charge_period_config.py +++ b/custom_components/foxess_modbus/entities/modbus_charge_period_config.py @@ -22,7 +22,7 @@ # mypy: disable-error-code="call-arg" -@dataclass +@dataclass(frozen=True) class ModbusChargePeriodAddressConfig: """Defines the set of registers which are used to define a charge period""" @@ -31,7 +31,7 @@ class ModbusChargePeriodAddressConfig: enable_charge_from_grid_address: int -@dataclass +@dataclass(frozen=True) class ModbusChargePeriodInfo: addresses: ModbusChargePeriodAddressConfig period_start_entity_id: str @@ -89,7 +89,7 @@ def get_enable_charge_from_grid_address(self) -> InverterModelSpec: return ModbusAddressSpecBase(self.models, addresses) -@dataclass +@dataclass(frozen=True) class ModbusChargePeriodFactory: """ Factory which creates various things required to define and specify a charge period diff --git a/custom_components/foxess_modbus/entities/modbus_charge_period_sensors.py b/custom_components/foxess_modbus/entities/modbus_charge_period_sensors.py index cccda82b..0f49f8e0 100644 --- a/custom_components/foxess_modbus/entities/modbus_charge_period_sensors.py +++ b/custom_components/foxess_modbus/entities/modbus_charge_period_sensors.py @@ -53,7 +53,7 @@ def _is_force_charge_enabled( return start_or_end_1 > 0 or start_or_end_2 > 0 -@dataclass(kw_only=True) +@dataclass(kw_only=True, frozen=True) class ModbusChargePeriodStartEndSensorDescription(SensorEntityDescription, EntityFactory): """Entity description for ModbusChargePeriodStartEndSensor""" @@ -179,7 +179,7 @@ def addresses(self) -> list[int]: return [self._address, self._other_address] -@dataclass(kw_only=True) +@dataclass(kw_only=True, frozen=True) class ModbusEnableForceChargeSensorDescription(BinarySensorEntityDescription, EntityFactory): """Entity description for ModbusEnableForceChargeSensor""" diff --git a/custom_components/foxess_modbus/entities/modbus_fault_sensor.py b/custom_components/foxess_modbus/entities/modbus_fault_sensor.py index e92c3f8c..b48025dd 100644 --- a/custom_components/foxess_modbus/entities/modbus_fault_sensor.py +++ b/custom_components/foxess_modbus/entities/modbus_fault_sensor.py @@ -155,7 +155,7 @@ assert any(fault for fault_list in _FAULTS for fault in fault_list if fault == assert_mask) -@dataclass(kw_only=True) +@dataclass(kw_only=True, frozen=True) class ModbusFaultSensorDescription(SensorEntityDescription, EntityFactory): """Description for ModbusFaultSensor""" diff --git a/custom_components/foxess_modbus/entities/modbus_inverter_state_sensor.py b/custom_components/foxess_modbus/entities/modbus_inverter_state_sensor.py index 5c7c0346..20713654 100644 --- a/custom_components/foxess_modbus/entities/modbus_inverter_state_sensor.py +++ b/custom_components/foxess_modbus/entities/modbus_inverter_state_sensor.py @@ -37,7 +37,7 @@ ] -@dataclass(kw_only=True) +@dataclass(kw_only=True, frozen=True) class ModbusInverterStateSensorDescription(SensorEntityDescription, EntityFactory): """Description for ModbusInverterStateSensor""" diff --git a/custom_components/foxess_modbus/entities/modbus_lambda_sensor.py b/custom_components/foxess_modbus/entities/modbus_lambda_sensor.py index 56f27d1e..22b9cee3 100644 --- a/custom_components/foxess_modbus/entities/modbus_lambda_sensor.py +++ b/custom_components/foxess_modbus/entities/modbus_lambda_sensor.py @@ -23,7 +23,7 @@ _LOGGER = logging.getLogger(__name__) -@dataclass(kw_only=True) +@dataclass(kw_only=True, frozen=True) class ModbusLambdaSensorDescription(SensorEntityDescription, EntityFactory): """Entity description for ModbusLambdaSensors""" diff --git a/custom_components/foxess_modbus/entities/modbus_number.py b/custom_components/foxess_modbus/entities/modbus_number.py index e23ef30e..66aed31c 100644 --- a/custom_components/foxess_modbus/entities/modbus_number.py +++ b/custom_components/foxess_modbus/entities/modbus_number.py @@ -24,7 +24,7 @@ _LOGGER: logging.Logger = logging.getLogger(__package__) -@dataclass(kw_only=True) +@dataclass(kw_only=True, frozen=True) class ModbusNumberDescription(NumberEntityDescription, EntityFactory): """Custom number entity description""" diff --git a/custom_components/foxess_modbus/entities/modbus_sensor.py b/custom_components/foxess_modbus/entities/modbus_sensor.py index ce03d50b..6af498fe 100644 --- a/custom_components/foxess_modbus/entities/modbus_sensor.py +++ b/custom_components/foxess_modbus/entities/modbus_sensor.py @@ -25,7 +25,7 @@ _LOGGER = logging.getLogger(__name__) -@dataclass(kw_only=True) +@dataclass(kw_only=True, frozen=True) class ModbusSensorDescription(SensorEntityDescription, EntityFactory): """Custom sensor description"""