Tuya: Fix init sequence and handle wifi test command (#820)

* Handle WiFi test command

Also rename commands to match Tuya protocol docs

* Fix init sequence and product info check

* Fix clang-format suggestions

* Additional changes based on code review

* Fix temp command buffer scope

* Let the interval timer fire the first heatbeat

* Fix init steps; add logging

* Lint

* Remove setup_priority override

* Add delay to dump_config

* Refactor dump sequence

* Fix verbose logging

* Fix lints

* Don't bother suppressing duplicate config dumps

* nolint


Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
Brandon Davidson
2019-11-14 04:43:44 -08:00
committed by Otto Winter
parent 531428b8b0
commit c5c42c4338
2 changed files with 80 additions and 37 deletions
+18 -6
View File
@@ -34,19 +34,29 @@ struct TuyaDatapointListener {
enum class TuyaCommandType : uint8_t {
HEARTBEAT = 0x00,
QUERY_PRODUCT = 0x01,
MCU_CONF = 0x02,
PRODUCT_QUERY = 0x01,
CONF_QUERY = 0x02,
WIFI_STATE = 0x03,
WIFI_RESET = 0x04,
WIFI_SELECT = 0x05,
SET_DATAPOINT = 0x06,
STATE = 0x07,
QUERY_STATE = 0x08,
DATAPOINT_DELIVER = 0x06,
DATAPOINT_REPORT = 0x07,
DATAPOINT_QUERY = 0x08,
WIFI_TEST = 0x0E,
};
enum class TuyaInitState : uint8_t {
INIT_HEARTBEAT = 0x00,
INIT_PRODUCT,
INIT_CONF,
INIT_WIFI,
INIT_DATAPOINT,
INIT_DONE,
};
class Tuya : public Component, public uart::UARTDevice {
public:
float get_setup_priority() const override { return setup_priority::HARDWARE; }
float get_setup_priority() const override { return setup_priority::LATE; }
void setup() override;
void loop() override;
void dump_config() override;
@@ -62,8 +72,10 @@ class Tuya : public Component, public uart::UARTDevice {
void send_command_(TuyaCommandType command, const uint8_t *buffer, uint16_t len);
void send_empty_command_(TuyaCommandType command) { this->send_command_(command, nullptr, 0); }
TuyaInitState init_state_ = TuyaInitState::INIT_HEARTBEAT;
int gpio_status_ = -1;
int gpio_reset_ = -1;
std::string product_ = "";
std::vector<TuyaDatapointListener> listeners_;
std::vector<TuyaDatapoint> datapoints_;
std::vector<uint8_t> rx_message_;