Skip to content

Commit 22297d8

Browse files
committed
improve chint and azzuro zcs
1 parent 5afe116 commit 22297d8

10 files changed

Lines changed: 84 additions & 134 deletions

File tree

packages/modules/devices/zcs/zcs/__init__.py renamed to packages/modules/devices/azzurro_zcs/azzurro_zcs_3p/__init__.py

File renamed without changes.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from typing import Optional
2+
3+
from modules.common.component_setup import ComponentSetup
4+
from ..vendor import vendor_descriptor
5+
6+
7+
class ZCS3PConfiguration:
8+
def __init__(self, modbus_id: int = 1, ip_address: Optional[str] = None, port: int = 502):
9+
self.modbus_id = modbus_id
10+
self.ip_address = ip_address
11+
self.port = port
12+
13+
14+
class ZCS3P:
15+
def __init__(self,
16+
name: str = "Azzurro - ZCS 3PH 12KTL",
17+
type: str = "azzurro_zcs_3p",
18+
id: int = 0,
19+
configuration: ZCS3PConfiguration = None) -> None:
20+
self.name = name
21+
self.type = type
22+
self.vendor = vendor_descriptor.configuration_factory().type
23+
self.id = id
24+
self.configuration = configuration or ZCS3PConfiguration()
25+
26+
27+
class ZCSPvInverterConfiguration:
28+
def __init__(self):
29+
pass
30+
31+
32+
class ZCSPvInverterSetup(ComponentSetup[ZCSPvInverterConfiguration]):
33+
def __init__(self,
34+
name: str = "ZCS Azzurro Wechselrichter",
35+
type: str = "pv_inverter",
36+
id: int = 0,
37+
configuration: ZCSPvInverterConfiguration = None) -> None:
38+
super().__init__(name, type, id, configuration or ZCSPvInverterConfiguration())
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
#!/usr/bin/env python3
22
import logging
3-
from typing import Iterable, Union
3+
from typing import Iterable
44

55
from modules.common.abstract_device import DeviceDescriptor
66
from modules.common.component_context import SingleComponentUpdateContext
77
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, MultiComponentUpdater
88
from modules.common.modbus import ModbusTcpClient_
9-
from modules.devices.zcs.zcs.config import ZCS, ZCSInverterSetup
10-
from modules.devices.zcs.zcs.inverter import ZCSInverter
9+
from modules.devices.azzurro_zcs.azzurro_zcs_3p.config import ZCS3P, ZCSPvInverterSetup
10+
from modules.devices.azzurro_zcs.azzurro_zcs_3p.pv_inverter import ZCSPvInverter
1111

1212
log = logging.getLogger(__name__)
1313

1414

15-
def create_device(device_config: ZCS):
15+
def create_device(device_config: ZCS3P):
1616
client = None
1717

18-
def create_inverter_component(component_config: ZCSInverterSetup):
18+
def create_pv_inverter_component(component_config: ZCSPvInverterSetup):
1919
nonlocal client
20-
return ZCSInverter(component_config, device_id=device_config.id, client=client)
20+
return ZCSPvInverter(component_config=component_config,
21+
modbus_id=device_config.configuration.modbus_id,
22+
client=client)
2123

22-
def update_components(components: Iterable[Union[ZCSInverter]]):
24+
def update_components(components: Iterable[ZCSPvInverter]):
25+
nonlocal client
2326
with client:
2427
for component in components:
2528
with SingleComponentUpdateContext(component.fault_state):
@@ -33,10 +36,10 @@ def initializer():
3336
device_config=device_config,
3437
initializer=initializer,
3538
component_factory=ComponentFactoryByType(
36-
inverter=create_inverter_component,
39+
pv_inverter=create_pv_inverter_component,
3740
),
3841
component_updater=MultiComponentUpdater(update_components)
3942
)
4043

4144

42-
device_descriptor = DeviceDescriptor(configuration_factory=ZCS)
45+
device_descriptor = DeviceDescriptor(configuration_factory=ZCS3P)

packages/modules/devices/zcs/zcs/inverter.py renamed to packages/modules/devices/azzurro_zcs/azzurro_zcs_3p/pv_inverter.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,25 @@
66
from modules.common.component_type import ComponentDescriptor
77
from modules.common.fault_state import ComponentInfo, FaultState
88
from modules.common.modbus import ModbusDataType, ModbusTcpClient_
9-
from modules.common.simcount import SimCounter
109
from modules.common.store import get_inverter_value_store
11-
from modules.devices.zcs.zcs.config import ZCSInverterSetup
10+
from modules.devices.azzurro_zcs.azzurro_zcs_3p.config import ZCSPvInverterSetup
1211

