Skip to content

Commit e31a916

Browse files
committed
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 home-assistant/core#105211
1 parent 752f31c commit e31a916

9 files changed

+12
-12
lines changed

custom_components/foxess_modbus/entities/modbus_battery_sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .modbus_sensor import ModbusSensorDescription
1717

1818

19-
@dataclass(kw_only=True)
19+
@dataclass(kw_only=True, frozen=True)
2020
class ModbusBatterySensorDescription(ModbusSensorDescription):
2121
"""Description for ModbusBatterySensor"""
2222

custom_components/foxess_modbus/entities/modbus_binary_sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
_LOGGER = logging.getLogger(__name__)
2424

2525

26-
@dataclass(kw_only=True)
26+
@dataclass(kw_only=True, frozen=True)
2727
class ModbusBinarySensorDescription(BinarySensorEntityDescription, EntityFactory):
2828
"""Description for ModbusBinarySensor"""
2929

custom_components/foxess_modbus/entities/modbus_charge_period_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# mypy: disable-error-code="call-arg"
2323

2424

25-
@dataclass
25+
@dataclass(frozen=True)
2626
class ModbusChargePeriodAddressConfig:
2727
"""Defines the set of registers which are used to define a charge period"""
2828

@@ -31,7 +31,7 @@ class ModbusChargePeriodAddressConfig:
3131
enable_charge_from_grid_address: int
3232

3333

34-
@dataclass
34+
@dataclass(frozen=True)
3535
class ModbusChargePeriodInfo:
3636
addresses: ModbusChargePeriodAddressConfig
3737
period_start_entity_id: str
@@ -89,7 +89,7 @@ def get_enable_charge_from_grid_address(self) -> InverterModelSpec:
8989
return ModbusAddressSpecBase(self.models, addresses)
9090

9191

92-
@dataclass
92+
@dataclass(frozen=True)
9393
class ModbusChargePeriodFactory:
9494
"""
9595
Factory which creates various things required to define and specify a charge period

custom_components/foxess_modbus/entities/modbus_charge_period_sensors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _is_force_charge_enabled(
5353
return start_or_end_1 > 0 or start_or_end_2 > 0
5454

5555

56-
@dataclass(kw_only=True)
56+
@dataclass(kw_only=True, frozen=True)
5757
class ModbusChargePeriodStartEndSensorDescription(SensorEntityDescription, EntityFactory):
5858
"""Entity description for ModbusChargePeriodStartEndSensor"""
5959

@@ -179,7 +179,7 @@ def addresses(self) -> list[int]:
179179
return [self._address, self._other_address]
180180

181181

182-
@dataclass(kw_only=True)
182+
@dataclass(kw_only=True, frozen=True)
183183
class ModbusEnableForceChargeSensorDescription(BinarySensorEntityDescription, EntityFactory):
184184
"""Entity description for ModbusEnableForceChargeSensor"""
185185

custom_components/foxess_modbus/entities/modbus_fault_sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
assert any(fault for fault_list in _FAULTS for fault in fault_list if fault == assert_mask)
156156

157157

158-
@dataclass(kw_only=True)
158+
@dataclass(kw_only=True, frozen=True)
159159
class ModbusFaultSensorDescription(SensorEntityDescription, EntityFactory):
160160
"""Description for ModbusFaultSensor"""
161161

custom_components/foxess_modbus/entities/modbus_inverter_state_sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
]
3838

3939

40-
@dataclass(kw_only=True)
40+
@dataclass(kw_only=True, frozen=True)
4141
class ModbusInverterStateSensorDescription(SensorEntityDescription, EntityFactory):
4242
"""Description for ModbusInverterStateSensor"""
4343

custom_components/foxess_modbus/entities/modbus_lambda_sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
_LOGGER = logging.getLogger(__name__)
2424

2525

26-
@dataclass(kw_only=True)
26+
@dataclass(kw_only=True, frozen=True)
2727
class ModbusLambdaSensorDescription(SensorEntityDescription, EntityFactory):
2828
"""Entity description for ModbusLambdaSensors"""
2929

custom_components/foxess_modbus/entities/modbus_number.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
_LOGGER: logging.Logger = logging.getLogger(__package__)
2525

2626

27-
@dataclass(kw_only=True)
27+
@dataclass(kw_only=True, frozen=True)
2828
class ModbusNumberDescription(NumberEntityDescription, EntityFactory):
2929
"""Custom number entity description"""
3030

custom_components/foxess_modbus/entities/modbus_sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
_LOGGER = logging.getLogger(__name__)
2626

2727

28-
@dataclass(kw_only=True)
28+
@dataclass(kw_only=True, frozen=True)
2929
class ModbusSensorDescription(SensorEntityDescription, EntityFactory):
3030
"""Custom sensor description"""
3131

0 commit comments

Comments
 (0)