Created
August 26, 2021 19:18
-
-
Save Habbie/ff382fef004076c2d78b46d97baed8a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/esphome/components/pm1006/pm1006.cpp b/esphome/components/pm1006/pm1006.cpp | |
index 9bedb3cf..215ddc93 100644 | |
--- a/esphome/components/pm1006/pm1006.cpp | |
+++ b/esphome/components/pm1006/pm1006.cpp | |
@@ -7,6 +7,7 @@ namespace pm1006 { | |
static const char *const TAG = "pm1006"; | |
static const uint8_t PM1006_RESPONSE_HEADER[] = {0x16, 0x11, 0x0B}; | |
+static const uint8_t PM1006_REQUEST[] = {0x11, 0x02, 0x0B, 0x01, 0xE1}; | |
void PM1006Component::setup() { | |
// because this implementation is currently rx-only, there is nothing to setup | |
@@ -18,6 +19,11 @@ void PM1006Component::dump_config() { | |
this->check_uart_settings(9600); | |
} | |
+void PM1006Component::update() { | |
+ ESP_LOGV(TAG, "sending measurement request %d", sizeof(PM1006_REQUEST)); | |
+ this->write_array(PM1006_REQUEST, sizeof(PM1006_REQUEST)); | |
+} | |
+ | |
void PM1006Component::loop() { | |
while (this->available() != 0) { | |
this->read_byte(&this->data_[this->data_index_]); | |
diff --git a/esphome/components/pm1006/pm1006.h b/esphome/components/pm1006/pm1006.h | |
index 66f4cf03..2a558ba9 100644 | |
--- a/esphome/components/pm1006/pm1006.h | |
+++ b/esphome/components/pm1006/pm1006.h | |
@@ -7,14 +7,15 @@ | |
namespace esphome { | |
namespace pm1006 { | |
-class PM1006Component : public Component, public uart::UARTDevice { | |
+class PM1006Component : public PollingComponent, public uart::UARTDevice { | |
public: | |
- PM1006Component() = default; | |
+ PM1006Component() {} | |
void set_pm_2_5_sensor(sensor::Sensor *pm_2_5_sensor) { this->pm_2_5_sensor_ = pm_2_5_sensor; } | |
void setup() override; | |
void dump_config() override; | |
void loop() override; | |
+ void update() override; | |
float get_setup_priority() const override; | |
diff --git a/esphome/components/pm1006/sensor.py b/esphome/components/pm1006/sensor.py | |
index 8ea0e303..64663156 100644 | |
--- a/esphome/components/pm1006/sensor.py | |
+++ b/esphome/components/pm1006/sensor.py | |
@@ -4,6 +4,7 @@ from esphome.components import sensor, uart | |
from esphome.const import ( | |
CONF_ID, | |
CONF_PM_2_5, | |
+ CONF_UPDATE_INTERVAL, | |
STATE_CLASS_MEASUREMENT, | |
UNIT_MICROGRAMS_PER_CUBIC_METER, | |
ICON_BLUR, | |
@@ -28,7 +29,8 @@ CONFIG_SCHEMA = cv.All( | |
} | |
) | |
.extend(cv.COMPONENT_SCHEMA) | |
- .extend(uart.UART_DEVICE_SCHEMA), | |
+ .extend(uart.UART_DEVICE_SCHEMA) | |
+ .extend(cv.polling_component_schema("never")), | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment