Skip to content
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

Solarlog #2733

Merged
merged 6 commits into from
Jun 6, 2023
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
2 changes: 1 addition & 1 deletion modules/bezug_solarlog/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fi
openwbDebugLog ${DMOD} 2 "Bezug Solarlog IP: ${bezug_solarlog_ip}"
openwbDebugLog ${DMOD} 2 "Bezug Solarlog Speicher : ${bezug_solarlog_speicherv}"

bash "$OPENWBBASEDIR/packages/legacy_run.sh" "bezug_solarlog.solarlog" "${bezug_solarlog_ip}" "${bezug_solarlog_speicherv}" >>"$MYLOGFILE" 2>&1
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.solar_log.device" "counter" "${bezug_solarlog_ip}" "${bezug_solarlog_speicherv}" >>"$MYLOGFILE" 2>&1
ret=$?

openwbDebugLog ${DMOD} 2 "RET: ${ret}"
Expand Down
60 changes: 0 additions & 60 deletions modules/bezug_solarlog/solarlog.py

This file was deleted.

10 changes: 4 additions & 6 deletions modules/wr_solarlog/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ MYLOGFILE="${RAMDISKDIR}/nurpv.log"
DMOD="PV"
Debug=$debug

bash "$OPENWBBASEDIR/packages/legacy_run.sh" "wr_solarlog.solarlog" "${bezug_solarlog_ip}" >> "${MYLOGFILE}" 2>&1
pvwatt=$(<"${RAMDISKDIR}/pvwatt")
pvkwh=$(<"${RAMDISKDIR}/pvkwh")
bash "$OPENWBBASEDIR/packages/legacy_run.sh" "modules.devices.solar_log.device" "inverter" "${bezug_solarlog_ip}" "0">> "${MYLOGFILE}" 2>&1
ret=$?
openwbDebugLog ${DMOD} 2 "RET: ${ret}"

openwbDebugLog ${DMOD} 2 "pvwatt: $pvwatt"
openwbDebugLog ${DMOD} 2 "pvkwh: $pvkwh"
echo $pvwatt
cat "$RAMDISKDIR/pvwatt"
33 changes: 0 additions & 33 deletions modules/wr_solarlog/solarlog.py

This file was deleted.

Empty file.
48 changes: 48 additions & 0 deletions packages/modules/devices/solar_log/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from typing import Optional

from modules.common.component_setup import ComponentSetup


class SolarLogConfiguration:
def __init__(self, ip_address: Optional[str] = None):
self.ip_address = ip_address


class SolarLog:
def __init__(self,
name: str = "Solar-Log",
type: str = "solar_log",
id: int = 0,
configuration: SolarLogConfiguration = None) -> None:
self.name = name
self.type = type
self.id = id
self.configuration = configuration or SolarLogConfiguration()


class SolarLogCounterConfiguration:
def __init__(self):
pass


class SolarLogCounterSetup(ComponentSetup[SolarLogCounterConfiguration]):
def __init__(self,
name: str = "Solar-Log Zähler",
type: str = "counter",
id: int = 0,
configuration: SolarLogCounterConfiguration = None) -> None:
super().__init__(name, type, id, configuration or SolarLogCounterConfiguration())


class SolarLogInverterConfiguration:
def __init__(self):
pass


class SolarLogInverterSetup(ComponentSetup[SolarLogInverterConfiguration]):
def __init__(self,
name: str = "Solar-Log Wechselrichter",
type: str = "inverter",
id: int = 0,
configuration: SolarLogInverterConfiguration = None) -> None:
super().__init__(name, type, id, configuration or SolarLogInverterConfiguration())
42 changes: 42 additions & 0 deletions packages/modules/devices/solar_log/counter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
import logging
from typing import Dict, Union


from dataclass_utils import dataclass_from_dict
from modules.common.component_state import CounterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo
from modules.common.simcount import SimCounter
from modules.common.store import get_counter_value_store
from modules.devices.solar_log.config import SolarLogCounterSetup

log = logging.getLogger(__name__)


class SolarLogCounter:
def __init__(self,
device_id: int,
component_config: Union[Dict, SolarLogCounterSetup]) -> None:
self.component_config = dataclass_from_dict(SolarLogCounterSetup, component_config)
self.sim_counter = SimCounter(device_id, self.component_config.id, prefix="bezug")
self.store = get_counter_value_store(self.component_config.id)
self.component_info = ComponentInfo.from_component_config(self.component_config)

