Support high update rates and fix several bugs in the cse7766 component.
What does this implement/fix?
This adds support for updating the frontend with measurements as fast as the cse7766 can supply them. It also more closely adheres to the flowchart specified in the user manual.
The following are fixed:
-
When a bad message arrives and the loop starts searching for a message header, the loop would start at index 1 rather than 0.
-
If a value was not measured, it was output as a zero, which does not represent reality and could mess up filters and statistics.
-
If the esphome device is booted with nothing pulling power, i.e. no power measurement is available, energy would show in HA as nan.
-
Double precision was used in the energy total computation.
I did testing with several Sonoff S31 plugs with the following connected: washer, refrigerator, box fan, dehydrator and server.
Before voltage (update_interval = 1ms):
After voltage (update_interval = 1ms):
Types of changes
- [x] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Other
Related issue or feature (if applicable): Fixes https://github.com/esphome/issues/issues/3468.
Test Environment
- [ ] ESP32
- [ ] ESP32 IDF
- [x] ESP8266
Checklist:
- [x] The code change is tested and works locally.
- [ ] Tests have been added to verify that the new code works (under
tests/folder).
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated in esphome-docs.