OnFreund / pyrisco

MIT License
9 stars 9 forks source link

Local communication support #5

Closed OnFreund closed 2 years ago

OnFreund commented 2 years ago

Inspired by https://github.com/vanackej/risco-lan-bridge, local support in Python will enable a native HA integration without reliance on Risco cloud on the one hand, or external components (e.g. mqtt) on the others.

I started to implement it in the local_comm branch. The encoding and encryption / decoding and decryption part is already implemented, and confirmed agains the test cases in https://github.com/vanackej/risco-lan-bridge/blob/main/test/crypto.test.ts Next up is the socket part. I'll only be implementing the direct mode, since there's no easy way to run a proxy from within HA, and the proxy doesn't have to be tied to the library - it probably makes more sense to implement it as an external component and point the library at it.

@vanackej would love your support on this if possible.

vanackej commented 2 years ago

Ok so you consider a full port of the library in python ? Good news ! I agree that proxy mode is a pain to maintain. I only kept it because the original creator of the library started implementing it, but it's really complex to maintain and has a lot of edge cases. The socket communication layer is not really simple to implement by itself, because of the encyption issues, unexpected data buffer that are sometime sent by the panel, socket disconnection when inactivity, duplicated response received, switching from unencrypted communication to enrypted communication, device discovery part, ... I really encourage you to port the typescript library as close as possible to my code, as I spent a lot of time making it work correctly.

I'll be happy to help you if you have any question, just let me know.

OnFreund commented 2 years ago

I'm definitely seeing some of the finer points come up, but I already have the encryption working, and initial socket implementation working as well - I'm able to send commands and get responses. I deviated quite a lot from the typescript library, because I'm giving up on a lot of features so I'm able so simplify:

  1. No proxy - like I said, it could be external
  2. No code or panel id discovery. If someone is looking to brute force the system, they can write their own script
  3. No enabling/disabling of cloud. Once again, I think this can be done outside the library. If I understand correctly, that also means I don't have to support programming commands.

I was having a hard time with the random clock commands I'm getting (took me a while to realize those weren't responses to my commands - I kept thinking I was doing something wrong), or with commands that included \x10\x03 in the middle, but I got over those. Would love to find time we can maybe go over it together?