-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New feature: custom_i2c component #6241
base: dev
Are you sure you want to change the base?
Conversation
Hey there @javawizard, CODEOWNERS = ["@javawizard"] And run (message by NeedsCodeownersLabel) |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #6241 +/- ##
==========================================
- Coverage 53.70% 53.46% -0.25%
==========================================
Files 50 50
Lines 9408 9545 +137
Branches 1654 1685 +31
==========================================
+ Hits 5053 5103 +50
- Misses 4056 4131 +75
- Partials 299 311 +12 ☔ View full report in Codecov by Sentry. |
443aea1
to
aec3d8c
Compare
50bbee7
to
a2de556
Compare
These seem to be working fine for me. Is this still relevant and/or is it that it applies on other (non-ESP32) platforms? These classes are templated out the wazoo so moving the |
09780d1
to
778e2a7
Compare
Looking at the code (in the absence of docs) it seems to me there are two different concepts conflated here - a generic I2C driver component, and a generic I/O expander component. Might it be better to split the I/O expander stuff out to a separate component? It could still use the generic I2C stuff as a base. |
Also it looks like you've added some (useful) comments in core code - that would be best as a separate PR, which would likely be very quickly merged without waiting for a full review of your component. |
cf21862
to
f66056a
Compare
f66056a
to
c4a0478
Compare
Also temporarily add verbose log statements in all of the on_setup methods; see the code comment for why.
(specifically fix the case where outputs are not used; we need to not write C++ code that depends on output things in that case)
c4a0478
to
419baf4
Compare
Core comments extracted to #6643 (cc @clydebarrow). |
This reverts commit 7354806. -- I'm going to keep this in the commit history but nix it from the initial custom_i2c PR.
So I started implementing a custom I2C component (see this discord message and this discord thread for the humble beginnings) and I wanted to throw up a draft PR with what I have so far. This is still a work-in-progress - there's plenty of stuff left to do before it's ready for review, but I want to start a discussion and gather thoughts/feedback/requests in the mean time.
What is it?
This is a custom I2C component: it allows one to talk to I2C devices that don't have an ESPHome component written for them yet.
It's easy to use: talking to a SparkFun Qwiic Relay, for example, is as simple as:
Why
It turns out there's a pretty steep learning curve involved in learning to write ESPHome components from scratch - you have to know Python and C++, you have to learn ESPHome's codegen API (what the heck is a
Pvariable
?), schema validation, etc., etc., and then you have to write all the C++ stuff to do the actual thing you want your component to do.That's all perfectly doable, but it's a bit daunting when all you want to do is "hey, there's this switch, when it turns on please write this value to this register, when it turns off please write this value to this other register, also you can poll this third register to get its current state and it's on if that register's value is 1" (a la https://www.sparkfun.com/products/15093).
The
custom_i2c
component intends to address that. My goal is to have it be possible to talk to any I2C device and both simple and easy to talk to ~80% of I2C devices. Having it be way easier/simpler/quicker to write I2C component support usingcustom_i2c
than it is to write a dedicated component is explicitly a design goal of thecustom_i2c
component.Goals
custom_i2c
component fully supports that.)Non-goals
custom_i2c
component to allow you talk to them if you're willing to write piles upon piles of lambdas to do the heavy lifting, but it's not a goal for it to bend over backward to do the heavy lifting for you if it would be just as much work to write a dedicated ESPHome component to do it.Possible future goals
custom_i2c
component does its job right, it's only a small logical leap from teachingcustom_i2c
how to talk to your devices to sharing those configurations with others. In particular, ifcustom_i2c
turns out as good as I hope it will, I think it would be interesting to explore the idea of allowing core ESPHome support for new I2C devices to be written ascustom_i2c
configs, which would lower the barrier to official support being added for new I2C devices. It's still far too early to tell whether that's a tenable goal, however; a more manageable short term goal would be to allow hosting of, and importing, device configs from e.g. Git/GitHub repos.Current status
It works! It compiles and runs and everything, and I have it controlling a Adafruit LED arcade button board and a SparkFun single relay board and a SparkFun quad relay board and everything's working flawlessly.
Now comes the fun part. I want to:
And then 🎉 🎉 🎉
How can I try it out?
Easy: drop this in your config file:
Then add a
custom_i2c:
config block and go to town. (More documentation on how exactly to write acustom_i2c
config coming soon)Feedback welcome!
So that's it. If you have any thoughts, requests etc., please leave a comment!
Things left to do
custom_i2c.h
and__init__.py
into multiple files (probably)dump_config
methodsCustomI2CPinBank
's registers into separate components (there's a code comment on the what and why)