Skip to content
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 thermocouple type, autoconversion, averaging, and has_fault to max31856 #6659

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

fhriley
Copy link
Contributor

@fhriley fhriley commented Apr 29, 2024

What does this implement/fix?

It adds thermocouple type, autoconversion, averaging, and has_fault to the max31856 sensor while maintaining backwards compatibility with polling mode if the data_ready_pin is not specified.

Types of changes

  • 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

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#3803

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx

Example entry for config.yaml:

sensor:
  - platform: max31856
    id: temperature_1
    name: "Temperature 1"
    has_fault:
      name: Temperature 1 Fault
    cs_pin: GPIO12
    data_ready_pin: GPIO13
    type: K
    samples_per_value: 16
  - platform: max31856
    id: temperature_2
    name: "Temperature 2"
    cs_pin: GPIO33
    type: T
    samples_per_value: 2

Checklist:

  • 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:

@codecov-commenter
Copy link

codecov-commenter commented Apr 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.05%. Comparing base (4d8b5ed) to head (6642660).
Report is 499 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #6659      +/-   ##
==========================================
+ Coverage   53.70%   54.05%   +0.34%     
==========================================
  Files          50       50              
  Lines        9408     9554     +146     
  Branches     1654     1687      +33     
==========================================
+ Hits         5053     5164     +111     
- Misses       4056     4066      +10     
- Partials      299      324      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fhriley fhriley force-pushed the max31856_features branch 2 times, most recently from ddc5d7f to 58bbdc7 Compare April 29, 2024 22:51
@fhriley fhriley changed the title Add thermocouple type, autoconversion, and averaging to max31856 WIP: Add thermocouple type, autoconversion, and averaging to max31856 Apr 29, 2024
@fhriley fhriley changed the title WIP: Add thermocouple type, autoconversion, and averaging to max31856 Add thermocouple type, autoconversion, and averaging to max31856 Apr 29, 2024
@fhriley fhriley force-pushed the max31856_features branch 2 times, most recently from 466231b to 541f807 Compare April 29, 2024 23:50
@fhriley fhriley changed the title Add thermocouple type, autoconversion, and averaging to max31856 WIP: Add thermocouple type, autoconversion, and averaging to max31856 Apr 30, 2024
@fhriley fhriley force-pushed the max31856_features branch 2 times, most recently from 3cf170c to e855cd8 Compare April 30, 2024 16:53
@fhriley fhriley changed the title WIP: Add thermocouple type, autoconversion, and averaging to max31856 WIP: Add thermocouple type, autoconversion, averaging, and has_fault to max31856 Apr 30, 2024
@fhriley fhriley changed the title WIP: Add thermocouple type, autoconversion, averaging, and has_fault to max31856 Add thermocouple type, autoconversion, averaging, and has_fault to max31856 Apr 30, 2024
Copy link
Member

@jesserockz jesserockz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests for the new configurations

void MAX31856Sensor::setup() {
ESP_LOGCONFIG(TAG, "Setting up MAX31856Sensor '%s'...", this->name_.c_str());
ESP_LOGVV(TAG, "Setting up MAX31856Sensor '%s'...", this->name_.c_str());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this? These should be LOGCONFIG

}
)
.extend(cv.polling_component_schema("60s"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should extend cv.COMPONENT_SCHEMA instead then

Comment on lines +73 to +76
cv.Optional(CONF_HAS_FAULT): binary_sensor.binary_sensor_schema(
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
device_class=DEVICE_CLASS_PROBLEM,
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sensors should not have binary sensors as children configuration. They should be in their own binary_sensor.py file which can link back to the parent.

Comment on lines +55 to +61
exclusive_update_interval_with_default = cv.Exclusive(
CONF_UPDATE_INTERVAL,
"mode",
exclusive_err_msg,
"update_interval will enable polling mode",
)
exclusive_update_interval_with_default.default = lambda: "60s"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still setting the default update interval to 60s. You can use regular Exclusive and a custom overall validation to add default values for this.

Then, this component should no longer inherit from PollingComponent, but set its own update interval in setup if the time is set but the pin is not.

There are other components that set their own update interval you can reference (I cannot remember them though)

@esphome
Copy link

esphome bot commented Apr 30, 2024

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@esphome esphome bot marked this pull request as draft April 30, 2024 20:17
@fhriley
Copy link
Contributor Author

fhriley commented May 2, 2024

I've already spent too much time on this, and I don't have time to go searching the codebase to figure out how to make a bunch of changes here, unfortunately. You can close this, and I'll just use it from my own repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants