Skip to content

Commit e7b5207

Browse files
ndrsnhsLKuemmel
andauthored
Kaco NH Serie (#2721)
* add kaco nh module * minor fix * remove variable * Update packages/modules/devices/kaco/kaco_nh/inverter.py * Update packages/modules/devices/kaco/kaco_nh/inverter.py * fix error --------- Co-authored-by: LKuemmel <76958050+LKuemmel@users.noreply.github.com>
1 parent 1a4c104 commit e7b5207

5 files changed

Lines changed: 251 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
from typing import Any, TypedDict
3+
4+
from modules.common import req
5+
from modules.common.abstract_device import AbstractBat
6+
from modules.common.component_state import BatState
7+
from modules.common.component_type import ComponentDescriptor
8+
from modules.common.fault_state import ComponentInfo, FaultState
9+
from modules.common.simcount import SimCounter
10+
from modules.common.store import get_bat_value_store
11+
from modules.devices.kaco.kaco_nh.config import KacoNHBatSetup
12+
from modules.devices.kaco.kaco_nh.config import KacoNHConfiguration
13+
14+
15+
class KwargsDict(TypedDict):
16+
device_config: KacoNHConfiguration
17+
device_id: int
18+
19+
20+
class KacoNHBat(AbstractBat):
21+
def __init__(self, component_config: KacoNHBatSetup, **kwargs: Any) -> None:
22+
self.component_config = component_config
23+
self.kwargs: KwargsDict = kwargs
24+
25+
def initialize(self) -> None:
26+
self.__device_id: int = self.kwargs['device_id']
27+
self.device_config: KacoNHConfiguration = self.kwargs['device_config']
28+
self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="speicher")
29+
self.store = get_bat_value_store(self.component_config.id)
30+
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))
31+
32+
def update(self) -> None:
33+
response = req.get_http_session().get(
34+
'http://' + self.device_config.ip_address + ':' + str(self.device_config.port) + '/getdevdata.cgi?device=' +
35+
str(self.component_config.configuration.id) + '&sn=' + self.device_config.serial_number,
36+
timeout=5).json()
37+
power = int(response["pb"]) * -1
38+
soc = float(response["soc"])
39+
40+
imported, exported = self.sim_counter.sim_count(power)
41+
bat_state = BatState(
42+
power=power,
43+
soc=soc,
44+
imported=imported,
45+
exported=exported
46+
)
47+
self.store.set(bat_state)
48+
49+
50+
component_descriptor = ComponentDescriptor(configuration_factory=KacoNHBatSetup)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env python3
2+
from typing import Optional
3+
4+
from modules.common.component_setup import ComponentSetup
5+
from ..vendor import vendor_descriptor
6+
7+
8+
class KacoNHConfiguration:
9+
def __init__(self, ip_address: Optional[str] = None,
10+
port: Optional[int] = None,
11+
serial_number: Optional[str] = None):
12+
self.ip_address = ip_address
13+
self.port = port
14+
self.serial_number = serial_number
15+
16+
17+
class KacoNH:
18+
def __init__(self,
19+
name: str = "Kaco NH",
20+
type: str = "kaco_nh",
21+
id: int = 0,
22+
configuration: KacoNHConfiguration = None) -> None:
23+
self.name = name
24+
self.type = type
25+
self.vendor = vendor_descriptor.configuration_factory().type
26+
self.id = id
27+
self.configuration = configuration or KacoNHConfiguration()
28+
29+
30+
class KacoNHBatConfiguration:
31+
def __init__(self, id: int = 0):
32+
self.id = id
33+
34+
35+
class KacoNHBatSetup(ComponentSetup[KacoNHBatConfiguration]):
36+
def __init__(self,
37+
name: str = "Kaco NH Speicher",
38+
type: str = "bat",
39+
id: int = 0,
40+
configuration: KacoNHBatConfiguration = None) -> None:
41+
super().__init__(name, type, id, configuration or KacoNHBatConfiguration())
42+
43+
44+
class KacoNHCounterConfiguration:
45+
def __init__(self, id: int = 0):
46+
self.id = id
47+
48+
49+
class KacoNHCounterSetup(ComponentSetup[KacoNHCounterConfiguration]):
50+
def __init__(self,
51+
name: str = "Kaco NH Zähler",
52+
type: str = "counter",
53+
id: int = 0,
54+
configuration: KacoNHCounterConfiguration = None) -> None:
55+
super().__init__(name, type, id, configuration or KacoNHCounterConfiguration())
56+
57+
58+
class KacoNHInverterConfiguration:
59+
def __init__(self, id: int = 0):
60+
self.id = id
61+
62+
63+
class KacoNHInverterSetup(ComponentSetup[KacoNHInverterConfiguration]):
64+
def __init__(self,
65+
name: str = "KacoNH Wechselrichter",
66+
type: str = "inverter",
67+
id: int = 0,
68+
configuration: KacoNHInverterConfiguration = None) -> None:
69+
super().__init__(name, type, id, configuration or KacoNHInverterConfiguration())
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python3
2+
from typing import TypedDict, Any
3+
4+
from modules.common import req
5+
from modules.common.abstract_device import AbstractCounter
6+
from modules.common.component_state import CounterState
7+
from modules.common.component_type import ComponentDescriptor
8+
from modules.common.fault_state import ComponentInfo, FaultState
9+
from modules.common.store import get_counter_value_store
10+
from modules.devices.kaco.kaco_nh.config import KacoNHConfiguration, KacoNHCounterSetup
11+
12+
13+
class KwargsDict(TypedDict):
14+
device_config: KacoNHConfiguration
15+
16+
17+
class KacoNHCounter(AbstractCounter):
18+
def __init__(self, component_config: KacoNHCounterSetup, **kwargs: Any) -> None:
19+
self.component_config = component_config
20+
self.kwargs: KwargsDict = kwargs
21+
22+
def initialize(self) -> None:
23+
self.device_config: KacoNHConfiguration = self.kwargs['device_config']
24+
self.store = get_counter_value_store(self.component_config.id)
25+
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))
26+
27+
def update(self) -> None:
28+
response = req.get_http_session().get(
29+
'http://' + self.device_config.ip_address + ':' + str(self.device_config.port) + '/getdevdata.cgi?device=' +
30+
str(self.component_config.configuration.id) + '&sn=' + self.device_config.serial_number,
31+
timeout=5).json()
32+
power = float(response["pac"])
33+
imported = float(response["iet"]) * 100
34+
exported = float(response["oet"]) * 100
35+
36+
counter_state = CounterState(
37+
imported=imported,
38+
exported=exported,
39+
power=power
40+
)
41+
self.store.set(counter_state)
42+
43+
44+
component_descriptor = ComponentDescriptor(configuration_factory=KacoNHCounterSetup)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python3
2+
import logging
3+
from typing import Iterable, Union
4+
5+
from modules.common.abstract_device import DeviceDescriptor
6+
from modules.common.configurable_device import ComponentFactoryByType, ConfigurableDevice, MultiComponentUpdater
7+
from modules.devices.kaco.kaco_nh.bat import KacoNHBat
8+
from modules.devices.kaco.kaco_nh.config import (KacoNH, KacoNHBatSetup,
9+
KacoNHCounterSetup, KacoNHInverterSetup)
10+
from modules.devices.kaco.kaco_nh.counter import KacoNHCounter
11+
from modules.devices.kaco.kaco_nh.inverter import KacoNHInverter
12+
13+
log = logging.getLogger(__name__)
14+
15+
16+
def create_device(device_config: KacoNH):
17+
def create_bat_component(component_config: KacoNHBatSetup):
18+
return KacoNHBat(component_config=component_config,
19+
device_config=device_config.configuration,
20+
device_id=device_config.id)
21+
22+
def create_counter_component(component_config: KacoNHCounterSetup):
23+
return KacoNHCounter(component_config=component_config,
24+
device_config=device_config.configuration)
25+
26+
def create_inverter_component(component_config: KacoNHInverterSetup):
27+
return KacoNHInverter(component_config=component_config,
28+
device_config=device_config.configuration)
29+
30+
def update_components(components: Iterable[Union[KacoNHBat, KacoNHCounter, KacoNHInverter]]):
31+
for component in components:
32+
component.update()
33+
34+
return ConfigurableDevice(
35+
device_config=device_config,
36+
component_factory=ComponentFactoryByType(
37+
bat=create_bat_component,
38+
counter=create_counter_component,
39+
inverter=create_inverter_component,
40+
),
41+
component_updater=MultiComponentUpdater(update_components)
42+
)
43+
44+
45+
device_descriptor = DeviceDescriptor(configuration_factory=KacoNH)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
from typing import Dict, TypedDict, Any
3+
4+
from modules.common import req
5+
from modules.common.abstract_device import AbstractInverter
6+
from modules.common.component_state import InverterState
7+
from modules.common.component_type import ComponentDescriptor
8+
from modules.common.fault_state import ComponentInfo, FaultState
9+
from modules.common.store import get_inverter_value_store
10+
from modules.devices.kaco.kaco_nh.config import KacoNHInverterSetup
11+
from modules.devices.kaco.kaco_nh.config import KacoNHConfiguration
12+
13+
14+
class KwargsDict(TypedDict):
15+
device_config: KacoNHConfiguration
16+
17+
18+
class KacoNHInverter(AbstractInverter):
19+
def __init__(self, component_config: KacoNHInverterSetup, **kwargs: Any) -> None:
20+
self.component_config = component_config
21+
self.kwargs: KwargsDict = kwargs
22+
23+
def initialize(self) -> None:
24+
self.device_config: KacoNHConfiguration = self.kwargs['device_config']
25+
self.store = get_inverter_value_store(self.component_config.id)
26+
self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config))
27+
28+
def update(self, response: Dict) -> None:
29+
response = req.get_http_session().get(
30+
'http://' + self.device_config.ip_address + ':' + str(self.device_config.port) + '/getdevdata.cgi?device=' +
31+
str(self.component_config.configuration.id) + '&sn=' + self.device_config.serial_number,
32+
timeout=5).json()
33+
34+
power = float(response["pac"]) * -1
35+
exported = float(response["eto"]) * 100
36+
37+
self.store.set(InverterState(
38+
power=power,
39+
exported=exported
40+
))
41+
42+
43+
component_descriptor = ComponentDescriptor(configuration_factory=KacoNHInverterSetup)

0 commit comments

Comments
 (0)