Skip to content
Merged

Vampair #3815

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
3 changes: 2 additions & 1 deletion docs/samples/sample_consumer/sample_consumer/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from modules.common.abstract_consumer import CurrentValues
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_state import ConsumerState
from modules.common.component_type import ComponentType
from modules.common.configurable_consumer import ConfigurableConsumer
from modules.common.modbus import ModbusDataType, ModbusTcpClient_
from modules.common.simcount._simcounter import SimCounterConsumer
from modules.consumers.askoma.askoheat.config import SampleConsumer
from modules.consumers.sample.sample.config import SampleConsumer

log = logging.getLogger(__name__)

Expand Down
4 changes: 1 addition & 3 deletions packages/modules/consumers/generic/json/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def __init__(self,
jq_switch_off: str = None,
jq_set_power_limit: str = None):
self.url = url
self.jq_current_l1 = jq_current_l1
self.jq_current_l2 = jq_current_l2
self.jq_current_l3 = jq_current_l3
self.jq_currents = (jq_current_l1, jq_current_l2, jq_current_l3)
self.jq_power = jq_power
self.jq_temperatures = jq_temperatures
self.jq_imported = jq_imported
Expand Down
6 changes: 3 additions & 3 deletions packages/modules/consumers/generic/json/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ def update() -> None:

def switch_on():
# Authorization?
jq_switch_on(session, params={"state": True})
jq_switch_on({"state": True})

def switch_off():
# Authorization?
jq_switch_off(session, params={"state": False})
jq_switch_off({"state": False})

def set_power_limit(power_limit: int):
# Authorization?
jq_set_power_limit(session, params={"power_limit": power_limit})
jq_set_power_limit({"power_limit": power_limit})

return ConfigurableConsumer(consumer_config=config,
initializer=initializer,
Expand Down
4 changes: 2 additions & 2 deletions packages/modules/consumers/my_pv/elwa_e/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def error_handler() -> None:
initializer()

def update() -> ConsumerState:
nonlocal status
nonlocal power, status
resp = client.read_holding_registers_bulk(
Register.POWER, 4, mapping=REG_MAPPING, unit=config.configuration.modbus_id)
power = resp[Register.POWER]
Expand All @@ -77,7 +77,7 @@ def set_limit(power_limit: float) -> None:
if power_limit < power:
power_limit = power + (power - power_limit) * fuse
power_limit = min(power_limit, 4000)
power_limit = min(power_limit, 0)
power_limit = max(power_limit, 0)

client.write_registers(1000, power_limit, unit=config.configuration.modbus_id)
return ConfigurableConsumer(consumer_config=config,
Expand Down
Empty file.
Empty file.
29 changes: 29 additions & 0 deletions packages/modules/consumers/solarfocus/vampair/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import Optional, Tuple

from control.consumer.consumer_data import ConsumerUsage
from helpermodules.auto_str import auto_str
from modules.common.consumer_setup import ConsumerSetup
from ..vendor import vendor_descriptor


@auto_str
class VampairConfiguration:
def __init__(self, ip_address: Optional[str] = None, port: Optional[int] = 502, modbus_id: Optional[int] = 1):
self.ip_address = ip_address
self.port = port
self.modbus_id = modbus_id


@auto_str
class Vampair(ConsumerSetup[VampairConfiguration]):
def __init__(self,
name: str = "Vampair Wärmepumpe",
type: str = "vampair",
id: int = 0,
configuration: VampairConfiguration = None,
usage: Tuple[ConsumerUsage, ...] = (ConsumerUsage.SELF_CONTROLLED,
ConsumerUsage.SUSPENDABLE_TUNABLE,
ConsumerUsage.METER_ONLY),
**kwargs) -> None:
super().__init__(name, type, id, vendor=vendor_descriptor.configuration_factory(
).type, configuration=configuration or VampairConfiguration(), usage=usage, **kwargs)
50 changes: 50 additions & 0 deletions packages/modules/consumers/solarfocus/vampair/consumer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
from modules.common.abstract_consumer import CurrentValues
from modules.common.abstract_device import DeviceDescriptor
from modules.common.component_state import ConsumerState
from modules.common.component_type import ComponentType
from modules.common.configurable_consumer import ConfigurableConsumer
from modules.common.modbus import ModbusDataType, ModbusTcpClient_
from modules.common.simcount._simcounter import SimCounterConsumer
from modules.consumers.solarfocus.vampair.config import Vampair


def create_consumer(config: Vampair):
client = None
sim_counter = None

def initializer():
nonlocal client, sim_counter
client = ModbusTcpClient_(config.configuration.ip_address, config.configuration.port)
sim_counter = SimCounterConsumer(config.id, ComponentType.CONSUMER)

def error_handler() -> None:
initializer()

def update() -> ConsumerState:
power = client.read_holding_registers(2322, ModbusDataType.INT_16, unit=config.configuration.modbus_id)
imported, exported = sim_counter.sim_count(power)
return ConsumerState(
power=power,
imported=imported,
exported=exported
)

def set_power_limit(power_limit: float) -> None:
# Elektrische Sollleistung HEMS (PV)
client.write_register(33415, power_limit, unit=config.configuration.modbus_id)
client.write_register(33409, power_limit * -1, unit=config.configuration.modbus_id)

def send_values(values: CurrentValues) -> None:
client.write_register(33408, values.pv_power * -1, unit=config.configuration.modbus_id)
client.write_register(33409, values.evu_power * -1, unit=config.configuration.modbus_id)

return ConfigurableConsumer(consumer_config=config,
initializer=initializer,
error_handler=error_handler,
update=update,
set_power_limit=set_power_limit,
send_values=send_values)


device_descriptor = DeviceDescriptor(configuration_factory=Vampair)
14 changes: 14 additions & 0 deletions packages/modules/consumers/solarfocus/vendor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pathlib import Path

from modules.common.abstract_device import DeviceDescriptor
from modules.devices.vendors import VendorGroup


class Vendor:
def __init__(self):
self.type = Path(__file__).parent.name
self.vendor = "Solarfocus"
self.group = VendorGroup.VENDORS.value


vendor_descriptor = DeviceDescriptor(configuration_factory=Vendor)