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

Inefficient socket reading causes failures in home assistant #66

Open
TD22057 opened this issue Feb 22, 2022 · 3 comments
Open

Inefficient socket reading causes failures in home assistant #66

TD22057 opened this issue Feb 22, 2022 · 3 comments

Comments

@TD22057
Copy link
Contributor

TD22057 commented Feb 22, 2022

I'm using my alarmdecoder (AD) with a ser2sock front end in a home assistant installation (HA). When I just have a basic HA with AD and no other components, everything works fine. However, when I add a lot of other integrations into HA, then AD starts missing events - I have multiple wireless zones that report open and never close (or closed and never opened). Unfortunately there is no logging in the library so I can't easily debug where these message are being lost. But - because everything works fine with just HA+AD and it's only if I add more components to HA does it start to fail, I believe I know what the problem is.

HA works using async IO everywhere. The AD network code is very inefficient - it calls select() and reads one character a time when the select triggers. I'm not sure why that's the case but I'm pretty certain that's what's causing the issue as I believe the AD code isn't being run often enough to read all the messages.

A fairly simple change to recv() to read as much data as there and then split that into lines for processing should help. Switching to the the more efficient poll system or better yet, the selectors library would also help.

To help fix my HA problems, I wrote a small alarmdecoder->MQTT bridge app that runs outside HA so it doesn't have any problems with the HA event loop. You can find a the read/parse code I used there as an example if that helps.

@jarkastr
Copy link

jarkastr commented Mar 6, 2022

@TD22057 I am having a problem where HA can read alarmdecoder armed and zone statuses and it can send a single key alarm, but it has completely stopped letting me disarm/arm if i have to key in my whole code in home assistant. I suspect it has a similar cause as above. Thoughts?

@TD22057
Copy link
Contributor Author

TD22057 commented Mar 7, 2022

No idea - w/o logging output in either the alarmdecoder HA component or in the alarmdecoder library itself there isn't any way to tell. IMO you should open a bug report in the home assistant github repo for that.

@f34rdotcom
Copy link
Contributor

Not sure if it will help but you could enable verbose logging on ser2sock and maybe it will show what is happening in more detail. You can increase to the point where it will dump all TX/RX data raw into syslog.

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

3 participants