Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions custom_components/growatt_server/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,30 @@

from .const import DOMAIN
from .coordinator import GrowattConfigEntry, GrowattCoordinator
from .growattServer.open_api_v1 import DeviceFieldTemplates

_LOGGER = logging.getLogger(__name__)

# Field name templates for different device types
# MIN/TLX devices use numbered time segment fields
MIN_TLX_FIELD_TEMPLATES = {
"start_time": "timeSegmentStart{segment_id}",
"stop_time": "timeSegmentStop{segment_id}",
"enabled": "timeSegmentEnabled{segment_id}",
}

# MIX/SPH devices use different field names for charge and discharge
SPH_MIX_CHARGE_FIELD_TEMPLATES = {
"start_time": "forcedChargeTimeStart{segment_id}",
"stop_time": "forcedChargeTimeStop{segment_id}",
"enabled": "forcedChargeStopSwitch{segment_id}",
}

SPH_MIX_DISCHARGE_FIELD_TEMPLATES = {
"start_time": "forcedDischargeTimeStart{segment_id}",
"stop_time": "forcedDischargeTimeStop{segment_id}",
"enabled": "forcedDischargeStopSwitch{segment_id}",
}


class GrowattChargeStartTimeEntity(CoordinatorEntity[GrowattCoordinator], TimeEntity):
"""Representation of charge start time."""
Expand All @@ -42,9 +62,9 @@ def __init__(self, coordinator: GrowattCoordinator, segment_id: int = 1) -> None
def _get_field_name(self, field_type: str) -> str:
"""Get the appropriate field name based on device type."""
if self.coordinator.device_type == "tlx":
template = DeviceFieldTemplates.MIN_TLX_TEMPLATES[field_type]
template = MIN_TLX_FIELD_TEMPLATES[field_type]
else: # mix
template = DeviceFieldTemplates.SPH_MIX_TEMPLATES_CHARGE[field_type]
template = SPH_MIX_CHARGE_FIELD_TEMPLATES[field_type]
return template.format(segment_id=self._segment_id)

@property
Expand Down Expand Up @@ -109,9 +129,9 @@ def __init__(self, coordinator: GrowattCoordinator, segment_id: int = 1) -> None
def _get_field_name(self, field_type: str) -> str:
"""Get the appropriate field name based on device type."""
if self.coordinator.device_type == "tlx":
template = DeviceFieldTemplates.MIN_TLX_TEMPLATES[field_type]
template = MIN_TLX_FIELD_TEMPLATES[field_type]
else: # mix
template = DeviceFieldTemplates.SPH_MIX_TEMPLATES_CHARGE[field_type]
template = SPH_MIX_CHARGE_FIELD_TEMPLATES[field_type]
return template.format(segment_id=self._segment_id)

@property
Expand Down Expand Up @@ -179,9 +199,9 @@ def __init__(self, coordinator: GrowattCoordinator, segment_id: int = 1) -> None
def _get_field_name(self, field_type: str) -> str:
"""Get the appropriate field name based on device type."""
if self.coordinator.device_type == "tlx":
template = DeviceFieldTemplates.MIN_TLX_TEMPLATES[field_type]
template = MIN_TLX_FIELD_TEMPLATES[field_type]
else: # mix
template = DeviceFieldTemplates.SPH_MIX_TEMPLATES_DIS_CHARGE[field_type]
template = SPH_MIX_DISCHARGE_FIELD_TEMPLATES[field_type]
return template.format(segment_id=self._segment_id)

@property
Expand Down Expand Up @@ -256,9 +276,9 @@ def __init__(self, coordinator: GrowattCoordinator, segment_id: int = 1) -> None
def _get_field_name(self, field_type: str) -> str:
"""Get the appropriate field name based on device type."""
if self.coordinator.device_type == "tlx":
template = DeviceFieldTemplates.MIN_TLX_TEMPLATES[field_type]
template = MIN_TLX_FIELD_TEMPLATES[field_type]
else: # mix
template = DeviceFieldTemplates.SPH_MIX_TEMPLATES_DIS_CHARGE[field_type]
template = SPH_MIX_DISCHARGE_FIELD_TEMPLATES[field_type]
return template.format(segment_id=self._segment_id)

@property
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
colorlog==6.9.0
homeassistant==2025.9.0
pip>=21.3.1
ruff==0.13.2
growattServer @ git+https://github.com/GraemeDBlue/PyPi_GrowattServer.git@write_values
ruff==0.13.2