Skip to content
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
24 changes: 13 additions & 11 deletions packages/modules/devices/deye/deye/bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,42 @@
class DeyeBat(AbstractBat):
def __init__(self, device_id: int,
component_config: DeyeBatSetup,
device_type: DeviceType) -> None:
client: ModbusTcpClient_) -> None:
self.component_config = dataclass_from_dict(DeyeBatSetup, component_config)
self.store = get_bat_value_store(self.component_config.id)
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))
self.__device_id = device_id
self.client = client
self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="speicher")
self.device_type = device_type
self.device_type = DeviceType(self.client.read_holding_registers(
0, ModbusDataType.INT_16, unit=component_config.configuration.modbus_id))

def update(self, client: ModbusTcpClient_, device_type: DeviceType) -> None:
def update(self) -> None:
unit = self.component_config.configuration.modbus_id

if self.device_type == DeviceType.SINGLE_PHASE_STRING or self.device_type == DeviceType.SINGLE_PHASE_HYBRID:
power = client.read_holding_registers(190, ModbusDataType.INT_16, unit=unit) * -1
soc = client.read_holding_registers(184, ModbusDataType.INT_16, unit=unit)
power = self.client.read_holding_registers(190, ModbusDataType.INT_16, unit=unit) * -1
soc = self.client.read_holding_registers(184, ModbusDataType.INT_16, unit=unit)

if self.device_type == DeviceType.SINGLE_PHASE_HYBRID:
# 516: Geladen in kWh * 0,1
imported = client.read_holding_registers(72, ModbusDataType.UINT_16, unit=unit) * 100
imported = self.client.read_holding_registers(72, ModbusDataType.UINT_16, unit=unit) * 100
# 518: Entladen in kWh * 0,1
exported = client.read_holding_registers(74, ModbusDataType.UINT_16, unit=unit) * 100
exported = self.client.read_holding_registers(74, ModbusDataType.UINT_16, unit=unit) * 100

elif self.device_type == DeviceType.SINGLE_PHASE_STRING:
imported, exported = self.sim_counter.sim_count(power)

else: # THREE_PHASE_LV (0x0500, 0x0005), THREE_PHASE_HV (0x0006)
power = client.read_holding_registers(590, ModbusDataType.INT_16, unit=unit) * -1
power = self.client.read_holding_registers(590, ModbusDataType.INT_16, unit=unit) * -1

if self.device_type == DeviceType.THREE_PHASE_HV:
power = power * 10
soc = client.read_holding_registers(588, ModbusDataType.INT_16, unit=unit)
soc = self.client.read_holding_registers(588, ModbusDataType.INT_16, unit=unit)
# 516: Geladen in kWh * 0,1
imported = client.read_holding_registers(516, ModbusDataType.UINT_16, unit=unit) * 100
imported = self.client.read_holding_registers(516, ModbusDataType.UINT_16, unit=unit) * 100
# 518: Entladen in kWh * 0,1
exported = client.read_holding_registers(518, ModbusDataType.UINT_16, unit=unit) * 100
exported = self.client.read_holding_registers(518, ModbusDataType.UINT_16, unit=unit) * 100

bat_state = BatState(
power=power,
Expand Down
30 changes: 17 additions & 13 deletions packages/modules/devices/deye/deye/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@
class DeyeCounter(AbstractCounter):
def __init__(self, device_id: int,
component_config: DeyeCounterSetup,
device_type: DeviceType) -> None:
client: ModbusTcpClient_) -> None:
self.component_config = dataclass_from_dict(DeyeCounterSetup, component_config)
self.store = get_counter_value_store(self.component_config.id)
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))
self.__device_id = device_id
self.client = client
self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="bezug")
self.device_type = device_type
self.device_type = DeviceType(self.client.read_holding_registers(
0, ModbusDataType.INT_16, unit=component_config.configuration.modbus_id))

def update(self, client: ModbusTcpClient_, device_type: DeviceType):
def update(self):
unit = self.component_config.configuration.modbus_id

if self.device_type == DeviceType.SINGLE_PHASE_STRING or self.device_type == DeviceType.SINGLE_PHASE_HYBRID:
frequency = client.read_holding_registers(79, ModbusDataType.INT_16, unit=unit) / 100
frequency = self.client.read_holding_registers(79, ModbusDataType.INT_16, unit=unit) / 100

if self.device_type == DeviceType.SINGLE_PHASE_HYBRID:
powers = [0]*3
Expand All @@ -37,22 +39,24 @@ def update(self, client: ModbusTcpClient_, device_type: DeviceType):
imported, exported = self.sim_counter.sim_count(power)

elif self.device_type == DeviceType.SINGLE_PHASE_STRING:
currents = [c / 100 for c in client.read_holding_registers(76, [ModbusDataType.INT_16]*3, unit=unit)]
voltages = [v / 10 for v in client.read_holding_registers(70, [ModbusDataType.INT_16]*3, unit=unit)]
currents = [
c / 100 for c in self.client.read_holding_registers(76, [ModbusDataType.INT_16]*3, unit=unit)]
voltages = [
v / 10 for v in self.client.read_holding_registers(70, [ModbusDataType.INT_16]*3, unit=unit)]
powers = [currents[i] * voltages[i] for i in range(0, 3)]
power = sum(powers)
imported, exported = self.sim_counter.sim_count(power)

