Skip to content

Commit

Permalink
Make dataclasses frozen
Browse files Browse the repository at this point in the history
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
  • Loading branch information
canton7 committed Dec 23, 2023
1 parent 752f31c commit 9076a5f
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down Expand Up @@ -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"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
]


@dataclass(kw_only=True)
@dataclass(kw_only=True, frozen=True)
class ModbusInverterStateSensorDescription(SensorEntityDescription, EntityFactory):
"""Description for ModbusInverterStateSensor"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down
2 changes: 1 addition & 1 deletion custom_components/foxess_modbus/entities/modbus_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down
2 changes: 1 addition & 1 deletion custom_components/foxess_modbus/entities/modbus_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down
2 changes: 1 addition & 1 deletion custom_components/foxess_modbus/flow/inverter_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ..inverter_adapters import InverterAdapterType


@dataclass
@dataclass(frozen=True)
class InverterData:
"""Holds data gathered on an inverter as the user went through the flow"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async def _update_all_charge_periods_callback(service_data: ServiceCall) -> None
)


@dataclass
@dataclass(frozen=True)
class ChargePeriod:
"""Holds the data for a single charge period"""

Expand Down

0 comments on commit 9076a5f

Please sign in to comment.