Skip to content

Inefficient socket reading causes failures in home assistant #66

@TD22057

Description

@TD22057

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions