Skip to content
Closed
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
21 changes: 21 additions & 0 deletions packages/modules/devices/fronius/fronius/API_LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Stephan Mükusch

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
48 changes: 47 additions & 1 deletion packages/modules/devices/fronius/fronius/bat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
from typing import Any, TypedDict
from typing import Any, TypedDict, Optional
import logging

from modules.common import req
from modules.common.abstract_device import AbstractBat
Expand All @@ -12,6 +13,9 @@
from modules.devices.fronius.fronius.config import FroniusConfiguration
from modules.common.utils.peak_filter import PeakFilter
from modules.common.component_type import ComponentType
from modules.devices.fronius.fronius.fronius_api import FroniusWR

log = logging.getLogger(__name__)


class KwargsDict(TypedDict):
Expand All @@ -31,6 +35,8 @@ def initialize(self) -> None:
self.store = get_component_value_store(self.component_config.type, self.component_config.id)
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))
self.peak_filter = PeakFilter(ComponentType.BAT, self.component_config.id, self.fault_state)
self.last_mode = 'Undefined'
self.bat_api = None

def update(self) -> None:
meter_id = str(self.component_config.configuration.meter_id)
Expand Down Expand Up @@ -65,5 +71,45 @@ def update(self) -> None:
)
self.store.set(bat_state)

def set_power_limit(self, power_limit: Optional[int]) -> None:
username = self.component_config.configuration.username
password = self.component_config.configuration.password
if self.bat_api is None:
config = {
'address': self.device_config.ip_address,
'user': username,
'password': password
}
self.bat_api = FroniusWR(config)
if username is not None and password is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diese Bedingung sollte eigentlich immer der Fall sein, oder? oben werden ja Standard-Werte gesetzt.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nein, username und password sind in der Konfiguration als Optional definiert und werden mit None initialisiert.

self.bat_api.set_config(self.device_config.ip_address, username, password)

log.debug(f'last_mode: {self.last_mode}')

if power_limit is None:
log.debug("Keine Batteriesteuerung, Selbstregelung durch Wechselrichter")
if self.last_mode is not None:
self.bat_api.set_mode_self_regulation()
self.last_mode = None
elif power_limit == 0:
log.debug("Aktive Batteriesteuerung. Batterie wird auf Stop gesetzt und nicht entladen")
if self.last_mode != 'stop':
self.bat_api.set_mode_avoid_discharge()
self.last_mode = 'stop'
elif power_limit < 0:
self.bat_api.set_mode_force_discharge(abs(power_limit))
log.debug(f"Aktive Batteriesteuerung. Batterie wird mit {abs(power_limit)} W "
"entladen für den Hausverbrauch")
self.last_mode = 'discharge'
elif power_limit > 0:
self.bat_api.set_mode_force_charge(power_limit)
log.debug(f"Aktive Batteriesteuerung. Batterie wird mit {power_limit} W geladen")
self.last_mode = 'charge'
else:
log.warning("Fronius Speicher: Keine Batteriesteuerung möglich, da keine Zugangsdaten hinterlegt sind.")

def power_limit_controllable(self) -> bool:
return True


component_descriptor = ComponentDescriptor(configuration_factory=FroniusBatSetup)
7 changes: 6 additions & 1 deletion packages/modules/devices/fronius/fronius/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ def __init__(self,


class FroniusBatConfiguration:
def __init__(self, meter_id: int = 0):
def __init__(self,
meter_id: int = 0,
username: Optional[str] = None,
password: Optional[str] = None):
self.meter_id = meter_id
self.username = username
self.password = password


class FroniusBatSetup(ComponentSetup[FroniusBatConfiguration]):
Expand Down
Loading