Closed zlymeda closed 10 months ago
We cannot remove the 1 second timeout - it wiľ break installation of other people
We cannot remove the 1 second timeout - it wiľ break installation of other people
do you know why it is necessary? it was not called for me for some reason, I think because of calling it in wrong thread. so I can run it similarly as the other fixes.
I was just wondering what is the reason for that timeout.
hi @kukulich I posted an update. however, I am not sure if it is a good idea to close a stream in the main "UI" thread let me know what you think
There was problem that without the timeout the stream was closed to early and the sent packet was not delivered to Jablotron.
@kukulich and what do you think about doing a sleep in the current thread - we are not on the "UI" thread so we can sleep and close, instead of running the close later on the "UI" thread.
like so:
stream = self._open_write_stream()
stream.write(packet)
time.sleep(1)
stream.close()
I think this version was used earlier but HA started to report it as problematic codde.
I think this version was used earlier but HA started to report it as problematic codde.
ok, I will try to update it on my side and test it to see if there are issues. I could see this being a problem only if this was run on the "UI" thread
@kukulich OK, so I know what was the problem. the _send_packet_by_stream
is called both on the main thread as well as on the worker threads.
it is okay to do sleep and close it on the current thread if we are not on a main thread.
let me know what you think. I tested this and integration loads find, I tried arming/disarming as well as motion sensors and smoke detectors seem to be working and reporting fine.
@zlymeda is it possible to test just the changes that are necessary to fix the bug?
@kukulich ok done, I updated it and squash the commits. can you take another look pls?
I've tested it in my environment and it looks there's no problem so I'll merge it. Thanks.
Fixes #80
I did lots of debugging, I added more debug statements to the
reader
andwriter
functions and I discovered that the stream was never closed and that my writer was stuck at sending the authorization packet.I found a few places where we called an
async
function on a worker thread and that caused errors as theasync
function needs to be processed on a thread that owns theloop
.I also added poetry, as I find it easy to install it for local testing. Let me know if you don't want that.
Thank you