From b3ea9cf6fe9ca62f20dd46eae9f34d99e0ee210d Mon Sep 17 00:00:00 2001
From: NP v/d Spek <github_mail@lumensoft.nl>
Date: Fri, 26 Jul 2024 19:04:38 +0200
Subject: [PATCH] make sure only esp32 is allowed. fixing CI errors

---
 esphome/components/espnow/__init__.py | 23 +++--------------------
 esphome/components/espnow/espnow.cpp  | 10 ++++------
 esphome/components/espnow/espnow.h    | 18 +++++++-----------
 3 files changed, 14 insertions(+), 37 deletions(-)

diff --git a/esphome/components/espnow/__init__.py b/esphome/components/espnow/__init__.py
index 2bdaa8682b..81de2a0f36 100644
--- a/esphome/components/espnow/__init__.py
+++ b/esphome/components/espnow/__init__.py
@@ -1,18 +1,12 @@
 from esphome import automation
 import esphome.codegen as cg
 import esphome.config_validation as cv
-from esphome.const import (
-    CONF_DATA,
-    CONF_ID,
-    CONF_MAC_ADDRESS,
-    CONF_TRIGGER_ID,
-    CONF_WIFI,
-)
+from esphome.const import CONF_DATA, CONF_ID, CONF_MAC_ADDRESS, CONF_TRIGGER_ID
 from esphome.core import CORE
 
 CODEOWNERS = ["@LumenSoftNL", "@jesserockz"]
 
-espnow_ns = cg.esphome_ns.namespace("esp_now")
+espnow_ns = cg.esphome_ns.namespace("espnow")
 ESPNowComponent = espnow_ns.class_("ESPNowComponent", cg.Component)
 ESPNowListener = espnow_ns.class_("ESPNowListener")
 
@@ -54,17 +48,6 @@ def validate_raw_data(value):
     )
 
 
-def disallowed_component(comp):
-    """Validate that this option can only be specified when the component `comp` is not loaded."""
-
-    def validator(value):
-        if comp in CORE.loaded_integrations:
-            raise cv.Invalid(f"This component  requires component {comp}")
-        return value
-
-    return validator
-
-
 CONFIG_SCHEMA = cv.Schema(
     {
         cv.GenerateID(): cv.declare_id(ESPNowComponent),
@@ -87,7 +70,7 @@ CONFIG_SCHEMA = cv.Schema(
         ),
         cv.Optional(CONF_PEERS): cv.ensure_list(cv.mac_address),
     },
-    disallowed_component(CONF_WIFI),
+    cv.only_on_esp32,
 ).extend(cv.COMPONENT_SCHEMA)
 
 
diff --git a/esphome/components/espnow/espnow.cpp b/esphome/components/espnow/espnow.cpp
index bd3f326177..534359135b 100644
--- a/esphome/components/espnow/espnow.cpp
+++ b/esphome/components/espnow/espnow.cpp
@@ -18,9 +18,9 @@
 #include "esphome/core/log.h"
 
 namespace esphome {
-namespace esp_now {
+namespace espnow {
 
-static const char *const TAG = "esp_now";
+static const char *const TAG = "espnow";
 
 #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 1)
 typedef struct {
@@ -275,7 +275,7 @@ void ESPNowComponent::loop() {
 
 /**< callback function of receiving ESPNOW data */
 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 1)
-void ESPNowComponent::on_data_received((const esp_now_recv_info_t *recv_info, const uint8_t *data, int size)
+void ESPNowComponent::on_data_received(const esp_now_recv_info_t *recv_info, const uint8_t *data, int size)
 #else
 void ESPNowComponent::on_data_received(const uint8_t *addr, const uint8_t *data, int size)
 #endif
@@ -300,7 +300,6 @@ void ESPNowComponent::on_data_received(const uint8_t *addr, const uint8_t *data,
   package->rssi(rx_ctrl->rssi);
   package->timestamp(rx_ctrl->timestamp);
   global_esp_now->push_receive_package_(package);
-
 }
 
 void ESPNowComponent::on_data_send(const uint8_t *mac_addr, esp_now_send_status_t status) {
@@ -321,8 +320,7 @@ void ESPNowComponent::on_data_send(const uint8_t *mac_addr, esp_now_send_status_
   global_esp_now->can_send_ = true;
 }
 
-
 ESPNowComponent *global_esp_now = nullptr;
 
-}  // namespace esp_now
+}  // namespace espnow
 }  // namespace esphome
diff --git a/esphome/components/espnow/espnow.h b/esphome/components/espnow/espnow.h
index 99260e4a5b..c18a09ed0e 100644
--- a/esphome/components/espnow/espnow.h
+++ b/esphome/components/espnow/espnow.h
@@ -14,7 +14,7 @@
 #include <vector>
 
 namespace esphome {
-namespace esp_now {
+namespace espnow {
 
 typedef uint8_t espnow_addr_t[6];
 
@@ -121,7 +121,7 @@ class ESPNowComponent : public Component {
   ESPNowComponent();
 
 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 1)
-    static void on_data_received((const esp_now_recv_info_t *recv_info, const uint8_t *data, int size);
+  static void on_data_received(const esp_now_recv_info_t *recv_info, const uint8_t *data, int size);
 #else
   static void on_data_received(const uint8_t *addr, const uint8_t *data, int size);
 #endif
@@ -129,14 +129,12 @@ class ESPNowComponent : public Component {
   static void on_data_send(const uint8_t *mac_addr, esp_now_send_status_t status);
 
   void dump_config() override;
-  float get_setup_priority() const override {
-    return -100; }
+  float get_setup_priority() const override { return -100; }
 
   void setup() override;
 
   void loop() override;
-  void set_wifi_channel(uint8_t channel) {
-    this->wifi_channel_ = channel; }
+  void set_wifi_channel(uint8_t channel) { this->wifi_channel_ = channel; }
 
   ESPNowPackage *send_package(const uint64_t mac_address, const uint8_t *data, int len) {
     auto package = new ESPNowPackage(mac_address, data, len);
@@ -170,8 +168,7 @@ class ESPNowComponent : public Component {
   esp_err_t add_peer(uint64_t addr);
   esp_err_t del_peer(uint64_t addr);
 
-  void set_auto_add_peer(bool value) {
-    this->auto_add_peer_ = value; }
+  void set_auto_add_peer(bool value) { this->auto_add_peer_ = value; }
 
   void on_package_received(ESPNowPackage *package);
   void on_package_send(ESPNowPackage *package);
@@ -181,8 +178,7 @@ class ESPNowComponent : public Component {
 
  protected:
   void unHold_send_(uint64_t mac);
-  void push_receive_package_(ESPNowPackage *package) {
-    this->receive_queue_.push(std::move(package)); }
+  void push_receive_package_(ESPNowPackage *package) { this->receive_queue_.push(std::move(package)); }
   bool validate_channel_(uint8_t channel);
   uint8_t wifi_channel_{0};
   bool auto_add_peer_{false};
@@ -279,7 +275,7 @@ class ESPNowNewPeerTrigger : public Trigger<ESPNowPackage *> {
 
 extern ESPNowComponent *global_esp_now;
 
-}  // namespace esp_now
+}  // namespace espnow
 }  // namespace esphome
 
 // #endif