esphome-daikin-s21 icon indicating copy to clipboard operation
esphome-daikin-s21 copied to clipboard

Add serial command state machine to prevent blocking esphome main loop

Open asund opened this issue 8 months ago • 11 comments

  • setup() initializes a pool of commands/queries to be periodically run
  • loop() transmits each command/query and waits for the response, yielding control if it's not ready
  • Changes to settings must be staged and applied asynchronously
  • All of this requires much more saved state in the DaikinS21 object

Other changes:

  • Add ETX -> ENQ checksum character escaping
  • Lower minimum setpoint (for my basement)
  • Replace some std::vector use with const strings or sized local buffers (embedded habits die hard)
  • Add support for reading out quiet fan mode from RG query

asund avatar Mar 16 '25 23:03 asund

This is a request for comments pull request.

I noticed when doing a lot of communication the component will block for longer than esphome likes. Do it too much and basic functionality stops working. So here's a communications state machine that allows loop() to yield and resume the queries if there's nothing to do. Unfortunately, that means quite a few changes so Github's diff isn't that helpful.

I can post a bunch of comments explaining what's going on if you like the basic idea

asund avatar Mar 16 '25 23:03 asund

This also fixes #31

benwa avatar Mar 18 '25 12:03 benwa

I am midway through abstracting the serial state machine from the command processing to make it less messy and easier to follow. Will update the PR when that's done.

asund avatar Mar 26 '25 17:03 asund

Hey @asund, do you think this is ready to be reviewed and merged?

benwa avatar May 29 '25 12:05 benwa

Hey @asund, do you think this is ready to be reviewed and merged?

Sure. My biggest concern with this one is dumping a bunch of drastic changes on the project and forcing others to read and understand them. Please let me know if I've overstepped by changing anything too much or making unnecessary changes that could be their own pull requests with discussion (lowering the minimum temperature, etc).

Questions:

  • How do people like the enum+bitset use instead of a bunch of bools? Can easily switch to bools.
  • Are we ok with a single NAK removing a query from the pool? I can add a three strikes rule or something else if it's considered risky.
  • Is the iterator use with the query pool cumbersome? Should I just use an index?

asund avatar May 29 '25 14:05 asund

At a glance, this all looks compelling. I lack the time at this point to give this a good review, and I'm currently not setup to test even relatively simple PRs. Your interest and time investment suggest to me that you should fork and grow this beyond what it currently is, because I don't have the time to put into taking care of it right now. I'll happily add a forwarding link to the README if you (or someone else?) take over.

joshbenner avatar May 30 '25 11:05 joshbenner

Thanks, I have a bit of free time now and then and can probably pitch in in a larger capacity. I am a C++ developer and don't know the ESPhome side very well. @benwa you seem pretty active, would you be interested in helping out with a fork? Is there a way to have a project with a couple admins?

asund avatar Jun 06 '25 03:06 asund

I'm by no means a developer (a sysadmin by trade), but I'm happy to assist however I can.

GitHub does allow for different levels of permissions.

benwa avatar Jun 06 '25 10:06 benwa

At a glance, this all looks compelling. I lack the time at this point to give this a good review, and I'm currently not setup to test even relatively simple PRs. Your interest and time investment suggest to me that you should fork and grow this beyond what it currently is, because I don't have the time to put into taking care of it right now. I'll happily add a forwarding link to the README if you (or someone else?) take over.

@asund has put in a whole lot of effort on their fork. Do you think you can add the notice to point to https://github.com/asund/esphome-daikin-s21?

benwa avatar Jul 07 '25 17:07 benwa

I do need to re-add support for the basic commands my unit doesn't support before I can say it's not a regression for some users, but I'm hoping to do that soon.

asund avatar Jul 07 '25 17:07 asund

I've added a link with a suggestion to consider asund's fork.

joshbenner avatar Jul 07 '25 17:07 joshbenner