kpetremann / mqtt-exporter

Simple generic MQTT Prometheus exporter for IoT working out of the box
https://hub.docker.com/r/kpetrem/mqtt-exporter
MIT License
110 stars 30 forks source link

add support for parsing values containing lists #44

Closed rixxxx closed 1 year ago

rixxxx commented 1 year ago

Shelly 3EM running Tasmota sends following. This patch enables mqtt-exporter to extract values from lists.

Before: DEBUG:mqtt-exporter:Failed to convert Power: Can't parse '[148, 133, 106]' to a number.

Now: DEBUG:mqtt-exporter:parsing list Power: [104, 133, 107] DEBUG:mqtt-exporter:new value for mqtt_ENERGY_Power_0: 104 DEBUG:mqtt-exporter:new value for mqtt_ENERGY_Power_1: 133 DEBUG:mqtt-exporter:new value for mqtt_ENERGY_Power_2: 107

MQTT message: { "Time": "2023-01-28T01:08:31", "ENERGY": { "TotalStartTime": "2023-01-23T23:19:38", "Total": 2.785, "Yesterday": 1.748, "Today": 1.037, "TodaySumImport": 1.037, "TodaySumExport": 0, "ExportActive": [ 0, 0, 0 ], "Period": [ 12, 11, 9 ], "Power": [ 97, 133, 107 ], "ApparentPower": [ 153, 182, 214 ], "ReactivePower": [ 118, 125, 186 ], "Factor": [ 0.64, 0.73, 0.5 ], "Frequency": [ 50, 50, 50 ], "Voltage": [ 231, 227, 234 ], "Current": [ 0.66, 0.803, 0.917 ], "CurrentNeutral": 0.011 } }

kpetremann commented 1 year ago

Hello @rixxxx, Thanks for the PR. Could you add a unit test for this as described in the contribute section in the README?

rixxxx commented 1 year ago

Hi,

Sure, I'll add the tests.

kpetremann commented 1 year ago

Hi @rixxxx, any news?

rixxxx commented 1 year ago

Hi, test added.

kpetremann commented 1 year ago

@rixxxx you should just run black. It will solve all the format issues.

rixxxx commented 1 year ago

hopefully its now ok

kpetremann commented 1 year ago

it is :tada: thanks again for the PR