mirror of
https://github.com/esphome/esphome.git
synced 2026-09-24 05:24:14 +00:00
only implement for esp32
This commit is contained in:
committed by
Kevin Ahrendt
parent
5115aeeb2b
commit
8c6917fe8b
@@ -10,15 +10,9 @@
|
||||
#endif
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#ifdef USE_WIFI
|
||||
#ifdef USE_ESP32
|
||||
#if defined(USE_WIFI) && defined(USE_ESP32)
|
||||
#include <esp_wifi.h>
|
||||
#elif defined(USE_ESP8266)
|
||||
extern "C" {
|
||||
#include <user_interface.h>
|
||||
}
|
||||
#endif // USE_ESP32 / USE_ESP8266
|
||||
#endif // USE_WIFI
|
||||
#endif
|
||||
#endif // USE_TEXT_SENSOR
|
||||
|
||||
namespace esphome {
|
||||
@@ -92,8 +86,6 @@ class DebugComponent : public PollingComponent {
|
||||
text_sensor::TextSensor *wifi_power_save_{nullptr};
|
||||
#if defined(USE_WIFI) && defined(USE_ESP32)
|
||||
wifi_ps_type_t last_wifi_ps_mode_{};
|
||||
#elif defined(USE_WIFI) && defined(USE_ESP8266)
|
||||
sleep_type_t last_wifi_sleep_type_{};
|
||||
#endif
|
||||
#endif // USE_TEXT_SENSOR
|
||||
|
||||
|
||||
@@ -3,41 +3,11 @@
|
||||
#include "esphome/core/log.h"
|
||||
#include <Esp.h>
|
||||
|
||||
#ifdef USE_WIFI
|
||||
extern "C" {
|
||||
#include <user_interface.h>
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
namespace debug {
|
||||
|
||||
static const char *const TAG = "debug";
|
||||
|
||||
#if defined(USE_TEXT_SENSOR) && defined(USE_WIFI)
|
||||
/// @brief Helper function to convert ESP8266 WiFi sleep type to string
|
||||
/// @param sleep_type WiFi sleep type from wifi_get_sleep_type()
|
||||
/// @return const char pointer to the readable sleep type
|
||||
///
|
||||
/// Maps ESP8266 WiFi sleep types to user-friendly strings:
|
||||
/// - NONE_SLEEP_T (no sleep) -> "NONE"
|
||||
/// - LIGHT_SLEEP_T (light sleep) -> "LIGHT"
|
||||
/// - MODEM_SLEEP_T (modem sleep) -> "HIGH"
|
||||
/// - RF_CAL_SLEEP_T (RF calibration sleep) -> "UNKNOWN" (special mode, rarely used)
|
||||
static const char *wifi_sleep_type_to_string(sleep_type_t sleep_type) {
|
||||
switch (sleep_type) {
|
||||
case NONE_SLEEP_T:
|
||||
return "NONE";
|
||||
case LIGHT_SLEEP_T:
|
||||
return "LIGHT";
|
||||
case MODEM_SLEEP_T:
|
||||
return "HIGH";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
#endif // USE_TEXT_SENSOR && USE_WIFI
|
||||
|
||||
std::string DebugComponent::get_reset_reason_() {
|
||||
#if !defined(CLANG_TIDY)
|
||||
return ESP.getResetReason().c_str();
|
||||
@@ -117,17 +87,6 @@ void DebugComponent::update_platform_() {
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(USE_TEXT_SENSOR) && defined(USE_WIFI)
|
||||
if (this->wifi_power_save_ != nullptr) {
|
||||
sleep_type_t sleep_type = wifi_get_sleep_type();
|
||||
// Publish if the state has changed or if this is the first read
|
||||
if (this->last_wifi_sleep_type_ != sleep_type || !this->wifi_power_save_->has_state()) {
|
||||
this->wifi_power_save_->publish_state(wifi_sleep_type_to_string(sleep_type));
|
||||
this->last_wifi_sleep_type_ = sleep_type;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace debug
|
||||
|
||||
@@ -32,7 +32,7 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
icon=ICON_WIFI,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
cv.only_on(["esp32", "esp8266"]),
|
||||
cv.only_on(["esp32"]),
|
||||
cv.requires_component("wifi"),
|
||||
),
|
||||
}
|
||||
|
||||
@@ -1,10 +1 @@
|
||||
<<: !include common.yaml
|
||||
|
||||
wifi:
|
||||
ssid: "WIFI SSID"
|
||||
password: "WIFI PASSWORD"
|
||||
|
||||
text_sensor:
|
||||
- platform: debug
|
||||
power_save_mode:
|
||||
name: "WiFi Power Save Mode"
|
||||
|
||||
Reference in New Issue
Block a user