1312
log = logging.getLogger(__name__)
1413

1514

1615
class KwargsDict(TypedDict):
17-
device_id: int
1816
client: ModbusTcpClient_
17+
modbus_id: int
1918

2019

21-
class ZCSInverter(AbstractInverter):
22-
def __init__(self, component_config: ZCSInverterSetup, **kwargs: Any) -> None:
20+
class ZCSPvInverter(AbstractInverter):
21+
def __init__(self, component_config: ZCSPvInverterSetup, **kwargs: Any) -> None:
2322
self.component_config = component_config
2423
self.kwargs: KwargsDict = kwargs
25-
self.__modbus_id = component_config.configuration.modbus_id
2624

2725
def initialize(self) -> None:
28-
self.__device_id: int = self.kwargs['device_id']
26+
self.__modbus_id: int = self.kwargs['modbus_id']
2927
self.client: ModbusTcpClient_ = self.kwargs['client']
30-
self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="pv")
3128
self.store = get_inverter_value_store(self.component_config.id)
3229
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))
3330

@@ -44,14 +41,13 @@ def update(self) -> None:
4441
]
4542
except Exception:
4643
log.debug("Modbus could not be read.")
47-
44+
4845
inverter_state = InverterState(
4946
currents=currents,
5047
power=power,
5148
exported=exported
52-
# dc_power=dc_power
5349
)
5450
self.store.set(inverter_state)
5551

5652

57-
component_descriptor = ComponentDescriptor(configuration_factory=ZCSInverterSetup)
53+
component_descriptor = ComponentDescriptor(configuration_factory=ZCSPvInverterSetup)

packages/modules/devices/chint/chint/config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ def __init__(self,
2828

2929
@auto_str
3030
class CHINTCounterConfiguration:
31-
def __init__(self, modbus_id: int = 1, invert: bool = False):
31+
def __init__(self, modbus_id: int = 1):
3232
self.modbus_id = modbus_id
33-
self.invert = invert
3433

3534

3635
@auto_str

packages/modules/devices/chint/chint/counter.py

Lines changed: 24 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,76 +13,47 @@
1313

1414

1515
class KwargsDict(TypedDict):
16-
device_id: int
1716
client: ModbusTcpClient_
1817

1918

2019
class CHINTCounter(AbstractCounter):
2120
def __init__(self, component_config: CHINTCounterSetup, **kwargs: Any) -> None:
2221
self.component_config = component_config
2322
self.kwargs: KwargsDict = kwargs
24-
self.__modbus_id = component_config.configuration.modbus_id
25-
self.invert = component_config.configuration.invert
2623

2724
def initialize(self) -> None:
28-
self.__device_id: int = self.kwargs['device_id']
2925
self.client: ModbusTcpClient_ = self.kwargs['client']
3026
self.store = get_counter_value_store(self.component_config.id)
3127
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))
28+
self.__modbus_id = self.component_config.configuration.modbus_id
3229

