Skip to content

Commit

Permalink
Merge branch 'fix/wg/headers' into feature/wireguard_component
Browse files Browse the repository at this point in the history
* fix headers not found if either binary_sensor or sensor are not loaded
  • Loading branch information
droscy committed Jun 25, 2023
2 parents 7fe4ee3 + 306f245 commit 2b4f2be
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions esphome/components/wireguard/wireguard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,20 @@ void Wireguard::update() {
}
}

#ifdef USE_BINARY_SENSOR
if (this->status_sensor_ != nullptr) {
this->status_sensor_->publish_state(peer_up);
}
#endif

#ifdef USE_SENSOR
if (this->handshake_sensor_ != nullptr) {
if (lhs > this->latest_saved_handshake_) {
this->latest_saved_handshake_ = lhs;
this->handshake_sensor_->publish_state((float) lhs);
}
}
#endif
}

void Wireguard::dump_config() {
Expand Down Expand Up @@ -164,8 +168,14 @@ void Wireguard::add_allowed_ip(const std::string &ip, const std::string &netmask
void Wireguard::set_keepalive(const uint16_t seconds) { this->keepalive_ = seconds; }
void Wireguard::set_reboot_timeout(const uint32_t seconds) { this->reboot_timeout_ = seconds; }
void Wireguard::set_srctime(time::RealTimeClock *srctime) { this->srctime_ = srctime; }

#ifdef USE_BINARY_SENSOR
void Wireguard::set_status_sensor(binary_sensor::BinarySensor *sensor) { this->status_sensor_ = sensor; }
#endif

#ifdef USE_SENSOR
void Wireguard::set_handshake_sensor(sensor::Sensor *sensor) { this->handshake_sensor_ = sensor; }
#endif

void Wireguard::disable_auto_proceed() { this->proceed_allowed_ = false; }

Expand Down
18 changes: 18 additions & 0 deletions esphome/components/wireguard/wireguard.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@

#include "esphome/core/component.h"
#include "esphome/components/time/real_time_clock.h"

#ifdef USE_BINARY_SENSOR
#include "esphome/components/binary_sensor/binary_sensor.h"
#endif

#ifdef USE_SENSOR
#include "esphome/components/sensor/sensor.h"
#endif

#include <esp_wireguard.h>

Expand Down Expand Up @@ -39,8 +45,14 @@ class Wireguard : public PollingComponent {
void set_keepalive(uint16_t seconds);
void set_reboot_timeout(uint32_t seconds);
void set_srctime(time::RealTimeClock *srctime);

#ifdef USE_BINARY_SENSOR
void set_status_sensor(binary_sensor::BinarySensor *sensor);
#endif

#ifdef USE_SENSOR
void set_handshake_sensor(sensor::Sensor *sensor);
#endif

/// Block the setup step until peer is connected.
void disable_auto_proceed();
Expand All @@ -63,8 +75,14 @@ class Wireguard : public PollingComponent {
uint32_t reboot_timeout_;

time::RealTimeClock *srctime_;

#ifdef USE_BINARY_SENSOR
binary_sensor::BinarySensor *status_sensor_ = nullptr;
#endif

#ifdef USE_SENSOR
sensor::Sensor *handshake_sensor_ = nullptr;
#endif

/// Set to false to block the setup step until peer is connected.
bool proceed_allowed_ = true;
Expand Down

0 comments on commit 2b4f2be

Please sign in to comment.