-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Add mpu6050 interrupt support #6827
base: dev
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #6827 +/- ##
==========================================
+ Coverage 53.70% 53.88% +0.17%
==========================================
Files 50 50
Lines 9408 9619 +211
Branches 1654 1698 +44
==========================================
+ Hits 5053 5183 +130
- Misses 4056 4112 +56
- Partials 299 324 +25 ☔ View full report in Codecov by Sentry. |
@@ -12,8 +12,7 @@ | |||
UNIT_DEGREE_PER_SECOND, | |||
UNIT_CELSIUS, | |||
) | |||
|
|||
DEPENDENCIES = ["i2c"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
THis should change to DEPENDENCIES = ["mpu6050"]
now that it has a dependency on a parent component.
CONFIG_SCHEMA = cv.Schema( | ||
{ | ||
cv.GenerateID(): cv.declare_id(MPU6050Sensor), | ||
cv.Required(CONF_MPU6050_ID): cv.use_id(MPU6050Component), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will automatically get the id if there is only 1 parent in config
cv.Required(CONF_MPU6050_ID): cv.use_id(MPU6050Component), | |
cv.GenerateID(CONF_MPU6050_ID): cv.use_id(MPU6050Component), |
CONFIG_SCHEMA = cv.Schema( | ||
{ | ||
cv.GenerateID(): cv.declare_id(MPU6050Component), | ||
cv.Optional(CONF_INTERRUPT, default=False): validate_interrupt, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cv.Optional(CONF_INTERRUPT, default=False): validate_interrupt, | |
cv.Optional(CONF_INTERRUPT): validate_interrupt, |
def validate_interrupt(value): | ||
schema = None | ||
if isinstance(value, bool): | ||
if value: | ||
schema = {CONF_THRESHOLD: 1, CONF_DURATION: cv.positive_time_period("1ms")} | ||
|
||
else: | ||
schema = cv.Schema( | ||
{ | ||
cv.Required(CONF_THRESHOLD): cv.positive_not_null_int, | ||
cv.Required(CONF_DURATION): cv.positive_time_period, | ||
} | ||
)(value) | ||
return schema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def validate_interrupt(value): | |
schema = None | |
if isinstance(value, bool): | |
if value: | |
schema = {CONF_THRESHOLD: 1, CONF_DURATION: cv.positive_time_period("1ms")} | |
else: | |
schema = cv.Schema( | |
{ | |
cv.Required(CONF_THRESHOLD): cv.positive_not_null_int, | |
cv.Required(CONF_DURATION): cv.positive_time_period, | |
} | |
)(value) | |
return schema | |
INTERRUPT_SCHEMA = cv.Schema( | |
{ | |
cv.Required(CONF_THRESHOLD): cv.positive_not_null_int, | |
cv.Required(CONF_DURATION): cv.positive_time_period, | |
} | |
) | |
def validate_interrupt(value): | |
if isinstance(value, bool): | |
if value: | |
return INTERRUPT_SCHEMA({ | |
CONF_THRESHOLD: 1, | |
CONF_DURATION: cv.positive_time_period("1ms") | |
}) | |
else: | |
return value | |
return INTERRUPT_SCHEMA(value) |
|
||
if conf_interrupt := config[CONF_INTERRUPT]: | ||
if conf_interrupt: | ||
cg.add_define("USE_MPU6050_INTERRUPT") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We dont use defines for things like this.
cg.add_define("USE_MPU6050_INTERRUPT") |
if conf_interrupt := config[CONF_INTERRUPT]: | ||
if conf_interrupt: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A falsey value will return false in the below statement already
if conf_interrupt := config[CONF_INTERRUPT]: | |
if conf_interrupt: | |
if conf_interrupt := config[CONF_INTERRUPT]: |
this->mark_failed(); | ||
return; | ||
// return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
What does this implement/fix?
This PR implements interrupt support for the MPU6050 accelerometer, allowing the 'INT' pin to be used, for example, to wake up the device upon detected motion.
This is a breaking change, as the original MPU6050 component only handled platform sensors. The code has been refactored to split the component into a base component and a platform sensor.
Here is a summary of the changes:
mpu6050/
tompu6050/sensor/
this->parent_
)__init__.py
Types of changes
Related issue or feature (if applicable): fixes
Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#3882
Test Environment
Example entry for
config.yaml
:Checklist:
tests/
folder).If user exposed functionality or configuration variables are added/changed: