pmsx003: add support for PMS5003S device (#2710)

This commit is contained in:
NeoAcheron 2021-11-13 15:14:23 +01:00 committed by GitHub
parent 2e0c89409d
commit 582567696e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 8 deletions

View File

@ -96,6 +96,7 @@ optional<bool> PMSX003Component::check_byte_() {
length_matches = payload_length == 28 || payload_length == 20; length_matches = payload_length == 28 || payload_length == 20;
break; break;
case PMSX003_TYPE_5003T: case PMSX003_TYPE_5003T:
case PMSX003_TYPE_5003S:
length_matches = payload_length == 28; length_matches = payload_length == 28;
break; break;
case PMSX003_TYPE_5003ST: case PMSX003_TYPE_5003ST:
@ -133,20 +134,25 @@ optional<bool> PMSX003Component::check_byte_() {
void PMSX003Component::parse_data_() { void PMSX003Component::parse_data_() {
switch (this->type_) { switch (this->type_) {
case PMSX003_TYPE_5003ST: { case PMSX003_TYPE_5003ST: {
uint16_t formaldehyde = this->get_16_bit_uint_(28);
float temperature = this->get_16_bit_uint_(30) / 10.0f; float temperature = this->get_16_bit_uint_(30) / 10.0f;
float humidity = this->get_16_bit_uint_(32) / 10.0f; float humidity = this->get_16_bit_uint_(32) / 10.0f;
ESP_LOGD(TAG, "Got Temperature: %.1f°C, Humidity: %.1f%% Formaldehyde: %u µg/m^3", temperature, humidity, ESP_LOGD(TAG, "Got Temperature: %.1f°C, Humidity: %.1f%%", temperature, humidity);
formaldehyde);
if (this->temperature_sensor_ != nullptr) if (this->temperature_sensor_ != nullptr)
this->temperature_sensor_->publish_state(temperature); this->temperature_sensor_->publish_state(temperature);
if (this->humidity_sensor_ != nullptr) if (this->humidity_sensor_ != nullptr)
this->humidity_sensor_->publish_state(humidity); this->humidity_sensor_->publish_state(humidity);
// The rest of the PMS5003ST matches the PMS5003S, continue on
}
case PMSX003_TYPE_5003S: {
uint16_t formaldehyde = this->get_16_bit_uint_(28);
ESP_LOGD(TAG, "Got Formaldehyde: %u µg/m^3", formaldehyde);
if (this->formaldehyde_sensor_ != nullptr) if (this->formaldehyde_sensor_ != nullptr)
this->formaldehyde_sensor_->publish_state(formaldehyde); this->formaldehyde_sensor_->publish_state(formaldehyde);
// The rest of the PMS5003ST matches the PMS5003, continue on // The rest of the PMS5003S matches the PMS5003, continue on
} }
case PMSX003_TYPE_X003: { case PMSX003_TYPE_X003: {
uint16_t pm_1_0_std_concentration = this->get_16_bit_uint_(4); uint16_t pm_1_0_std_concentration = this->get_16_bit_uint_(4);

View File

@ -11,6 +11,7 @@ enum PMSX003Type {
PMSX003_TYPE_X003 = 0, PMSX003_TYPE_X003 = 0,
PMSX003_TYPE_5003T, PMSX003_TYPE_5003T,
PMSX003_TYPE_5003ST, PMSX003_TYPE_5003ST,
PMSX003_TYPE_5003S,
}; };
class PMSX003Component : public uart::UARTDevice, public Component { class PMSX003Component : public uart::UARTDevice, public Component {

View File

@ -42,21 +42,23 @@ PMSX003Sensor = pmsx003_ns.class_("PMSX003Sensor", sensor.Sensor)
TYPE_PMSX003 = "PMSX003" TYPE_PMSX003 = "PMSX003"
TYPE_PMS5003T = "PMS5003T" TYPE_PMS5003T = "PMS5003T"
TYPE_PMS5003ST = "PMS5003ST" TYPE_PMS5003ST = "PMS5003ST"
TYPE_PMS5003S = "PMS5003S"
PMSX003Type = pmsx003_ns.enum("PMSX003Type") PMSX003Type = pmsx003_ns.enum("PMSX003Type")
PMSX003_TYPES = { PMSX003_TYPES = {
TYPE_PMSX003: PMSX003Type.PMSX003_TYPE_X003, TYPE_PMSX003: PMSX003Type.PMSX003_TYPE_X003,
TYPE_PMS5003T: PMSX003Type.PMSX003_TYPE_5003T, TYPE_PMS5003T: PMSX003Type.PMSX003_TYPE_5003T,
TYPE_PMS5003ST: PMSX003Type.PMSX003_TYPE_5003ST, TYPE_PMS5003ST: PMSX003Type.PMSX003_TYPE_5003ST,
TYPE_PMS5003S: PMSX003Type.PMSX003_TYPE_5003S,
} }
SENSORS_TO_TYPE = { SENSORS_TO_TYPE = {
CONF_PM_1_0: [TYPE_PMSX003, TYPE_PMS5003ST], CONF_PM_1_0: [TYPE_PMSX003, TYPE_PMS5003ST, TYPE_PMS5003S],
CONF_PM_2_5: [TYPE_PMSX003, TYPE_PMS5003T, TYPE_PMS5003ST], CONF_PM_2_5: [TYPE_PMSX003, TYPE_PMS5003T, TYPE_PMS5003ST, TYPE_PMS5003S],
CONF_PM_10_0: [TYPE_PMSX003, TYPE_PMS5003ST], CONF_PM_10_0: [TYPE_PMSX003, TYPE_PMS5003ST, TYPE_PMS5003S],
CONF_TEMPERATURE: [TYPE_PMS5003T, TYPE_PMS5003ST], CONF_TEMPERATURE: [TYPE_PMS5003T, TYPE_PMS5003ST],
CONF_HUMIDITY: [TYPE_PMS5003T, TYPE_PMS5003ST], CONF_HUMIDITY: [TYPE_PMS5003T, TYPE_PMS5003ST],
CONF_FORMALDEHYDE: [TYPE_PMS5003ST], CONF_FORMALDEHYDE: [TYPE_PMS5003ST, TYPE_PMS5003S],
} }