-
Notifications
You must be signed in to change notification settings - Fork 107
Add IDM heatpump as counter #2766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
977cd16
Create vendor.py
seaspotter 2afad2d
Add files via upload
seaspotter c04e0d3
Create config.py
seaspotter 557cdfe
Add files via upload
seaspotter 696da4b
Create device.py
seaspotter 07d3226
Create counter.py
seaspotter 8073289
Update config.py
seaspotter 6e6ac86
Fix Register
seaspotter b76a167
flake8
seaspotter 4afc6ec
Add modbus_id to IDMCounter and update initialization
seaspotter bdfe62a
fix parameter
LKuemmel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| from typing import Optional | ||
| from helpermodules.auto_str import auto_str | ||
| from modules.common.component_setup import ComponentSetup | ||
| from ..vendor import vendor_descriptor | ||
|
|
||
|
|
||
| @auto_str | ||
| class IDMConfiguration: | ||
| def __init__(self, ip_address: Optional[str] = None, port: int = 502, modbus_id: int = 1): | ||
| self.ip_address = ip_address | ||
| self.port = port | ||
| self.modbus_id = modbus_id | ||
|
|
||
|
|
||
| @auto_str | ||
| class IDM: | ||
| def __init__(self, | ||
| name: str = "IDM", | ||
| type: str = "idm", | ||
| id: int = 0, | ||
| configuration: IDMConfiguration = None) -> None: | ||
| self.name = name | ||
| self.type = type | ||
| self.vendor = vendor_descriptor.configuration_factory().type | ||
| self.id = id | ||
| self.configuration = configuration or IDMConfiguration() | ||
|
|
||
|
|
||
| @auto_str | ||
| class IDMCounterConfiguration: | ||
| def __init__(self): | ||
| pass | ||
|
|
||
|
|
||
| @auto_str | ||
| class IDMCounterSetup(ComponentSetup[IDMCounterConfiguration]): | ||
| def __init__(self, | ||
| name: str = "IDM Zähler", | ||
| type: str = "counter", | ||
| id: int = 0, | ||
| configuration: IDMCounterConfiguration = None) -> None: | ||
| super().__init__(name, type, id, configuration or IDMCounterConfiguration()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #!/usr/bin/env python3 | ||
| from typing import TypedDict, Any | ||
| from pymodbus.constants import Endian | ||
|
|
||
| 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, ModbusTcpClient_ | ||
| from modules.common.simcount import SimCounter | ||
| from modules.common.store import get_counter_value_store | ||
| from modules.devices.idm.idm.config import IDMCounterSetup | ||
|
|
||
|
|
||
| class KwargsDict(TypedDict): | ||
| device_id: int | ||
| client: ModbusTcpClient_ | ||
| modbus_id: int | ||
|
|
||
|
|
||
| class IDMCounter(AbstractCounter): | ||
| def __init__(self, component_config: IDMCounterSetup, **kwargs: Any) -> None: | ||
| self.component_config = component_config | ||
| self.kwargs: KwargsDict = kwargs | ||
|
|
||
| def initialize(self) -> None: | ||
| self.__device_id: int = self.kwargs['device_id'] | ||
| self.client: ModbusTcpClient_ = self.kwargs['client'] | ||
| self.modbus_id: int = self.kwargs['modbus_id'] | ||
| self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="bezug") | ||
| self.store = get_counter_value_store(self.component_config.id) | ||
| self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) | ||
|
|
||
| def update(self): | ||
| unit = self.modbus_id | ||
| power = self.client.read_input_registers(4122, ModbusDataType.FLOAT_32, | ||
| wordorder=Endian.Little, unit=unit) * 1000 | ||
| imported, exported = self.sim_counter.sim_count(power) | ||
|
|
||
| counter_state = CounterState( | ||
| imported=imported, | ||
| exported=exported, | ||
| power=power, | ||
| ) | ||
| self.store.set(counter_state) | ||
|
|
||
|
|
||
| component_descriptor = ComponentDescriptor(configuration_factory=IDMCounterSetup) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #!/usr/bin/env python3 | ||
| import logging | ||
| from typing import Iterable | ||
|
|
||
| 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 ModbusTcpClient_ | ||
| from modules.devices.idm.idm.config import IDM, IDMCounterSetup | ||
| from modules.devices.idm.idm.counter import IDMCounter | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def create_device(device_config: IDM): | ||
| client = None | ||
|
|
||
| def create_counter_component(component_config: IDMCounterSetup): | ||
| nonlocal client | ||
| return IDMCounter(component_config, | ||
| device_id=device_config.id, | ||
| client=client, | ||
| modbus_id=device_config.configuration.modbus_id) | ||
|
|
||
| def update_components(components: Iterable[IDMCounter]): | ||
| with client: | ||
| for component in components: | ||
| with SingleComponentUpdateContext(component.fault_state): | ||
| component.update() | ||
|
|
||
| def initializer(): | ||
| nonlocal client | ||
| client = ModbusTcpClient_(device_config.configuration.ip_address, device_config.configuration.port) | ||
|
|
||
| return ConfigurableDevice( | ||
| device_config=device_config, | ||
| initializer=initializer, | ||
| component_factory=ComponentFactoryByType( | ||
| counter=create_counter_component, | ||
| ), | ||
| component_updater=MultiComponentUpdater(update_components) | ||
seaspotter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
|
|
||
| device_descriptor = DeviceDescriptor(configuration_factory=IDM) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = "IDM" | ||
| self.group = VendorGroup.VENDORS.value | ||
|
|
||
|
|
||
| vendor_descriptor = DeviceDescriptor(configuration_factory=Vendor) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.