3330
def update(self):
3431
powers = voltages = currents = power_factors = None
3532
imported_ep = exported_ep = power = frequency = 0
36-
try:
37-
irat = self.client.read_holding_registers(0x0006, ModbusDataType.INT_16, unit=self.__modbus_id)
38-
urat = self.client.read_holding_registers(0x0007, ModbusDataType.INT_16, unit=self.__modbus_id)
39-
power_ratio = urat*0.1*irat*0.1
40-
if self.invert:
41-
power_ratio = power_ratio * -1
42-
frequency = self.client.read_holding_registers(0x2044, ModbusDataType.FLOAT_32, unit=self.__modbus_id)/100
43-
power = self.client.read_holding_registers(0x2012,
44-
ModbusDataType.FLOAT_32, unit=self.__modbus_id) * power_ratio
45-
powers = [
46-
self.client.read_holding_registers(0x2014,
47-
ModbusDataType.FLOAT_32, unit=self.__modbus_id) * power_ratio,
48-
self.client.read_holding_registers(0x2016,
49-
ModbusDataType.FLOAT_32, unit=self.__modbus_id) * power_ratio,
50-
self.client.read_holding_registers(0x2018,
33+
irat = self.client.read_holding_registers(0x0006, ModbusDataType.INT_16, unit=self.__modbus_id)
34+
urat = self.client.read_holding_registers(0x0007, ModbusDataType.INT_16, unit=self.__modbus_id)
35+
power_ratio = urat*0.1*irat*0.1
36+
37+
frequency = self.client.read_holding_registers(0x2044, ModbusDataType.FLOAT_32, unit=self.__modbus_id)/100
38+
power = self.client.read_holding_registers(0x2012,
5139
ModbusDataType.FLOAT_32, unit=self.__modbus_id) * power_ratio
52-
]
53-
voltage_ratio = urat*0.1*0.1
54-
voltages = [
55-
self.client.read_holding_registers(0x2006,
56-
ModbusDataType.FLOAT_32, unit=self.__modbus_id) * voltage_ratio,
57-
self.client.read_holding_registers(0x2008,
58-
ModbusDataType.FLOAT_32, unit=self.__modbus_id) * voltage_ratio,
59-
self.client.read_holding_registers(0x200A,
60-
ModbusDataType.FLOAT_32, unit=self.__modbus_id) * voltage_ratio
61-
]
62-
current_ratio = irat*0.001
63-
currents = [
64-
self.client.read_holding_registers(0x200C,
65-
ModbusDataType.FLOAT_32, unit=self.__modbus_id) * current_ratio,
66-
self.client.read_holding_registers(0x200E,
67-
ModbusDataType.FLOAT_32, unit=self.__modbus_id) * current_ratio,
68-
self.client.read_holding_registers(0x2010,
69-
ModbusDataType.FLOAT_32, unit=self.__modbus_id) * current_ratio
70-
]
71-
power_factors = [
72-
self.client.read_holding_registers(0x202C, ModbusDataType.FLOAT_32, unit=self.__modbus_id) * 0.001,
73-
self.client.read_holding_registers(0x202E, ModbusDataType.FLOAT_32, unit=self.__modbus_id) * 0.001,
74-
self.client.read_holding_registers(0x2030, ModbusDataType.FLOAT_32, unit=self.__modbus_id) * 0.001
75-
]
76-
ep_ratio = irat * urat * 100
77-
imported_ep = self.client.read_holding_registers(0x401E,
78-
ModbusDataType.FLOAT_32, unit=self.__modbus_id) * ep_ratio
79-
exported_ep = self.client.read_holding_registers(0x4028,
80-
ModbusDataType.FLOAT_32, unit=self.__modbus_id) * ep_ratio
81-
if self.invert:
82-
imported_ep, exported_ep = exported_ep, imported_ep
83-
84-
except Exception:
85-
log.debug("Modbus could not be read.")
40+
powers = [self.client.read_holding_registers(reg, ModbusDataType.FLOAT_32, unit=self.__modbus_id) * power_ratio
41+
for reg in [0x2014, 0x2016, 0x2018]]
42+
voltage_ratio = urat*0.1*0.1
43+
voltages = [self.client.read_holding_registers(
44+
reg, ModbusDataType.FLOAT_32, unit=self.__modbus_id) * voltage_ratio
45+
for reg in [0x2006, 0x2008, 0x200A]]
46+
current_ratio = irat*0.001
47+
currents = [self.client.read_holding_registers(
48+
reg, ModbusDataType.FLOAT_32, unit=self.__modbus_id) * current_ratio
49+
for reg in [0x200C, 0x200E, 0x2010]]
50+
power_factors = [self.client.read_holding_registers(reg, ModbusDataType.FLOAT_32, unit=self.__modbus_id) * 0.001
51+
for reg in [0x202C, 0x202E, 0x2030]]
52+
ep_ratio = irat * urat * 100
53+
imported_ep = self.client.read_holding_registers(0x401E,
54+
ModbusDataType.FLOAT_32, unit=self.__modbus_id) * ep_ratio
55+
exported_ep = self.client.read_holding_registers(0x4028,
56+
ModbusDataType.FLOAT_32, unit=self.__modbus_id) * ep_ratio
8657

8758
counter_state = CounterState(
8859
currents=currents,

packages/modules/devices/chint/chint/device.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ def create_device(device_config: CHINT):
1717

1818
def create_counter_component(component_config: CHINTCounterSetup):
1919
nonlocal client
20-
return CHINTCounter(component_config=component_config,
21-
device_id=device_config.id, client=client)
20+
return CHINTCounter(component_config=component_config, client=client)
2221

2322
def update_components(components: Iterable[Union[CHINTCounter]]):
2423
with client:
@@ -40,4 +39,4 @@ def initializer():
4039
)
4140

4241

43-
device_descriptor = DeviceDescriptor(configuration_factory=CHINT)
42+
device_descriptor = DeviceDescriptor(configuration_factory=CHINT)

packages/modules/devices/zcs/__init__ .py

Whitespace-only changes.

packages/modules/devices/zcs/vendor.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/modules/devices/zcs/zcs/config.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)