matthewwall / weewx-mqtt

upload data to mqtt broker
58 stars 31 forks source link

Exception with explicit default config for 'aggregation' #20

Open ThomDietrich opened 3 years ago

ThomDietrich commented 3 years ago

With weewx.conf:

    [[MQTT]]
        ...
        aggregation = individual, aggregate

I'm seeing the issue below. I know it's the default but still wanted to report the error. Best!

weewx_1      | May 16 19:30:58 weewx[18] ERROR weewx.restx: MQTT: Unexpected exception of type <class 'AttributeError'>
weewx_1      | May 16 19:30:58 weewx[18] ERROR weewx.restx: *** Traceback (most recent call last):
weewx_1      | May 16 19:30:58 weewx[18] ERROR weewx.restx: ***   File "/home/weewx/bin/weewx/restx.py", line 381, in run_loop
weewx_1      | May 16 19:30:58 weewx[18] ERROR weewx.restx: ***     self.process_record(_record, dbmanager)
weewx_1      | May 16 19:30:58 weewx[18] ERROR weewx.restx: ***   File "/home/weewx/bin/user/mqtt.py", line 496, in process_record
weewx_1      | May 16 19:30:58 weewx[18] ERROR weewx.restx: ***     if self.aggregation.find('aggregate') >= 0:
weewx_1      | May 16 19:30:58 weewx[18] ERROR weewx.restx: *** AttributeError: 'list' object has no attribute 'find'
weewx_1      | May 16 19:30:58 weewx[18] CRITICAL weewx.restx: MQTT: Thread terminating. Reason: 'list' object has no attribute 'find'
weewx_1      | Exception in thread MQTT:
weewx_1      | Traceback (most recent call last):
weewx_1      |   File "/usr/local/lib/python3.9/threading.py", line 954, in _bootstrap_inner
weewx_1      |     self.run()
weewx_1      |   File "/home/weewx/bin/weewx/restx.py", line 354, in run
weewx_1      |     self.run_loop(_manager)
weewx_1      |   File "/home/weewx/bin/weewx/restx.py", line 381, in run_loop
weewx_1      |     self.process_record(_record, dbmanager)
weewx_1      |   File "/home/weewx/bin/user/mqtt.py", line 496, in process_record
weewx_1      |     if self.aggregation.find('aggregate') >= 0:
weewx_1      | AttributeError: 'list' object has no attribute 'find'
alexdelprete commented 3 years ago

aggregation is a string, not the same type as the binding, so the syntax is not the same.

Try with quotes:

aggregation = "individual, aggregate"

If it doesn't work, try also removing the space:

aggregation = "individual,aggregate"

alexslaets commented 2 years ago

I confirm this solution.

ThomDietrich commented 2 years ago

I can confirm too, however see this as a workaround. The rest of the configuration file weewx.conf works with lists (like hemispheres = N, S, E, W) and so should addons.

This looks like a rather easy thing to solve. Untested:

                aggregation = self.aggregation if isinstance(self.aggregation, list) else [self.aggregation]
                if 'aggregate' in aggregation:
                    ...
                if 'individual' in aggregation:
                    ...
alexdelprete commented 2 years ago

I can confirm too, however see this as a workaround.

obviously it's a workaround, found by looking at the code, and that's all we can do for now, since we cannot commit the needed modifications, only Matthew can.

I'm sure as soon as he will be back he'll fix this.

HoracioDos commented 1 year ago

Thank you for this workaround. I was getting into trouble to make it work.