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

Fix: Incorporate unique serial number in preference's hash for multiple Sensirion sensors #5479

Merged
merged 2 commits into from Oct 25, 2023

Conversation

kahrendt
Copy link
Contributor

@kahrendt kahrendt commented Oct 4, 2023

What does this implement/fix?

Currently, the sgp4x, spg30, and sen5x components store the baseline values in the preferences using a hash derived from the compilation time. If you have multiple sensors on different I2C buses, then the same baseline preference will be used for each sensor. This PR changes it so that the hash computation uses the compilation time (so the baseline still resets with any new firmware) and each sensor's unique serial number.

This PR isn't a breaking change, as the current behavior will already recompute the baseline after flashing a new firmware.

I have tested it locally with two SGP40 sensors. The sgp30 and sen5x components should also work, as the changes follow the same logic. The existing test cases already have the baseline stored (by default), so the modifications are tested at least through compilation.

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

Related issue or feature (if applicable): not applicable

Pull request in esphome-docs with documentation (if applicable): not applicable

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040

Example entry for config.yaml:

# Example config.yaml

  - platform: sgp4x
    i2c_id: multplex0channel0
    store_baseline: true
    voc:
      name: "VOC Index 0"
    compensation:
      temperature_source: temp_sensor
      humidity_source: humidity_sensor
  - platform: sgp4x
    i2c_id: multplex0channel1
    store_baseline: true
    voc:
      name: "VOC Index 1"
    compensation:
      temperature_source: temp_sensor
      humidity_source: humidity_sensor    

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:

@probot-esphome
Copy link

probot-esphome bot commented Oct 4, 2023

Hey there @martgras, mind taking a look at this pull request as it has been labeled with an integration (sen5x) you are listed as a code owner for? Thanks!
Hey there @SenexCrenshaw, @martgras, mind taking a look at this pull request as it has been labeled with an integration (sgp4x) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

esphome/components/sen5x/sen5x.cpp Outdated Show resolved Hide resolved
@jesserockz jesserockz merged commit 258b0fb into esphome:dev Oct 25, 2023
30 checks passed
@kahrendt kahrendt deleted the sensirion-unique-hash branch October 26, 2023 11:47
@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants