فهرست منبع

Drop support for ESPHome versions before 2021.10

Oxan van Leeuwen 4 سال پیش
والد
کامیت
c6af03f750
3فایلهای تغییر یافته به همراه3 افزوده شده و 35 حذف شده
  1. 1 1
      components/stream_server/__init__.py
  2. 0 19
      components/stream_server/stream_server.cpp
  3. 2 15
      components/stream_server/stream_server.h

+ 1 - 1
components/stream_server/__init__.py

@@ -20,7 +20,7 @@ from esphome.const import CONF_ID, CONF_PORT
 
 # ESPHome doesn't know the Stream abstraction yet, so hardcode to use a UART for now.
 
-AUTO_LOAD = ["async_tcp"]
+AUTO_LOAD = ["socket"]
 
 DEPENDENCIES = ["uart", "network"]
 

+ 0 - 19
components/stream_server/stream_server.cpp

@@ -19,10 +19,7 @@
 #include "esphome/core/log.h"
 #include "esphome/core/util.h"
 
-#if ESPHOME_VERSION_CODE >= VERSION_CODE(2021, 10, 0)
 #include "esphome/components/network/util.h"
-#endif
-
 
 static const char *TAG = "streamserver";
 
@@ -62,37 +59,21 @@ void StreamServerComponent::read() {
     while ((len = this->stream_->available()) > 0) {
         char buf[128];
         len = std::min(len, 128);
-#if ESPHOME_VERSION_CODE >= VERSION_CODE(2021, 10, 0)
         this->stream_->read_array(reinterpret_cast<uint8_t*>(buf), len);
-#else
-        this->stream_->readBytes(buf, len);
-#endif
         for (auto const& client : this->clients_)
             client->tcp_client->write(buf, len);
     }
 }
 
 void StreamServerComponent::write() {
-#if ESPHOME_VERSION_CODE >= VERSION_CODE(2021, 10, 0)
     this->stream_->write_array(this->recv_buf_);
     this->recv_buf_.clear();
-#else
-    size_t len;
-    while ((len = this->recv_buf_.size()) > 0) {
-        this->stream_->write(this->recv_buf_.data(), len);
-        this->recv_buf_.erase(this->recv_buf_.begin(), this->recv_buf_.begin() + len);
-    }
-#endif
 }
 
 void StreamServerComponent::dump_config() {
     ESP_LOGCONFIG(TAG, "Stream Server:");
     ESP_LOGCONFIG(TAG, "  Address: %s:%u",
-#if ESPHOME_VERSION_CODE >= VERSION_CODE(2021, 10, 0)
                   esphome::network::get_ip_address().str().c_str(),
-#else
-                  network_get_address().c_str(),
-#endif
                   this->port_);
 }
 

+ 2 - 15
components/stream_server/stream_server.h

@@ -16,19 +16,12 @@
 
 #pragma once
 
-#include "esphome/core/version.h"
 #include "esphome/core/component.h"
 #include "esphome/components/uart/uart.h"
 
-// Provide VERSION_CODE for ESPHome versions lacking it, as existence checking doesn't work for function-like macros
-#ifndef VERSION_CODE
-#define VERSION_CODE(major, minor, patch) ((major) << 16 | (minor) << 8 | (patch))
-#endif
-
 #include <memory>
 #include <string>
 #include <vector>
-#include <Stream.h>
 
 #ifdef ARDUINO_ARCH_ESP8266
 #include <ESPAsyncTCP.h>
@@ -38,16 +31,10 @@
 #include <AsyncTCP.h>
 #endif
 
-#if ESPHOME_VERSION_CODE >= VERSION_CODE(2021, 10, 0)
-using SSStream = esphome::uart::UARTComponent;
-#else
-using SSStream = Stream;
-#endif
-
 class StreamServerComponent : public esphome::Component {
 public:
     StreamServerComponent() = default;
-    explicit StreamServerComponent(SSStream *stream) : stream_{stream} {}
+    explicit StreamServerComponent(esphome::uart::UARTComponent *stream) : stream_{stream} {}
     void set_uart_parent(esphome::uart::UARTComponent *parent) { this->stream_ = parent; }
 
     void setup() override;
@@ -73,7 +60,7 @@ protected:
         bool disconnected{false};
     };
 
-    SSStream *stream_{nullptr};
+    esphome::uart::UARTComponent *stream_{nullptr};
     AsyncServer server_{0};
     uint16_t port_{6638};
     std::vector<uint8_t> recv_buf_{};