domschl/python-fhem

Queue filterlist parameter: Index out of range error

varna9000 opened this issue · 6 comments

Hi, I'm trying to filter on client slide one device and one reading like this:

fhemev = fhem.FhemEventQueue("192.168.0.2",que, filterlist=[{'device':'WeatherAlarms', "reading":"code"}])

Although I see the requested reading, I'm getting the following error:

{'timestamp': datetime.datetime(2020, 3, 24, 14, 52, 13), 'devicetype': 'CustomReadings', 'device': 'WeatherAlarms', 'reading': 'code', 'value': 'Жълт', 'unit': ''}

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/fhem/init.py", line 800, in _event_worker_thread
if vl[0][-1] == ':':
IndexError: string index out of range

The script doesn't break but upon second event, I don't receive any reading anymore. Also I noticed that if reading is string containing few words (e.g. "high temperature"), it gets broken in words and only first one (eg "high") is passed to the returned dictionary and the second is passed into "units". I guess you have done it for your particular case, but it breaks up in the case which I've mentioned.

I've published a new version 0.6.4 on pypi that (hopefully) fixes the crash of the background event thread. Please let me know, if this solves your problem.

This doesn't fix the multi-word problem yet. And I am not sure, if this can be fixed, without potentially breaking other things. To my knowledge this FHEM protocol just isn't defined well enough.

Yes, that fixes the index out of range. Thank you!
As for multi-word issue, do you think that we can just skip the "units"? if we leave 'val' to be equal to li[4:] here ? It's not straightforward and will break other things, you are right. I'll try to change it for my own case, as I don't really need units.

Edit: ok, so for my particular case, changing the output list (lines 832-838) works fine like this:

'timestamp': dt,
'devicetype': devtype,
'device': dev,
'reading': read,
#'value': val,
'value':li[4:]
#'unit': unit

I am preparing a new version with a new option raw_value, that simply returns the full remainder as string...

There's now 0.6.5 on pypi.
If you create the Queue with fhemev = fhem.FhemEventQueue("192.168.0.2",que, raw_value=True,...) the value returned is just the complete unparsed remainder-string. unit is always None with raw_value=True.
Please comment, if this works / is useful.

Working as expected! Thanks for your efforts :) Great library!

Tx!