else: # THREE_PHASE_LV (0x0500, 0x0005), THREE_PHASE_HV (0x0006)
currents = [c / 100 for c in client.read_holding_registers(613, [ModbusDataType.INT_16]*3, unit=unit)]
voltages = [v / 10 for v in client.read_holding_registers(644, [ModbusDataType.INT_16]*3, unit=unit)]
powers = client.read_holding_registers(616, [ModbusDataType.INT_16]*3, unit=unit)
power = client.read_holding_registers(625, ModbusDataType.INT_16, unit=unit)
frequency = client.read_holding_registers(609, ModbusDataType.INT_16, unit=unit) / 100
currents = [c / 100 for c in self.client.read_holding_registers(613, [ModbusDataType.INT_16]*3, unit=unit)]
voltages = [v / 10 for v in self.client.read_holding_registers(644, [ModbusDataType.INT_16]*3, unit=unit)]
powers = self.client.read_holding_registers(616, [ModbusDataType.INT_16]*3, unit=unit)
power = self.client.read_holding_registers(625, ModbusDataType.INT_16, unit=unit)
frequency = self.client.read_holding_registers(609, ModbusDataType.INT_16, unit=unit) / 100

# Wenn der Import/export Netz in wh gerechnet wird => *100 !! kommt in kw/h *0.1
imported = client.read_holding_registers(522, ModbusDataType.INT_16, unit=unit) * 100
exported = client.read_holding_registers(524, ModbusDataType.INT_16, unit=unit) * 100
imported = self.client.read_holding_registers(522, ModbusDataType.INT_16, unit=unit) * 100
exported = self.client.read_holding_registers(524, ModbusDataType.INT_16, unit=unit) * 100

counter_state = CounterState(
currents=currents,
Expand Down
19 changes: 6 additions & 13 deletions packages/modules/devices/deye/deye/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_context import SingleComponentUpdateContext
from modules.common.configurable_device import ConfigurableDevice, ComponentFactoryByType, MultiComponentUpdater
from modules.common.modbus import ModbusDataType, ModbusTcpClient_
from modules.common.modbus import ModbusTcpClient_
from modules.devices.deye.deye.bat import DeyeBat
from modules.devices.deye.deye.counter import DeyeCounter
from modules.devices.deye.deye.device_type import DeviceType
from modules.devices.deye.deye.inverter import DeyeInverter
from modules.devices.deye.deye import bat, counter, inverter
from modules.devices.deye.deye.config import Deye, DeyeBatSetup, DeyeConfiguration, DeyeCounterSetup, DeyeInverterSetup
Expand All @@ -19,25 +18,19 @@

def create_device(device_config: Deye):
def create_bat_component(component_config: DeyeBatSetup):
device_type = client.read_holding_registers(
0, ModbusDataType.INT_16, unit=component_config.configuration.modbus_id)
return DeyeBat(device_config.id, component_config, device_type)
return DeyeBat(device_config.id, component_config, client)

def create_counter_component(component_config: DeyeCounterSetup):
device_type = client.read_holding_registers(
0, ModbusDataType.INT_16, unit=component_config.configuration.modbus_id)
return DeyeCounter(device_config.id, component_config, device_type)
return DeyeCounter(device_config.id, component_config, client)

def create_inverter_component(component_config: DeyeInverterSetup):
device_type = client.read_holding_registers(
0, ModbusDataType.INT_16, unit=component_config.configuration.modbus_id)
return DeyeInverter(device_config.id, component_config, device_type)
return DeyeInverter(device_config.id, component_config, client)

def update_components(components: Iterable[Union[DeyeBat, DeyeCounter, DeyeInverter]]):
with client as c:
with client:
for component in components:
with SingleComponentUpdateContext(component.fault_state):
component.update(c, DeviceType(device_config.configuration.device_type))
component.update()

try:
client = ModbusTcpClient_(device_config.configuration.ip_address, device_config.configuration.port)
Expand Down
14 changes: 8 additions & 6 deletions packages/modules/devices/deye/deye/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,30 @@
class DeyeInverter(AbstractInverter):
def __init__(self, device_id: int,
component_config: Union[Dict, DeyeInverterSetup],
device_type: DeviceType) -> None:
client: ModbusTcpClient_) -> None:
self.component_config = dataclass_from_dict(DeyeInverterSetup, component_config)
self.store = get_inverter_value_store(self.component_config.id)
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))
self.__device_id = device_id
self.client = client
self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="pv")
self.device_type = device_type
self.device_type = DeviceType(self.client.read_holding_registers(
0, ModbusDataType.INT_16, unit=component_config.configuration.modbus_id))

def update(self, client: ModbusTcpClient_, device_type: DeviceType) -> None:
def update(self) -> None:
unit = self.component_config.configuration.modbus_id

if self.device_type == DeviceType.SINGLE_PHASE_STRING or self.device_type == DeviceType.SINGLE_PHASE_HYBRID:
power = sum(client.read_holding_registers(186, [ModbusDataType.INT_16]*4, unit=unit)) * -1
power = sum(self.client.read_holding_registers(186, [ModbusDataType.INT_16]*4, unit=unit)) * -1
exported = self.sim_counter.sim_count(power)[1]

else: # THREE_PHASE_LV (0x0500, 0x0005), THREE_PHASE_HV (0x0006)
power = sum(client.read_holding_registers(672, [ModbusDataType.INT_16]*2, unit=unit)) * -1
power = sum(self.client.read_holding_registers(672, [ModbusDataType.INT_16]*2, unit=unit)) * -1

if self.device_type == DeviceType.THREE_PHASE_HV:
power = power * 10
# 534: Gesamt Produktion Wechselrichter unsigned integer in kWh * 0,1
exported = client.read_holding_registers(534, ModbusDataType.UINT_16, unit=unit) * 100
exported = self.client.read_holding_registers(534, ModbusDataType.UINT_16, unit=unit) * 100

inverter_state = InverterState(
power=power,
Expand Down