forked from snaptec/openWB
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* youless * typecast
- Loading branch information
Showing
6 changed files
with
135 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains 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,38 @@ | ||
from typing import Optional | ||
from helpermodules.auto_str import auto_str | ||
from modules.common.component_setup import ComponentSetup | ||
|
||
|
||
@auto_str | ||
class YoulessConfiguration: | ||
def __init__(self, ip_address: Optional[str] = None): | ||
self.ip_address = ip_address | ||
|
||
|
||
@auto_str | ||
class Youless: | ||
def __init__(self, | ||
name: str = "Youless", | ||
type: str = "youless", | ||
id: int = 0, | ||
configuration: YoulessConfiguration = None) -> None: | ||
self.name = name | ||
self.type = type | ||
self.id = id | ||
self.configuration = configuration or YoulessConfiguration() | ||
|
||
|
||
@auto_str | ||
class YoulessInverterConfiguration: | ||
def __init__(self, source_s0: bool = True): | ||
self.source_s0 = source_s0 | ||
|
||
|
||
@auto_str | ||
class YoulessInverterSetup(ComponentSetup[YoulessInverterConfiguration]): | ||
def __init__(self, | ||
name: str = "Youless LS120 Wechselrichter", | ||
type: str = "inverter", | ||
id: int = 0, | ||
configuration: YoulessInverterConfiguration = None) -> None: | ||
super().__init__(name, type, id, configuration or YoulessInverterConfiguration()) |
This file contains 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,65 @@ | ||
#!/usr/bin/env python3 | ||
import logging | ||
from typing import Iterable, Optional, List | ||
|
||
from helpermodules.cli import run_using_positional_cli_args | ||
from modules.common import req | ||
from modules.common.abstract_device import DeviceDescriptor | ||
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, MultiComponentUpdater | ||
from modules.devices.youless import inverter | ||
from modules.devices.youless.config import Youless, YoulessConfiguration, YoulessInverterSetup | ||
from modules.devices.youless.inverter import YoulessInverter | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def create_device(device_config: Youless): | ||
def create_inverter_component(component_config: YoulessInverterSetup): | ||
return YoulessInverter(component_config) | ||
|
||
def update_components(components: Iterable[YoulessInverter]): | ||
response = req.get_http_session().get("http://"+device_config.configuration.ip_address+'/a', | ||
params=(('f', 'j'),), | ||
timeout=5).json() | ||
for component in components: | ||
component.update(response) | ||
|
||
return ConfigurableDevice( | ||
device_config=device_config, | ||
component_factory=ComponentFactoryByType( | ||
inverter=create_inverter_component, | ||
), | ||
component_updater=MultiComponentUpdater(update_components) | ||
) | ||
|
||
|
||
COMPONENT_TYPE_TO_MODULE = { | ||
"inverter": inverter | ||
} | ||
|
||
|
||
def read_legacy(component_type: str, ip_address: str, source_s0: int, num: Optional[int]) -> None: | ||
device_config = Youless(configuration=YoulessConfiguration(ip_address=ip_address)) | ||
dev = create_device(device_config) | ||
if component_type in COMPONENT_TYPE_TO_MODULE: | ||
component_config = COMPONENT_TYPE_TO_MODULE[component_type].component_descriptor.configuration_factory() | ||
else: | ||
raise Exception( | ||
"illegal component type " + component_type + ". Allowed values: " + | ||
','.join(COMPONENT_TYPE_TO_MODULE.keys()) | ||
) | ||
component_config.id = num | ||
component_config.configuration.source_s0 = True if source_s0 == 0 else False | ||
dev.add_component(component_config) | ||
|
||
log.debug('Youless IP-Adresse: ' + ip_address) | ||
log.debug('Youless source_s0: ' + str(source_s0)) | ||
|
||
dev.update() | ||
|
||
|
||
def main(argv: List[str]): | ||
run_using_positional_cli_args(read_legacy, argv) | ||
|
||
|
||
device_descriptor = DeviceDescriptor(configuration_factory=Youless) |
This file contains 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,30 @@ | ||
#!/usr/bin/env python3 | ||
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.youless.config import YoulessInverterSetup | ||
|
||
|
||
class YoulessInverter: | ||
def __init__(self, component_config: YoulessInverterSetup) -> None: | ||
self.component_config = 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) -> None: | ||
if self.component_config.configuration.source_s0: | ||
power = int(response["ps0"]) | ||
exported = int(response["cs0"].replace(",", "")) | ||
else: | ||
power = int(response["pwr"]) | ||
exported = int(response["cnt"].replace(",", "")) | ||
|
||
inverter_state = InverterState( | ||
power=-abs(power), | ||
exported=exported, | ||
) | ||
self.store.set(inverter_state) | ||
|
||
|
||
component_descriptor = ComponentDescriptor(configuration_factory=YoulessInverterSetup) |