Skip to content

Commit d889fa6

Browse files
authored
Revert "Improve support of two rs485 inputs at once and single output transport"
1 parent aeef8bb commit d889fa6

6 files changed

Lines changed: 10 additions & 539 deletions

File tree

MULTIPROCESSING.md

Lines changed: 0 additions & 166 deletions
This file was deleted.

classes/protocol_settings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class protocol_settings:
265265
_log : logging.Logger = None
266266

267267

268-
def __init__(self, protocol : str, transport_settings : "SectionProxy" = None, settings_dir : str = "protocols", unique_id : str = None):
268+
def __init__(self, protocol : str, transport_settings : "SectionProxy" = None, settings_dir : str = "protocols"):
269269

270270
#apply log level to logger
271271
self._log_level = getattr(logging, logging.getLevelName(logging.getLogger().getEffectiveLevel()), logging.INFO)
@@ -275,7 +275,6 @@ def __init__(self, protocol : str, transport_settings : "SectionProxy" = None, s
275275
self.protocol = protocol
276276
self.settings_dir = settings_dir
277277
self.transport_settings = transport_settings
278-
self.unique_id = unique_id # Store unique identifier for this instance
279278

280279
#load variable mask
281280
self.variable_mask = []

classes/transports/influxdb_out.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from configparser import SectionProxy
33
from typing import TextIO
44
import time
5-
import logging
65

76
from defs.common import strtobool
87

@@ -22,7 +21,6 @@ class influxdb_out(transport_base):
2221
include_device_info: bool = True
2322
batch_size: int = 100
2423
batch_timeout: float = 10.0
25-
force_float: bool = True # Force all numeric fields to be floats to avoid InfluxDB type conflicts
2624

2725
client = None
2826
batch_points = []
@@ -39,7 +37,6 @@ def __init__(self, settings: SectionProxy):
3937
self.include_device_info = strtobool(settings.get("include_device_info", fallback=self.include_device_info))
4038
self.batch_size = settings.getint("batch_size", fallback=self.batch_size)
4139
self.batch_timeout = settings.getfloat("batch_timeout", fallback=self.batch_timeout)
42-
self.force_float = strtobool(settings.get("force_float", fallback=self.force_float))
4340

4441
self.write_enabled = True # InfluxDB output is always write-enabled
4542
super().__init__(settings)
@@ -106,17 +103,14 @@ def write_data(self, data: dict[str, str], from_transport: transport_base):
106103
for key, value in data.items():
107104
# Check if we should force float formatting based on protocol settings
108105
should_force_float = False
109-
unit_mod_found = None
110106

111107
# Try to get registry entry from protocol settings to check unit_mod
112108
if hasattr(from_transport, 'protocolSettings') and from_transport.protocolSettings:
113109
# Check both input and holding registries
114110
for registry_type in [Registry_Type.INPUT, Registry_Type.HOLDING]:
115111
registry_map = from_transport.protocolSettings.get_registry_map(registry_type)
116112
for entry in registry_map:
117-
# Match by variable_name (which is lowercase)
118-
if entry.variable_name.lower() == key.lower():
119-
unit_mod_found = entry.unit_mod
113+
if entry.variable_name == key:
120114
# If unit_mod is not 1.0, this value should be treated as float
121115
if entry.unit_mod != 1.0:
122116
should_force_float = True
@@ -130,28 +124,14 @@ def write_data(self, data: dict[str, str], from_transport: transport_base):
130124
# Try to convert to float first
131125
float_val = float(value)
132126

133-
# Always use float for InfluxDB to avoid type conflicts
134-
# InfluxDB is strict about field types - once a field is created as integer,
135-
# it must always be integer. Using float avoids this issue.
136-
if self.force_float:
127+
# If it's an integer but should be forced to float, or if it's already a float
128+
if should_force_float or not float_val.is_integer():
137129
fields[key] = float_val
138130
else:
139-
# Only use integer if it's actually an integer and we're not forcing floats
140-
if float_val.is_integer():
141-
fields[key] = int(float_val)
142-
else:
143-
fields[key] = float_val
144-
145-
# Log data type conversion for debugging
146-
if self._log.isEnabledFor(logging.DEBUG):
147-
original_type = type(value).__name__
148-
final_type = type(fields[key]).__name__
149-
self._log.debug(f"Field {key}: {value} ({original_type}) -> {fields[key]} ({final_type}) [unit_mod: {unit_mod_found}]")
150-
131+
fields[key] = int(float_val)
151132
except (ValueError, TypeError):
152133
# If conversion fails, store as string
153134
fields[key] = str(value)
154-
self._log.debug(f"Field {key}: {value} -> string (conversion failed)")
155135

156136
# Create InfluxDB point
157137
point = {

classes/transports/transport_base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,7 @@ def __init__(self, settings : "SectionProxy") -> None:
112112
#must load after settings
113113
self.protocol_version = settings.get("protocol_version")
114114
if self.protocol_version:
115-
# Create a unique protocol settings instance for each transport to avoid shared state
116-
unique_id = f"{self.transport_name}_{self.protocol_version}"
117-
self._log.debug(f"Creating protocol settings with unique_id: {unique_id}")
118-
self.protocolSettings = protocol_settings(self.protocol_version, transport_settings=settings, unique_id=unique_id)
115+
self.protocolSettings = protocol_settings(self.protocol_version, transport_settings=settings)
119116

120117
if self.protocolSettings:
121118
self.protocol_version = self.protocolSettings.protocol

0 commit comments

Comments
 (0)