@@ -57,50 +57,6 @@ static const int8_t SEN5X_INDEX_SCALE_FACTOR = 10; //
5757static const int8_t SEN5X_MIN_INDEX_VALUE = 1 * SEN5X_INDEX_SCALE_FACTOR; // must be adjusted by the scale factor
5858static const int16_t SEN5X_MAX_INDEX_VALUE = 500 * SEN5X_INDEX_SCALE_FACTOR; // must be adjusted by the scale factor
5959
60- static const char *model_to_str (Sen5xType model) {
61- switch (model) {
62- case SEN50:
63- return " SEN50" ;
64- case SEN54:
65- return " SEN54" ;
66- case SEN55:
67- return " SEN55" ;
68- case SEN60:
69- return " SEN60" ;
70- case SEN63C:
71- return " SEN63C" ;
72- case SEN65:
73- return " SEN65" ;
74- case SEN66:
75- return " SEN66" ;
76- case SEN68:
77- return " SEN68" ;
78- default :
79- return " UNKNOWN MODEL" ;
80- }
81- }
82- static const Sen5xType str_to_model (const char *product_name) {
83- if (strcmp (product_name, " SEN50" ) == 0 ) {
84- return SEN50;
85- } else if (strcmp (product_name, " SEN54" ) == 0 ) {
86- return SEN54;
87- } else if (strcmp (product_name, " SEN55" ) == 0 ) {
88- return SEN55;
89- } else if (strcmp (product_name, " SEN60" ) == 0 ) {
90- return SEN60;
91- } else if (strcmp (product_name, " SEN63C" ) == 0 ) {
92- return SEN63C;
93- } else if (strcmp (product_name, " SEN65" ) == 0 ) {
94- return SEN65;
95- } else if (strcmp (product_name, " SEN66" ) == 0 ) {
96- return SEN66;
97- } else if (strcmp (product_name, " SEN68" ) == 0 ) {
98- return SEN68;
99- } else {
100- return UNKNOWN_MODEL;
101- }
102- }
103-
10460void SEN5XComponent::setup () { this ->internal_setup_ (0 ); }
10561
10662void SEN5XComponent::internal_setup_ (uint8_t state) {
@@ -168,7 +124,7 @@ void SEN5XComponent::internal_setup_(uint8_t state) {
168124 return ;
169125 }
170126 this ->product_name_ = convert_to_string_ (string_number, 16 );
171- if (this ->product_name_ == " " ) {
127+ if (this ->product_name_ . empty () ) {
172128 // If blank the user must set the model parameter in the configuration
173129 // original PR indicated the SEN66 did not report Product Name, mine do
174130 // just in case I added the model configuration parameter so the user can specify the model
@@ -211,7 +167,7 @@ void SEN5XComponent::internal_setup_(uint8_t state) {
211167 return ;
212168 }
213169 if (this ->is_sen6x_ ()) {
214- this ->firmware_minor_ = firmware && 0xFF ;
170+ this ->firmware_minor_ = firmware & 0xFF ;
215171 this ->firmware_major_ = firmware >> 8 ;
216172 ESP_LOGD (TAG, " Firmware version %u.%u" , this ->firmware_major_ , this ->firmware_minor_ );
217173 } else {
@@ -223,8 +179,6 @@ void SEN5XComponent::internal_setup_(uint8_t state) {
223179 break ;
224180 case 6 :
225181 if (this ->voc_sensor_ && this ->store_baseline_ ) {
226- uint32_t combined_serial =
227- encode_uint24 (this ->serial_number_ [0 ], this ->serial_number_ [1 ], this ->serial_number_ [2 ]);
228182 // Hash with compilation time and serial number, this ensures the baseline storage is cleared after OTA
229183 // Serial numbers are unique to each sensor, so multiple sensors can be used without conflict
230184 uint32_t hash = fnv1_hash (App.get_compilation_time () + this ->serial_number_ );
@@ -256,7 +210,6 @@ void SEN5XComponent::internal_setup_(uint8_t state) {
256210 this ->set_timeout (20 , [this ]() { this ->internal_setup_ (7 ); });
257211 break ;
258212 case 7 :
259- bool result;
260213 if (this ->auto_cleaning_interval_ .has_value ()) {
261214 if (this ->is_sen6x_ ()) {
262215 ESP_LOGE (TAG, " Automatic Cleaning Interval is not supported" );
@@ -530,7 +483,7 @@ void SEN5XComponent::dump_config() {
530483 this ->co2_ambient_pressure_source_ ->get_name ().c_str ());
531484 } else {
532485 if (this ->co2_altitude_compensation_ .has_value ()) {
533- ESP_LOGCONFIG (TAG, " Altitude compensation: %dm" , this ->co2_altitude_compensation_ );
486+ ESP_LOGCONFIG (TAG, " Altitude compensation: %dm" , this ->co2_altitude_compensation_ . value () );
534487 }
535488 }
536489 }
@@ -574,12 +527,6 @@ void SEN5XComponent::update() {
574527 uint16_t cmd;
575528 uint8_t length;
576529 switch (this ->model_ .value ()) {
577- case SEN50:
578- case SEN54:
579- case SEN55:
580- cmd = SEN5X_CMD_READ_MEASUREMENT;
581- length = 9 ;
582- break ;
583530 case SEN60:
584531 cmd = SEN60_CMD_READ_MEASUREMENT;
585532 length = 4 ;
@@ -599,6 +546,9 @@ void SEN5XComponent::update() {
599546 case SEN68:
600547 cmd = SEN68_CMD_READ_MEASUREMENT;
601548 length = 9 ;
549+ default :
550+ cmd = SEN5X_CMD_READ_MEASUREMENT;
551+ length = 9 ;
602552 break ;
603553 }
604554
@@ -727,14 +677,13 @@ bool SEN5XComponent::start_measurements_() {
727677 cmd = CMD_START_MEASUREMENTS;
728678 }
729679 break ;
730- case SEN60:
731- cmd = SEN60_CMD_START_MEASUREMENTS;
732- break ;
733680 case SEN63C:
734681 case SEN65:
735682 case SEN66:
736683 case SEN68:
737684 cmd = CMD_START_MEASUREMENTS;
685+ default :
686+ cmd = SEN60_CMD_START_MEASUREMENTS;
738687 break ;
739688 }
740689
@@ -763,7 +712,7 @@ bool SEN5XComponent::stop_measurements_() {
763712 return result;
764713}
765714
766- std::string SEN5XComponent::convert_to_string_ (uint16_t array[], uint8_t length) {
715+ std::string SEN5XComponent::convert_to_string_ (const uint16_t array[], uint8_t length) {
767716 std::string new_string;
768717 const uint16_t *current_int = array;
769718 char current_char;
@@ -830,7 +779,7 @@ bool SEN5XComponent::set_ambient_pressure_compensation(float pressure_in_hpa) {
830779 if (new_ambient_pressure != this ->co2_ambient_pressure_ ) {
831780 update_co2_ambient_pressure_compensation_ (new_ambient_pressure);
832781 this ->co2_ambient_pressure_ = new_ambient_pressure;
833- this ->set_timeout (20 , [this ]() {});
782+ this ->set_timeout (20 , []() {});
834783 } else {
835784 ESP_LOGD (TAG, " Ambient Pressure compensation skipped - no change required" );
836785 }
@@ -853,6 +802,50 @@ bool SEN5XComponent::is_sen6x_() {
853802 return false ;
854803 }
855804}
805+ const char *SEN5XComponent::model_to_str (Sen5xType model) {
806+ switch (model) {
807+ case SEN50:
808+ return " SEN50" ;
809+ case SEN54:
810+ return " SEN54" ;
811+ case SEN55:
812+ return " SEN55" ;
813+ case SEN60:
814+ return " SEN60" ;
815+ case SEN63C:
816+ return " SEN63C" ;
817+ case SEN65:
818+ return " SEN65" ;
819+ case SEN66:
820+ return " SEN66" ;
821+ case SEN68:
822+ return " SEN68" ;
823+ default :
824+ return " UNKNOWN MODEL" ;
825+ }
826+ }
827+
828+ Sen5xType SEN5XComponent::str_to_model (const char *product_name) {
829+ if (strcmp (product_name, " SEN50" ) == 0 ) {
830+ return SEN50;
831+ } else if (strcmp (product_name, " SEN54" ) == 0 ) {
832+ return SEN54;
833+ } else if (strcmp (product_name, " SEN55" ) == 0 ) {
834+ return SEN55;
835+ } else if (strcmp (product_name, " SEN60" ) == 0 ) {
836+ return SEN60;
837+ } else if (strcmp (product_name, " SEN63C" ) == 0 ) {
838+ return SEN63C;
839+ } else if (strcmp (product_name, " SEN65" ) == 0 ) {
840+ return SEN65;
841+ } else if (strcmp (product_name, " SEN66" ) == 0 ) {
842+ return SEN66;
843+ } else if (strcmp (product_name, " SEN68" ) == 0 ) {
844+ return SEN68;
845+ } else {
846+ return UNKNOWN_MODEL;
847+ }
848+ }
856849
857850bool SEN5XComponent::start_fan_cleaning () {
858851 ESP_LOGV (TAG, " Fan Cleaning started" );
0 commit comments