Skip to content

Commit

Permalink
Abstract components (#1865)
Browse files Browse the repository at this point in the history
* interface for counter  & inverter component

* add new modules solis and sigenergy
  • Loading branch information
LKuemmel authored Oct 10, 2024
1 parent 021867b commit 8b468e2
Show file tree
Hide file tree
Showing 108 changed files with 234 additions and 107 deletions.
20 changes: 20 additions & 0 deletions packages/modules/common/abstract_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ def set_power_limit(self, power_limit: Optional[int]) -> None:
pass


class AbstractCounter:
@abstractmethod
def __init__(self, *kwargs) -> None:
pass

@abstractmethod
def update(self, *kwargs) -> None:
pass


class AbstractInverter:
@abstractmethod
def __init__(self, *kwargs) -> None:
pass

@abstractmethod
def update(self, *kwargs) -> None:
pass


class DeviceDescriptor:
def __init__(self, configuration_factory: Type):
self.configuration_factory = configuration_factory
3 changes: 2 additions & 1 deletion packages/modules/devices/alpha_ess/alpha_ess/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
from dataclass_utils import dataclass_from_dict
from modules.devices.alpha_ess.alpha_ess.config import AlphaEssConfiguration, AlphaEssCounterSetup
from modules.common import modbus
from modules.common.abstract_device import AbstractCounter
from modules.common.component_state import CounterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
from modules.common.modbus import ModbusDataType
from modules.common.store import get_counter_value_store


class AlphaEssCounter:
class AlphaEssCounter(AbstractCounter):
def __init__(self,
device_id: int,
component_config: Union[Dict, AlphaEssCounterSetup],
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/alpha_ess/alpha_ess/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from dataclass_utils import dataclass_from_dict
from modules.devices.alpha_ess.alpha_ess.config import AlphaEssConfiguration, AlphaEssInverterSetup
from modules.common import modbus
from modules.common.abstract_device import AbstractInverter
from modules.common.component_state import InverterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand All @@ -12,7 +13,7 @@
from modules.common.store import get_inverter_value_store


class AlphaEssInverter:
class AlphaEssInverter(AbstractInverter):
def __init__(self, device_id: int,
component_config: Union[Dict, AlphaEssInverterSetup],
tcp_client: modbus.ModbusTcpClient_,
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/azzurro_zcs/azzurro_zcs/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pymodbus.constants import Endian

from dataclass_utils import dataclass_from_dict
from modules.common.abstract_device import AbstractCounter
from modules.common.component_state import CounterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand All @@ -11,7 +12,7 @@
from modules.devices.azzurro_zcs.azzurro_zcs.config import ZCSCounterSetup


class ZCSCounter:
class ZCSCounter(AbstractCounter):
def __init__(self,
component_config: Union[Dict, ZCSCounterSetup],
modbus_id: int) -> None:
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/azzurro_zcs/azzurro_zcs/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pymodbus.constants import Endian

from dataclass_utils import dataclass_from_dict
from modules.common.abstract_device import AbstractInverter
from modules.common.component_state import InverterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand All @@ -11,7 +12,7 @@
from modules.devices.azzurro_zcs.azzurro_zcs.config import ZCSInverterSetup


class ZCSInverter:
class ZCSInverter(AbstractInverter):
def __init__(self,
component_config: Union[Dict, ZCSInverterSetup],
modbus_id: int) -> None:
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/batterx/batterx/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from dataclass_utils import dataclass_from_dict
from modules.devices.batterx.batterx.config import BatterXCounterSetup
from modules.common.abstract_device import AbstractCounter
from modules.common.component_state import CounterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand All @@ -13,7 +14,7 @@
log = logging.getLogger(__name__)


class BatterXCounter:
class BatterXCounter(AbstractCounter):
def __init__(self, device_id: int, component_config: Union[Dict, BatterXCounterSetup]) -> None:
self.__device_id = device_id
self.component_config = dataclass_from_dict(BatterXCounterSetup, component_config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

from dataclass_utils import dataclass_from_dict
from modules.devices.batterx.batterx.config import BatterXExternalInverterSetup
from modules.common.abstract_device import AbstractInverter
from modules.common.component_state import InverterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
from modules.common.simcount import SimCounter
from modules.common.store import get_inverter_value_store


class BatterXExternalInverter:
class BatterXExternalInverter(AbstractInverter):
def __init__(self, device_id: int, component_config: Union[Dict, BatterXExternalInverterSetup]) -> None:
self.__device_id = device_id
self.component_config = dataclass_from_dict(BatterXExternalInverterSetup, component_config)
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/batterx/batterx/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

from dataclass_utils import dataclass_from_dict
from modules.devices.batterx.batterx.config import BatterXInverterSetup
from modules.common.abstract_device import AbstractInverter
from modules.common.component_state import InverterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
from modules.common.simcount import SimCounter
from modules.common.store import get_inverter_value_store


class BatterXInverter:
class BatterXInverter(AbstractInverter):
def __init__(self, device_id: int, component_config: Union[Dict, BatterXInverterSetup]) -> None:
self.__device_id = device_id
self.component_config = dataclass_from_dict(BatterXInverterSetup, component_config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dataclass_utils import dataclass_from_dict
from modules.devices.carlo_gavazzi.carlo_gavazzi.config import CarloGavazziCounterSetup
from modules.common import modbus
from modules.common.abstract_device import AbstractCounter
from modules.common.component_state import CounterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand All @@ -14,7 +15,7 @@
from modules.common.store import get_counter_value_store


class CarloGavazziCounter:
class CarloGavazziCounter(AbstractCounter):
def __init__(self,
device_id: int,
component_config: Union[Dict, CarloGavazziCounterSetup],
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/deye/deye/counter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
from dataclass_utils import dataclass_from_dict
from modules.common.abstract_device import AbstractCounter
from modules.common.component_state import CounterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand All @@ -10,7 +11,7 @@
from modules.devices.deye.deye.device_type import DeviceType


class DeyeCounter:
class DeyeCounter(AbstractCounter):
def __init__(self, device_id: int, component_config: DeyeCounterSetup) -> None:
self.component_config = dataclass_from_dict(DeyeCounterSetup, component_config)
self.store = get_counter_value_store(self.component_config.id)
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/deye/deye/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Dict, Union

from dataclass_utils import dataclass_from_dict
from modules.common.abstract_device import AbstractInverter
from modules.common.component_state import InverterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand All @@ -12,7 +13,7 @@
from modules.devices.deye.deye.device_type import DeviceType


class DeyeInverter:
class DeyeInverter(AbstractInverter):
def __init__(self, device_id: int, component_config: Union[Dict, DeyeInverterSetup]) -> None:
self.component_config = dataclass_from_dict(DeyeInverterSetup, component_config)
self.store = get_inverter_value_store(self.component_config.id)
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/discovergy/discovergy/counter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from requests import Session

from modules.common.abstract_device import AbstractCounter
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
from modules.common.store import get_counter_value_store
from modules.devices.discovergy.discovergy import api
from modules.devices.discovergy.discovergy.config import DiscovergyCounterSetup


class DiscovergyCounter:
class DiscovergyCounter(AbstractCounter):
def __init__(self, component_config: DiscovergyCounterSetup) -> None:
self.component_config = component_config
self.store = get_counter_value_store(self.component_config.id)
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/discovergy/discovergy/inverter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from requests import Session

from modules.common.abstract_device import AbstractInverter
from modules.common.component_state import InverterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand All @@ -8,7 +9,7 @@
from modules.devices.discovergy.discovergy.config import DiscovergyInverterSetup


class DiscovergyInverter:
class DiscovergyInverter(AbstractInverter):
def __init__(self, component_config: DiscovergyInverterSetup) -> None:
self.component_config = component_config
self.store = get_inverter_value_store(self.component_config.id)
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/e3dc/e3dc/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Tuple, List

from modules.common import modbus
from modules.common.abstract_device import AbstractCounter
from modules.common.component_state import CounterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand Down Expand Up @@ -39,7 +40,7 @@ def read_counter(client: modbus.ModbusTcpClient_, modbus_id: int) -> Tuple[int,
return power, powers


class E3dcCounter:
class E3dcCounter(AbstractCounter):
def __init__(self,
device_id: int,
component_config: E3dcCounterSetup,
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/e3dc/e3dc/external_inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging

from modules.common import modbus
from modules.common.abstract_device import AbstractInverter
from modules.common.component_state import InverterState
from modules.common.component_type import ComponentDescriptor
from modules.common.modbus import ModbusDataType, Endian
Expand All @@ -21,7 +22,7 @@ def read_external_inverter(client: modbus.ModbusTcpClient_, modbus_id: int) -> i
return pv_external


class E3dcExternalInverter:
class E3dcExternalInverter(AbstractInverter):
def __init__(self,
device_id: int,
component_config: E3dcExternalInverterSetup,
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/e3dc/e3dc/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging

from modules.common import modbus
from modules.common.abstract_device import AbstractInverter
from modules.common.component_state import InverterState
from modules.common.component_type import ComponentDescriptor
from modules.common.modbus import ModbusDataType, Endian
Expand All @@ -20,7 +21,7 @@ def read_inverter(client: modbus.ModbusTcpClient_, modbus_id: int) -> int:
return pv


class E3dcInverter:
class E3dcInverter(AbstractInverter):
def __init__(self,
device_id: int,
component_config: E3dcInverterSetup,
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/enphase/enphase/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any, Dict, Union

from dataclass_utils import dataclass_from_dict
from modules.common.abstract_device import AbstractCounter
from modules.common.component_state import CounterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand All @@ -12,7 +13,7 @@
log = logging.getLogger(__name__)


class EnphaseCounter:
class EnphaseCounter(AbstractCounter):
def __init__(self, device_id: int, component_config: Union[Dict, EnphaseCounterSetup]) -> None:
self.component_config = dataclass_from_dict(EnphaseCounterSetup, component_config)
self.store = get_counter_value_store(self.component_config.id)
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/enphase/enphase/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any, Dict, Union

from dataclass_utils import dataclass_from_dict
from modules.common.abstract_device import AbstractInverter
from modules.common.component_state import InverterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand All @@ -12,7 +13,7 @@
log = logging.getLogger(__name__)


class EnphaseInverter:
class EnphaseInverter(AbstractInverter):
def __init__(self, device_id: int, component_config: Union[Dict, EnphaseInverterSetup]) -> None:
self.component_config = dataclass_from_dict(EnphaseInverterSetup, component_config)
self.store = get_inverter_value_store(self.component_config.id)
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/fems/fems/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from requests import Session
from helpermodules.scale_metric import scale_metric
from modules.devices.fems.fems.config import FemsCounterSetup
from modules.common.abstract_device import AbstractCounter
from modules.common.component_state import CounterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand All @@ -11,7 +12,7 @@
log = logging.getLogger(__name__)


class FemsCounter:
class FemsCounter(AbstractCounter):
def __init__(self, ip_address: str, component_config: FemsCounterSetup, session: Session) -> None:
self.ip_address = ip_address
self.component_config = component_config
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/fems/fems/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from requests import Session
from helpermodules.scale_metric import scale_metric
from modules.devices.fems.fems.config import FemsInverterSetup
from modules.common.abstract_device import AbstractInverter
from modules.common.component_state import InverterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand All @@ -10,7 +11,7 @@
log = logging.getLogger(__name__)


class FemsInverter:
class FemsInverter(AbstractInverter):
def __init__(self, ip_address: str, component_config: FemsInverterSetup, session: Session) -> None:
self.ip_address = ip_address
self.component_config = component_config
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/fox_ess/fox_ess/counter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
from dataclass_utils import dataclass_from_dict
from modules.common.abstract_device import AbstractCounter
from modules.common.component_state import CounterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand All @@ -8,7 +9,7 @@
from modules.devices.fox_ess.fox_ess.config import FoxEssCounterSetup


class FoxEssCounter:
class FoxEssCounter(AbstractCounter):
def __init__(self, component_config: FoxEssCounterSetup) -> None:
self.component_config = dataclass_from_dict(FoxEssCounterSetup, component_config)
self.store = get_counter_value_store(self.component_config.id)
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/fox_ess/fox_ess/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Dict, Union

from dataclass_utils import dataclass_from_dict
from modules.common.abstract_device import AbstractInverter
from modules.common.component_state import InverterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand All @@ -10,7 +11,7 @@
from modules.devices.fox_ess.fox_ess.config import FoxEssInverterSetup


class FoxEssInverter:
class FoxEssInverter(AbstractInverter):
def __init__(self, component_config: Union[Dict, FoxEssInverterSetup]) -> None:
self.component_config = dataclass_from_dict(FoxEssInverterSetup, component_config)
self.store = get_inverter_value_store(self.component_config.id)
Expand Down
3 changes: 2 additions & 1 deletion packages/modules/devices/fronius/fronius/counter_s0.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from dataclass_utils import dataclass_from_dict
from modules.common import req
from modules.common.abstract_device import AbstractCounter
from modules.common.component_state import CounterState
from modules.common.component_type import ComponentDescriptor
from modules.common.fault_state import ComponentInfo, FaultState
Expand All @@ -11,7 +12,7 @@
from modules.devices.fronius.fronius.config import FroniusConfiguration, FroniusS0CounterSetup


class FroniusS0Counter:
class FroniusS0Counter(AbstractCounter):
def __init__(self,
device_id: int,
component_config: Union[Dict, FroniusS0CounterSetup],
Expand Down
Loading

0 comments on commit 8b468e2

Please sign in to comment.