johanmeijer / grott

Growatt inverter monitor
https://github.com/johanmeijer/grott/wiki
375 stars 103 forks source link

InfluxDb2 client write_api's write method accepts a dict, not a list #454

Closed jar349 closed 8 months ago

jar349 commented 8 months ago

Code for sending records to InfluxDB2 lives in grottdata.py. In grottdata.py, a list is created with one element: the ifobj which is the dict of data we wish to send to InfluxDB2.

https://github.com/johanmeijer/grott/blob/master/grottdata.py#L641-L642

#Create list for influx
ifjson = [ifobj]

However, in the latest release of the influxdb-client-python package (1.38.0), the write method on the WriteApi class accepts a dict but not a list.

https://github.com/influxdata/influxdb-client-python/blob/v1.38.0/influxdb_client/client/write_api.py#L305-L306

:param record: Point, Line Protocol, Dictionary, NamedTuple, Data Classes, Pandas DataFrame or
               RxPY Observable to write

When I use your code in the python REPL, I change ifresult = conf.ifwrite_api.write(conf.ifbucket,conf.iforg,ifjson) to ifresult = conf.ifwrite_api.write(conf.ifbucket,conf.iforg,ifobj) (send the dict itself instead of a list containing the dict) and then the fields have datapoints assocated with them.

Based on this, I propose that grott stop submitting a list when using the influxdb2 client and instead directly submit the dict.

jar349 commented 8 months ago

While I believe that what I wrote was correct, I also discovered this problem: https://github.com/johanmeijer/grott/issues/455 and I believe that I was "tricked" into thinking that a list isn't working because there was no data for the measurement. But the measurement was there, which should have been a clue to me that I needed to wait an hour to see the data because of the bug in the linked issue.

Since it does seem that the influxdb2 client library is correctly handling a list, I am going to close this issue.