-
Notifications
You must be signed in to change notification settings - Fork 121
feat: add SunEnergyXT 500 Series battery storage module #3387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ChristophCaina
wants to merge
6
commits into
openWB:master
Choose a base branch
from
ChristophCaina:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+365
−0
Draft
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8a8ff60
feat: add SunEnergyXT 500 Series battery storage module
7288783
Delete packages/modules/devices/sunenergyxt/sunenergyxt/device.vue
ChristophCaina 6f78f04
Refactor SunEnergyXTConfiguration constructor parameters
ChristophCaina efb4c74
Refactor HTTP requests to use common module
ChristophCaina 05f4a5e
Remove unused logging import in device.py
ChristophCaina e80f520
Add files via upload
ChristophCaina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #!/usr/bin/env python3 | ||
| """SunEnergyXT 500 Series – openWB Batteriespeicher-Modul.""" | ||
| import logging | ||
| from typing import Any, Optional | ||
| import requests | ||
| from modules.common.abstract_device import AbstractBat | ||
| from modules.common.component_state import BatState | ||
| from modules.common.component_type import ComponentDescriptor | ||
| from modules.common.fault_state import ComponentInfo, FaultState | ||
| from modules.common.simcount import SimCounter | ||
| from modules.common.store import get_bat_value_store | ||
| from modules.devices.sunenergyxt.sunenergyxt.config import SunEnergyXT, SunEnergyXTBatSetup | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class SunEnergyXTBat(AbstractBat): | ||
| def __init__(self, component_config: SunEnergyXTBatSetup, **kwargs: Any) -> None: | ||
| self.component_config = component_config | ||
| self.kwargs = kwargs | ||
|
|
||
| def initialize(self) -> None: | ||
| self.device_config: SunEnergyXT = self.kwargs['device_config'] | ||
| self.sim_counter = SimCounter(self.device_config.id, self.component_config.id, prefix="speicher") | ||
| self.store = get_bat_value_store(self.component_config.id) | ||
| self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) | ||
| self._base_url = ( | ||
| f"http://{self.device_config.configuration.ip_address}" | ||
| f":{self.device_config.configuration.port}" | ||
| ) | ||
| self._timeout = self.device_config.configuration.timeout | ||
|
|
||
| def _read(self) -> dict: | ||
| url = f"{self._base_url}/read" | ||
| resp = requests.get(url, timeout=self._timeout) | ||
| resp.raise_for_status() | ||
| return resp.json() | ||
|
|
||
| def _write(self, **kwargs) -> None: | ||
| url = f"{self._base_url}/write" | ||
| payload = {"state": kwargs} | ||
| resp = requests.post(url, json=payload, timeout=self._timeout) | ||
| resp.raise_for_status() | ||
| log.debug("SunEnergyXT write %s → %s", kwargs, resp.text) | ||
|
ChristophCaina marked this conversation as resolved.
|
||
|
|
||
| def update(self) -> None: | ||
| data = self._read() | ||
| reported = data.get("state", {}).get("reported", data) | ||
|
|
||
| soc = int(float(reported.get("SC", 0))) | ||
|
ChristophCaina marked this conversation as resolved.
|
||
| power = float(reported.get("PB", 0)) | ||
| max_power = float(reported.get("IS", 0)) | ||
|
|
||
| imported, exported = self.sim_counter.sim_count(power) | ||
|
|
||
| bat_state = BatState( | ||
| power=power, | ||
| soc=soc, | ||
| imported=imported, | ||
| exported=exported, | ||
| ) | ||
| bat_state.max_charge_power = max_power | ||
| bat_state.max_discharge_power = max_power | ||
| self.store.set(bat_state) | ||
|
ChristophCaina marked this conversation as resolved.
|
||
| log.debug("SunEnergyXT: SoC=%d%%, PB=%.0fW, IS=%.0fW", soc, power, max_power) | ||
|
|
||
| def set_power_limit(self, power_limit: Optional[int]) -> None: | ||
| if power_limit is None: | ||
| log.debug("SunEnergyXT: Automatik (MM=1, GS=0)") | ||
| self._write(MM=1, GS=0) | ||
| elif power_limit == 0: | ||
| log.debug("SunEnergyXT: Entladung gesperrt (MM=0, GS=0)") | ||
| self._write(MM=0, GS=0) | ||
| elif power_limit > 0: | ||
| p = int(min(power_limit, 9999)) | ||
| log.debug("SunEnergyXT: Entladen mit %dW", p) | ||
| self._write(MM=0, GS=p) | ||
| else: | ||
| p = int(min(abs(power_limit), 9999)) | ||
| log.debug("SunEnergyXT: Laden mit %dW", p) | ||
| self._write(MM=0, GS=-p) | ||
|
ChristophCaina marked this conversation as resolved.
|
||
|
|
||
| def power_limit_controllable(self) -> bool: | ||
| return True | ||
|
|
||
|
|
||
| component_descriptor = ComponentDescriptor(configuration_factory=SunEnergyXTBatSetup) | ||
40 changes: 40 additions & 0 deletions
40
packages/modules/devices/sunenergyxt/sunenergyxt/config.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| from typing import Optional | ||
| from modules.common.component_setup import ComponentSetup | ||
| from ..vendor import vendor_descriptor | ||
|
|
||
|
|
||
| class SunEnergyXTConfiguration: | ||
| def __init__(self, | ||
| ip_address: Optional[str] = "192.168.1.100", | ||
| port: int = 80, | ||
| timeout: int = 5): | ||
|
ChristophCaina marked this conversation as resolved.
Outdated
|
||
| self.ip_address = ip_address | ||
| self.port = port | ||
| self.timeout = timeout | ||
|
|
||
|
|
||
| class SunEnergyXT: | ||
| def __init__(self, | ||
| name: str = "SunEnergyXT 500 Series", | ||
| type: str = "sunenergyxt", | ||
| id: int = 0, | ||
| configuration: SunEnergyXTConfiguration = None) -> None: | ||
| self.name = name | ||
| self.type = type | ||
| self.vendor = vendor_descriptor.configuration_factory().type | ||
| self.id = id | ||
| self.configuration = configuration or SunEnergyXTConfiguration() | ||
|
|
||
|
|
||
| class SunEnergyXTBatConfiguration: | ||
| def __init__(self): | ||
| pass | ||
|
|
||
|
|
||
| class SunEnergyXTBatSetup(ComponentSetup[SunEnergyXTBatConfiguration]): | ||
| def __init__(self, | ||
| name: str = "SunEnergyXT Speicher", | ||
| type: str = "bat", | ||
| id: int = 0, | ||
| configuration: SunEnergyXTBatConfiguration = None) -> None: | ||
| super().__init__(name, type, id, configuration or SunEnergyXTBatConfiguration()) | ||
31 changes: 31 additions & 0 deletions
31
packages/modules/devices/sunenergyxt/sunenergyxt/device.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #!/usr/bin/env python3 | ||
| import logging | ||
| from typing import Iterable | ||
| from modules.common.abstract_device import DeviceDescriptor | ||
| from modules.common.component_context import SingleComponentUpdateContext | ||
| from modules.common.configurable_device import ComponentFactoryByType, ConfigurableDevice, MultiComponentUpdater | ||
| from modules.devices.sunenergyxt.sunenergyxt.bat import SunEnergyXTBat | ||
| from modules.devices.sunenergyxt.sunenergyxt.config import SunEnergyXT, SunEnergyXTBatSetup | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
ChristophCaina marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| def create_device(device_config: SunEnergyXT): | ||
| def create_bat_component(component_config: SunEnergyXTBatSetup): | ||
| return SunEnergyXTBat(component_config, device_config=device_config) | ||
|
|
||
| def update_components(components: Iterable[SunEnergyXTBat]): | ||
| for component in components: | ||
| with SingleComponentUpdateContext(component.fault_state): | ||
| component.update() | ||
|
|
||
| return ConfigurableDevice( | ||
| device_config=device_config, | ||
| component_factory=ComponentFactoryByType( | ||
| bat=create_bat_component, | ||
| ), | ||
|
ChristophCaina marked this conversation as resolved.
|
||
| component_updater=MultiComponentUpdater(update_components) | ||
| ) | ||
|
|
||
|
|
||
| device_descriptor = DeviceDescriptor(configuration_factory=SunEnergyXT) | ||
56 changes: 56 additions & 0 deletions
56
packages/modules/devices/sunenergyxt/sunenergyxt/device.vue
|
ChristophCaina marked this conversation as resolved.
Outdated
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <template> | ||
| <div class="device-sunenergyxt"> | ||
| <openwb-base-heading> | ||
| Einstellungen für SunEnergyXT 500 Series | ||
| </openwb-base-heading> | ||
| <openwb-base-text-input | ||
| title="IP-Adresse oder Hostname" | ||
| subtype="host" | ||
| required | ||
| :model-value="device.configuration.ip_address" | ||
| @update:model-value=" | ||
| updateConfiguration($event, 'configuration.ip_address') | ||
| " | ||
| > | ||
| <template #help> | ||
| IP-Adresse des SunEnergyXT-Geräts im lokalen Netzwerk | ||
| </template> | ||
| </openwb-base-text-input> | ||
| <openwb-base-number-input | ||
| title="Port" | ||
| :min="1" | ||
| :max="65535" | ||
| required | ||
| :model-value="device.configuration.port" | ||
| @update:model-value=" | ||
| updateConfiguration($event, 'configuration.port') | ||
| " | ||
| > | ||
| <template #help> | ||
| HTTP-Port des Geräts (Standard: 80) | ||
| </template> | ||
| </openwb-base-number-input> | ||
| <openwb-base-number-input | ||
| title="Timeout" | ||
| :min="1" | ||
| :max="30" | ||
| required | ||
| :model-value="device.configuration.timeout" | ||
| @update:model-value=" | ||
| updateConfiguration($event, 'configuration.timeout') | ||
| " | ||
| > | ||
| <template #help> | ||
| HTTP-Timeout in Sekunden (Standard: 5) | ||
| </template> | ||
| </openwb-base-number-input> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script> | ||
| import DeviceConfigMixin from "../../DeviceConfigMixin.vue"; | ||
| export default { | ||
| name: "DeviceSunEnergyXT", | ||
| mixins: [DeviceConfigMixin], | ||
| }; | ||
|
ChristophCaina marked this conversation as resolved.
Outdated
|
||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from pathlib import Path | ||
| from modules.common.abstract_device import DeviceDescriptor | ||
| from modules.devices.vendors import VendorGroup | ||
|
|
||
| class Vendor: | ||
| def __init__(self): | ||
| self.type = Path(__file__).parent.name | ||
| self.vendor = "SunEnergyXT" | ||
| self.group = VendorGroup.VENDORS.value | ||
|
|
||
| vendor_descriptor = DeviceDescriptor(configuration_factory=Vendor) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.