5#include <initializer_list>
12#ifdef USE_BINARY_SENSOR
24#include <esp_wireguard.h>
37 void setup()
override;
64 void set_allowed_ips(std::initializer_list<std::tuple<std::string, std::string>> ips) =
delete;
70#ifdef USE_BINARY_SENSOR
117#ifdef USE_BINARY_SENSOR
126#ifdef USE_TEXT_SENSOR
136 wireguard_config_t
wg_config_ = ESP_WIREGUARD_CONFIG_DEFAULT();
137 wireguard_ctx_t
wg_ctx_ = ESP_WIREGUARD_CONTEXT_DEFAULT();
162static constexpr size_t MASK_KEY_BUFFER_SIZE = 12;
Base class for all automation conditions.
Fixed-capacity vector - allocates once at runtime, never reallocates This avoids std::vector template...
Helper class to easily give an object a parent of type T.
This class simplifies creating components that periodically check a state.
Base class for all binary_sensor-type classes.
Base-class for all sensors.
The RealTimeClock class exposes common timekeeping functions via the device's local real-time clock.
Action to disable Wireguard component.
void play(const Ts &...x) override
Action to enable Wireguard component.
void play(const Ts &...x) override
Condition to check if Wireguard component is enabled.
bool check(const Ts &...x) override
Main Wireguard component class.
binary_sensor::BinarySensor * enabled_sensor_
void set_netmask(const char *netmask)
FixedVector< AllowedIP > allowed_ips_
void set_keepalive(uint16_t seconds)
bool enabled_
When false the wireguard link will not be established.
void set_allowed_ips(std::initializer_list< AllowedIP > ips)
binary_sensor::BinarySensor * status_sensor_
float get_setup_priority() const override
void set_status_sensor(binary_sensor::BinarySensor *sensor)
void set_srctime(time::RealTimeClock *srctime)
void publish_enabled_state()
Publish the enabled state if the enabled binary sensor is configured.
time_t get_latest_handshake() const
void on_shutdown() override
sensor::Sensor * handshake_sensor_
time::RealTimeClock * srctime_
void set_preshared_key(const char *key)
bool proceed_allowed_
Set to false to block the setup step until peer is connected.
void set_peer_endpoint(const std::string &endpoint)=delete
void dump_config() override
void set_allowed_ips(std::initializer_list< std::tuple< std::string, std::string > > ips)=delete
Prevent accidental use of std::string which would dangle.
void set_peer_public_key(const std::string &key)=delete
const char * private_key_
void set_reboot_timeout(uint32_t seconds)
void disable_auto_proceed()
Block the setup step until peer is connected.
bool can_proceed() override
void set_private_key(const char *key)
void set_address_sensor(text_sensor::TextSensor *sensor)
text_sensor::TextSensor * address_sensor_
uint32_t wg_peer_offline_time_
The last time the remote peer become offline.
void set_address(const char *address)
void disable()
Stop any running connection and disable the WireGuard component.
void set_enabled_sensor(binary_sensor::BinarySensor *sensor)
void set_address(const std::string &address)=delete
Prevent accidental use of std::string which would dangle.
void set_handshake_sensor(sensor::Sensor *sensor)
esp_err_t wg_initialized_
void set_preshared_key(const std::string &key)=delete
bool is_enabled()
Return if the WireGuard component is or is not enabled.
const char * peer_public_key_
void enable()
Enable the WireGuard component.
void set_peer_port(uint16_t port)
void set_peer_endpoint(const char *endpoint)
void set_netmask(const std::string &netmask)=delete
const char * preshared_key_
void set_private_key(const std::string &key)=delete
void set_peer_public_key(const char *key)
const char * peer_endpoint_
time_t latest_saved_handshake_
The latest saved handshake.
wireguard_config_t wg_config_
Condition to check if remote peer is online.
bool check(const Ts &...x) override
constexpr float BEFORE_CONNECTION
For components that should be initialized after WiFi and before API is connected.
void mask_key_to(char *buffer, size_t len, const char *key)
Strip most part of the key only for secure printing.
Allowed IP entry for WireGuard peer configuration.