Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queue filterlist parameter: Index out of range error #21

Closed
varna9000 opened this issue Mar 24, 2020 · 6 comments
Closed

Queue filterlist parameter: Index out of range error #21

varna9000 opened this issue Mar 24, 2020 · 6 comments

Comments

@varna9000
Copy link

varna9000 commented Mar 24, 2020

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.

@domschl
Copy link
Owner

domschl commented Mar 24, 2020

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.

@varna9000
Copy link
Author

varna9000 commented Mar 24, 2020

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

@domschl
Copy link
Owner

domschl commented Mar 24, 2020

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

@domschl
Copy link
Owner

domschl commented Mar 24, 2020

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.

@domschl domschl reopened this Mar 24, 2020
@varna9000
Copy link
Author

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

@domschl
Copy link
Owner

domschl commented Mar 24, 2020

Tx!

@domschl domschl closed this as completed Mar 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants