mirror of
https://github.com/esphome/esphome.git
synced 2025-01-18 20:10:55 +00:00
Fix: Incorporate unique serial number in preference's hash for multiple Sensirion sensors (#5479)
This commit is contained in:
parent
fdef6c6d46
commit
258b0fbff3
@ -1,5 +1,6 @@
|
|||||||
#include "sen5x.h"
|
#include "sen5x.h"
|
||||||
#include "esphome/core/hal.h"
|
#include "esphome/core/hal.h"
|
||||||
|
#include "esphome/core/helpers.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
|
||||||
@ -135,9 +136,12 @@ void SEN5XComponent::setup() {
|
|||||||
ESP_LOGD(TAG, "Firmware version %d", this->firmware_version_);
|
ESP_LOGD(TAG, "Firmware version %d", this->firmware_version_);
|
||||||
|
|
||||||
if (this->voc_sensor_ && this->store_baseline_) {
|
if (this->voc_sensor_ && this->store_baseline_) {
|
||||||
// Hash with compilation time
|
uint32_t combined_serial =
|
||||||
|
encode_uint24(this->serial_number_[0], this->serial_number_[1], this->serial_number_[2]);
|
||||||
|
// Hash with compilation time and serial number
|
||||||
// This ensures the baseline storage is cleared after OTA
|
// This ensures the baseline storage is cleared after OTA
|
||||||
uint32_t hash = fnv1_hash(App.get_compilation_time());
|
// Serial numbers are unique to each sensor, so mulitple sensors can be used without conflict
|
||||||
|
uint32_t hash = fnv1_hash(App.get_compilation_time() + std::to_string(combined_serial));
|
||||||
this->pref_ = global_preferences->make_preference<Sen5xBaselines>(hash, true);
|
this->pref_ = global_preferences->make_preference<Sen5xBaselines>(hash, true);
|
||||||
|
|
||||||
if (this->pref_.load(&this->voc_baselines_storage_)) {
|
if (this->pref_.load(&this->voc_baselines_storage_)) {
|
||||||
|
@ -73,9 +73,10 @@ void SGP30Component::setup() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash with compilation time
|
// Hash with compilation time and serial number
|
||||||
// This ensures the baseline storage is cleared after OTA
|
// This ensures the baseline storage is cleared after OTA
|
||||||
uint32_t hash = fnv1_hash(App.get_compilation_time());
|
// Serial numbers are unique to each sensor, so mulitple sensors can be used without conflict
|
||||||
|
uint32_t hash = fnv1_hash(App.get_compilation_time() + std::to_string(this->serial_number_));
|
||||||
this->pref_ = global_preferences->make_preference<SGP30Baselines>(hash, true);
|
this->pref_ = global_preferences->make_preference<SGP30Baselines>(hash, true);
|
||||||
|
|
||||||
if (this->pref_.load(&this->baselines_storage_)) {
|
if (this->pref_.load(&this->baselines_storage_)) {
|
||||||
|
@ -61,9 +61,10 @@ void SGP4xComponent::setup() {
|
|||||||
ESP_LOGD(TAG, "Product version: 0x%0X", uint16_t(this->featureset_ & 0x1FF));
|
ESP_LOGD(TAG, "Product version: 0x%0X", uint16_t(this->featureset_ & 0x1FF));
|
||||||
|
|
||||||
if (this->store_baseline_) {
|
if (this->store_baseline_) {
|
||||||
// Hash with compilation time
|
// Hash with compilation time and serial number
|
||||||
// This ensures the baseline storage is cleared after OTA
|
// This ensures the baseline storage is cleared after OTA
|
||||||
uint32_t hash = fnv1_hash(App.get_compilation_time());
|
// Serial numbers are unique to each sensor, so mulitple sensors can be used without conflict
|
||||||
|
uint32_t hash = fnv1_hash(App.get_compilation_time() + std::to_string(this->serial_number_));
|
||||||
this->pref_ = global_preferences->make_preference<SGP4xBaselines>(hash, true);
|
this->pref_ = global_preferences->make_preference<SGP4xBaselines>(hash, true);
|
||||||
|
|
||||||
if (this->pref_.load(&this->voc_baselines_storage_)) {
|
if (this->pref_.load(&this->voc_baselines_storage_)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user