From 6c9540911b96e287fc8c2f5bf3677ac7d617120b Mon Sep 17 00:00:00 2001 From: Graeme Dewe Date: Mon, 10 Nov 2025 09:46:43 +0000 Subject: [PATCH] fix import --- custom_components/growatt_server/time.py | 38 ++++++++++++++++++------ requirements.txt | 3 +- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/custom_components/growatt_server/time.py b/custom_components/growatt_server/time.py index 420f6ff..ffb9a2c 100644 --- a/custom_components/growatt_server/time.py +++ b/custom_components/growatt_server/time.py @@ -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.""" @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/requirements.txt b/requirements.txt index 2cff901..778f265 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file +ruff==0.13.2 \ No newline at end of file