Skip to content

Commit

Permalink
VEDirect driver: Avoid naming collision when reading multiple devices
Browse files Browse the repository at this point in the history
  • Loading branch information
nznobody authored and amotl committed Sep 16, 2021
1 parent 34a442e commit c6a494d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib/terkin/driver/vedirect_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,19 @@ def read(self):
return
log.info('Reading sensor "Victron Energy VE.Direct"')

# Read raw data from sensor.
data_raw = self.driver.read_data_single()

# Compute key fragment based on information from data packet.
if "PID" in data_raw:
product_id = str(data_raw["PID"])
else:
product_id = "unknown-pid"

# Aggregate measurement values.
data = {}
for key, value in data_raw.items():
key = "vedirect:{}".format(key)
key = "vedirect-{}:{}".format(product_id, key)
data[key] = value

return data

0 comments on commit c6a494d

Please sign in to comment.