def update(self, response: Dict) -> None:
self.store_values(self.get_power(response))

def store_values(self, power) -> None:
imported, exported = self.sim_counter.sim_count(power)

self.store.set(CounterState(
imported=imported,
exported=exported,
power=power
))

def get_power(self, response: Dict) -> CounterState:
return int(float(response["801"]["170"]["110"]))


component_descriptor = ComponentDescriptor(configuration_factory=SolarLogCounterSetup)
71 changes: 71 additions & 0 deletions packages/modules/devices/solar_log/device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
import json
import logging
from typing import List, Optional, Union

from helpermodules.cli import run_using_positional_cli_args
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.common import req
from modules.devices.solar_log.counter import SolarLogCounter
from modules.devices.solar_log.config import SolarLog, SolarLogCounterSetup, SolarLogInverterSetup
from modules.devices.solar_log.inverter import SolarLogInverter
log = logging.getLogger(__name__)


def create_device(device_config: SolarLog):
def create_counter_component(component_config: SolarLogCounterSetup):
return SolarLogCounter(device_config.id, component_config)

def create_inverter_component(component_config: SolarLogInverterSetup):
return SolarLogInverter(device_config.id, component_config)

def update_components(components: Union[SolarLogCounter, SolarLogInverter]):
response = req.get_http_session().post('http://'+device_config.ip_adress+'/getjp',
data=json.dumps({"801": {"170": None}}), timeout=5).json()
for component in components:
component.update(response)

return ConfigurableDevice(
device_config=device_config,
component_factory=ComponentFactoryByType(
counter=create_counter_component,
inverter=create_inverter_component,
),
component_updater=MultiComponentUpdater(update_components)
)


def read_legacy(component_type: str, ip_address: str, note_bat: Optional[int] = 0) -> None:
log.debug('Solar-Log ip_address: ' + ip_address)
if component_type == "inverter":
inverter = SolarLogInverter(None, SolarLogInverterSetup(id=1))
with SingleComponentUpdateContext(inverter.component_info):
response = req.get_http_session().post('http://'+ip_address+'/getjp',
data=json.dumps({"801": {"170": None}}), timeout=5).json()
inverter.update(response)
elif component_type == "counter":
inverter = SolarLogInverter(None, SolarLogInverterSetup(id=1))
counter = SolarLogCounter(None, SolarLogCounterSetup(id=None))
with SingleComponentUpdateContext(counter.component_info):
# WR bei WR oder EVU-Modul immer auslesen
response = req.get_http_session().post('http://'+ip_address+'/getjp',
data=json.dumps({"801": {"170": None}}), timeout=5).json()
inverter.update(response)
power = counter.get_power(response)
pvwatt = int(float(response["801"]["170"]["101"]))
power = power - pvwatt

if note_bat == 1:
with open("ramdisk/speicherleistung", "r") as f:
speicherleistung = int(float(f.read()))
power = power + speicherleistung
counter.store_values(power)


def main(argv: List[str]):
run_using_positional_cli_args(read_legacy, argv)


device_descriptor = DeviceDescriptor(configuration_factory=SolarLog)
33 changes: 33 additions & 0 deletions packages/modules/devices/solar_log/inverter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
import logging
from typing import Dict, Union

from dataclass_utils import dataclass_from_dict
from modules.common.component_state import InverterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo
from modules.common.store import get_inverter_value_store
from modules.devices.solar_log.config import SolarLogInverterSetup

log = logging.getLogger(__name__)


class SolarLogInverter:
def __init__(self,
device_id: int,
component_config: Union[Dict, SolarLogInverterSetup]) -> None:
self.component_config = dataclass_from_dict(SolarLogInverterSetup, component_config)
self.store = get_inverter_value_store(self.component_config.id)
self.component_info = ComponentInfo.from_component_config(self.component_config)

def update(self, response: Dict) -> None:
self.store.set(self.get_values(response))

def get_values(self, response: Dict) -> InverterState:
return InverterState(
exported=float(response["801"]["170"]["109"]),
power=-abs(float(response["801"]["170"]["101"]))
)


component_descriptor = ComponentDescriptor(configuration_factory=SolarLogInverterSetup)