ESPHome  2023.5.5
Data Structures | Public Member Functions | Protected Attributes
esphome::api::APIServer Class Reference

#include <api_server.h>

Inheritance diagram for esphome::api::APIServer:
esphome::Component esphome::Controller

Data Structures

struct  HomeAssistantStateSubscription
 

Public Member Functions

 APIServer ()
 
void setup () override
 
uint16_t get_port () const
 
float get_setup_priority () const override
 
void loop () override
 
void dump_config () override
 
void on_shutdown () override
 
bool check_password (const std::string &password) const
 
bool uses_password () const
 
void set_port (uint16_t port)
 
void set_password (const std::string &password)
 
void set_reboot_timeout (uint32_t reboot_timeout)
 
void set_noise_psk (psk_t psk)
 
std::shared_ptr< APINoiseContextget_noise_ctx ()
 
void handle_disconnect (APIConnection *conn)
 
void on_binary_sensor_update (binary_sensor::BinarySensor *obj, bool state) override
 
void on_cover_update (cover::Cover *obj) override
 
void on_fan_update (fan::Fan *obj) override
 
void on_light_update (light::LightState *obj) override
 
void on_sensor_update (sensor::Sensor *obj, float state) override
 
void on_switch_update (switch_::Switch *obj, bool state) override
 
void on_text_sensor_update (text_sensor::TextSensor *obj, const std::string &state) override
 
void on_climate_update (climate::Climate *obj) override
 
void on_number_update (number::Number *obj, float state) override
 
void on_select_update (select::Select *obj, const std::string &state, size_t index) override
 
void on_lock_update (lock::Lock *obj) override
 
void on_media_player_update (media_player::MediaPlayer *obj) override
 
void send_homeassistant_service_call (const HomeassistantServiceResponse &call)
 
void send_bluetooth_le_advertisement (const BluetoothLEAdvertisementResponse &call)
 
void send_bluetooth_device_connection (uint64_t address, bool connected, uint16_t mtu=0, esp_err_t error=ESP_OK)
 
void send_bluetooth_device_pairing (uint64_t address, bool paired, esp_err_t error=ESP_OK)
 
void send_bluetooth_device_unpairing (uint64_t address, bool success, esp_err_t error=ESP_OK)
 
void send_bluetooth_device_clear_cache (uint64_t address, bool success, esp_err_t error=ESP_OK)
 
void send_bluetooth_connections_free (uint8_t free, uint8_t limit)
 
void send_bluetooth_gatt_read_response (const BluetoothGATTReadResponse &call)
 
void send_bluetooth_gatt_write_response (const BluetoothGATTWriteResponse &call)
 
void send_bluetooth_gatt_notify_data_response (const BluetoothGATTNotifyDataResponse &call)
 
void send_bluetooth_gatt_notify_response (const BluetoothGATTNotifyResponse &call)
 
void send_bluetooth_gatt_services (const BluetoothGATTGetServicesResponse &call)
 
void send_bluetooth_gatt_services_done (uint64_t address)
 
void send_bluetooth_gatt_error (uint64_t address, uint16_t handle, esp_err_t error)
 
void register_user_service (UserServiceDescriptor *descriptor)
 
void request_time ()
 
bool start_voice_assistant ()
 
void stop_voice_assistant ()
 
bool is_connected () const
 
void subscribe_home_assistant_state (std::string entity_id, optional< std::string > attribute, std::function< void(std::string)> f)
 
const std::vector< HomeAssistantStateSubscription > & get_state_subs () const
 
const std::vector< UserServiceDescriptor * > & get_user_services () const
 
- Public Member Functions inherited from esphome::Component
float get_actual_setup_priority () const
 
void set_setup_priority (float priority)
 
virtual float get_loop_priority () const
 priority of loop(). More...
 
void call ()
 
virtual void on_safe_shutdown ()
 
uint32_t get_component_state () const
 
virtual void mark_failed ()
 Mark this component as failed. More...
 
bool is_failed ()
 
bool is_ready ()
 
virtual bool can_proceed ()
 
bool status_has_warning ()
 
bool status_has_error ()
 
void status_set_warning ()
 
void status_set_error ()
 
void status_clear_warning ()
 
void status_clear_error ()
 
void status_momentary_warning (const std::string &name, uint32_t length=5000)
 
void status_momentary_error (const std::string &name, uint32_t length=5000)
 
bool has_overridden_loop () const
 
void set_component_source (const char *source)
 Set where this component was loaded from for some debug messages. More...
 
const char * get_component_source () const
 Get the integration where this component was declared as a string. More...
 
- Public Member Functions inherited from esphome::Controller
void setup_controller (bool include_internal=false)
 

Protected Attributes

std::unique_ptr< socket::Socketsocket_ = nullptr
 
uint16_t port_ {6053}
 
uint32_t reboot_timeout_ {300000}
 
uint32_t last_connected_ {0}
 
std::vector< std::unique_ptr< APIConnection > > clients_
 
std::string password_
 
std::vector< HomeAssistantStateSubscriptionstate_subs_
 
std::vector< UserServiceDescriptor * > user_services_
 
std::shared_ptr< APINoiseContextnoise_ctx_ = std::make_shared<APINoiseContext>()
 
- Protected Attributes inherited from esphome::Component
uint32_t component_state_ {0x0000}
 State of this component. More...
 
float setup_priority_override_ {NAN}
 
const char * component_source_ {nullptr}
 

Additional Inherited Members

- Protected Member Functions inherited from esphome::Component
virtual void call_loop ()
 
virtual void call_setup ()
 
virtual void call_dump_config ()
 
void set_interval (const std::string &name, uint32_t interval, std::function< void()> &&f)
 Set an interval function with a unique name. More...
 
void set_interval (uint32_t interval, std::function< void()> &&f)
 
bool cancel_interval (const std::string &name)
 Cancel an interval function. More...
 
void set_retry (const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f)
 Set an retry function with a unique name. More...
 
void set_retry (uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult(uint8_t)> &&f, float backoff_increase_factor=1.0f)
 
bool cancel_retry (const std::string &name)
 Cancel a retry function. More...
 
void set_timeout (const std::string &name, uint32_t timeout, std::function< void()> &&f)
 Set a timeout function with a unique name. More...
 
void set_timeout (uint32_t timeout, std::function< void()> &&f)
 
bool cancel_timeout (const std::string &name)
 Cancel a timeout function. More...
 
void defer (const std::string &name, std::function< void()> &&f)
 Defer a callback to the next loop() call. More...
 
void defer (std::function< void()> &&f)
 Defer a callback to the next loop() call. More...
 
bool cancel_defer (const std::string &name)
 Cancel a defer callback using the specified name, name must not be empty. More...
 

Detailed Description

Definition at line 20 of file api_server.h.

Constructor & Destructor Documentation

◆ APIServer()

esphome::api::APIServer::APIServer ( )

Definition at line 400 of file api_server.cpp.

Member Function Documentation

◆ check_password()

bool esphome::api::APIServer::check_password ( const std::string &  password) const

Definition at line 147 of file api_server.cpp.

◆ dump_config()

void esphome::api::APIServer::dump_config ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 137 of file api_server.cpp.

◆ get_noise_ctx()

std::shared_ptr<APINoiseContext> esphome::api::APIServer::get_noise_ctx ( )
inline

Definition at line 37 of file api_server.h.

◆ get_port()

uint16_t esphome::api::APIServer::get_port ( ) const

Definition at line 412 of file api_server.cpp.

◆ get_setup_priority()

float esphome::api::APIServer::get_setup_priority ( ) const
overridevirtual

Reimplemented from esphome::Component.

Definition at line 284 of file api_server.cpp.

◆ get_state_subs()

const std::vector< APIServer::HomeAssistantStateSubscription > & esphome::api::APIServer::get_state_subs ( ) const

Definition at line 409 of file api_server.cpp.

◆ get_user_services()

const std::vector<UserServiceDescriptor *>& esphome::api::APIServer::get_user_services ( ) const
inline

Definition at line 114 of file api_server.h.

◆ handle_disconnect()

void esphome::api::APIServer::handle_disconnect ( APIConnection conn)

Definition at line 175 of file api_server.cpp.

◆ is_connected()

bool esphome::api::APIServer::is_connected ( ) const

Definition at line 422 of file api_server.cpp.

◆ loop()

void esphome::api::APIServer::loop ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 94 of file api_server.cpp.

◆ on_binary_sensor_update()

void esphome::api::APIServer::on_binary_sensor_update ( binary_sensor::BinarySensor obj,
bool  state 
)
overridevirtual

Reimplemented from esphome::Controller.

Definition at line 177 of file api_server.cpp.

◆ on_climate_update()

void esphome::api::APIServer::on_climate_update ( climate::Climate obj)
overridevirtual

Reimplemented from esphome::Controller.

Definition at line 240 of file api_server.cpp.

◆ on_cover_update()

void esphome::api::APIServer::on_cover_update ( cover::Cover obj)
overridevirtual

Reimplemented from esphome::Controller.

Definition at line 186 of file api_server.cpp.

◆ on_fan_update()

void esphome::api::APIServer::on_fan_update ( fan::Fan obj)
overridevirtual

Reimplemented from esphome::Controller.

Definition at line 195 of file api_server.cpp.

◆ on_light_update()

void esphome::api::APIServer::on_light_update ( light::LightState obj)
overridevirtual

Reimplemented from esphome::Controller.

Definition at line 204 of file api_server.cpp.

◆ on_lock_update()

void esphome::api::APIServer::on_lock_update ( lock::Lock obj)
overridevirtual

Reimplemented from esphome::Controller.

Definition at line 267 of file api_server.cpp.

◆ on_media_player_update()

void esphome::api::APIServer::on_media_player_update ( media_player::MediaPlayer obj)
overridevirtual

Reimplemented from esphome::Controller.

Definition at line 276 of file api_server.cpp.

◆ on_number_update()

void esphome::api::APIServer::on_number_update ( number::Number obj,
float  state 
)
overridevirtual

Reimplemented from esphome::Controller.

Definition at line 249 of file api_server.cpp.

◆ on_select_update()

void esphome::api::APIServer::on_select_update ( select::Select obj,
const std::string &  state,
size_t  index 
)
overridevirtual

Reimplemented from esphome::Controller.

Definition at line 258 of file api_server.cpp.

◆ on_sensor_update()

void esphome::api::APIServer::on_sensor_update ( sensor::Sensor obj,
float  state 
)
overridevirtual

Reimplemented from esphome::Controller.

Definition at line 213 of file api_server.cpp.

◆ on_shutdown()

void esphome::api::APIServer::on_shutdown ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 423 of file api_server.cpp.

◆ on_switch_update()

void esphome::api::APIServer::on_switch_update ( switch_::Switch obj,
bool  state 
)
overridevirtual

Reimplemented from esphome::Controller.

Definition at line 222 of file api_server.cpp.

◆ on_text_sensor_update()

void esphome::api::APIServer::on_text_sensor_update ( text_sensor::TextSensor obj,
const std::string &  state 
)
overridevirtual

Reimplemented from esphome::Controller.

Definition at line 231 of file api_server.cpp.

◆ register_user_service()

void esphome::api::APIServer::register_user_service ( UserServiceDescriptor descriptor)
inline

Definition at line 93 of file api_server.h.

◆ request_time()

void esphome::api::APIServer::request_time ( )

Definition at line 415 of file api_server.cpp.

◆ send_bluetooth_connections_free()

void esphome::api::APIServer::send_bluetooth_connections_free ( uint8_t  free,
uint8_t  limit 
)

Definition at line 345 of file api_server.cpp.

◆ send_bluetooth_device_clear_cache()

void esphome::api::APIServer::send_bluetooth_device_clear_cache ( uint64_t  address,
bool  success,
esp_err_t  error = ESP_OK 
)

Definition at line 334 of file api_server.cpp.

◆ send_bluetooth_device_connection()

void esphome::api::APIServer::send_bluetooth_device_connection ( uint64_t  address,
bool  connected,
uint16_t  mtu = 0,
esp_err_t  error = ESP_OK 
)

Definition at line 300 of file api_server.cpp.

◆ send_bluetooth_device_pairing()

void esphome::api::APIServer::send_bluetooth_device_pairing ( uint64_t  address,
bool  paired,
esp_err_t  error = ESP_OK 
)

Definition at line 312 of file api_server.cpp.

◆ send_bluetooth_device_unpairing()

void esphome::api::APIServer::send_bluetooth_device_unpairing ( uint64_t  address,
bool  success,
esp_err_t  error = ESP_OK 
)

Definition at line 323 of file api_server.cpp.

◆ send_bluetooth_gatt_error()

void esphome::api::APIServer::send_bluetooth_gatt_error ( uint64_t  address,
uint16_t  handle,
esp_err_t  error 
)

Definition at line 388 of file api_server.cpp.

◆ send_bluetooth_gatt_notify_data_response()

void esphome::api::APIServer::send_bluetooth_gatt_notify_data_response ( const BluetoothGATTNotifyDataResponse call)

Definition at line 365 of file api_server.cpp.

◆ send_bluetooth_gatt_notify_response()

void esphome::api::APIServer::send_bluetooth_gatt_notify_response ( const BluetoothGATTNotifyResponse call)

Definition at line 370 of file api_server.cpp.

◆ send_bluetooth_gatt_read_response()

void esphome::api::APIServer::send_bluetooth_gatt_read_response ( const BluetoothGATTReadResponse call)

Definition at line 355 of file api_server.cpp.

◆ send_bluetooth_gatt_services()

void esphome::api::APIServer::send_bluetooth_gatt_services ( const BluetoothGATTGetServicesResponse call)

Definition at line 375 of file api_server.cpp.

◆ send_bluetooth_gatt_services_done()

void esphome::api::APIServer::send_bluetooth_gatt_services_done ( uint64_t  address)

Definition at line 380 of file api_server.cpp.

◆ send_bluetooth_gatt_write_response()

void esphome::api::APIServer::send_bluetooth_gatt_write_response ( const BluetoothGATTWriteResponse call)

Definition at line 360 of file api_server.cpp.

◆ send_bluetooth_le_advertisement()

void esphome::api::APIServer::send_bluetooth_le_advertisement ( const BluetoothLEAdvertisementResponse call)

Definition at line 295 of file api_server.cpp.

◆ send_homeassistant_service_call()

void esphome::api::APIServer::send_homeassistant_service_call ( const HomeassistantServiceResponse call)

Definition at line 289 of file api_server.cpp.

◆ set_noise_psk()

void esphome::api::APIServer::set_noise_psk ( psk_t  psk)
inline

Definition at line 36 of file api_server.h.

◆ set_password()

void esphome::api::APIServer::set_password ( const std::string &  password)

Definition at line 288 of file api_server.cpp.

◆ set_port()

void esphome::api::APIServer::set_port ( uint16_t  port)

Definition at line 285 of file api_server.cpp.

◆ set_reboot_timeout()

void esphome::api::APIServer::set_reboot_timeout ( uint32_t  reboot_timeout)

Definition at line 413 of file api_server.cpp.

◆ setup()

void esphome::api::APIServer::setup ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 24 of file api_server.cpp.

◆ start_voice_assistant()

bool esphome::api::APIServer::start_voice_assistant ( )

Definition at line 431 of file api_server.cpp.

◆ stop_voice_assistant()

void esphome::api::APIServer::stop_voice_assistant ( )

Definition at line 438 of file api_server.cpp.

◆ subscribe_home_assistant_state()

void esphome::api::APIServer::subscribe_home_assistant_state ( std::string  entity_id,
optional< std::string >  attribute,
std::function< void(std::string)>  f 
)

Definition at line 401 of file api_server.cpp.

◆ uses_password()

bool esphome::api::APIServer::uses_password ( ) const

Definition at line 146 of file api_server.cpp.

Field Documentation

◆ clients_

std::vector<std::unique_ptr<APIConnection> > esphome::api::APIServer::clients_
protected

Definition at line 121 of file api_server.h.

◆ last_connected_

uint32_t esphome::api::APIServer::last_connected_ {0}
protected

Definition at line 120 of file api_server.h.

◆ noise_ctx_

std::shared_ptr<APINoiseContext> esphome::api::APIServer::noise_ctx_ = std::make_shared<APINoiseContext>()
protected

Definition at line 127 of file api_server.h.

◆ password_

std::string esphome::api::APIServer::password_
protected

Definition at line 122 of file api_server.h.

◆ port_

uint16_t esphome::api::APIServer::port_ {6053}
protected

Definition at line 118 of file api_server.h.

◆ reboot_timeout_

uint32_t esphome::api::APIServer::reboot_timeout_ {300000}
protected

Definition at line 119 of file api_server.h.

◆ socket_

std::unique_ptr<socket::Socket> esphome::api::APIServer::socket_ = nullptr
protected

Definition at line 117 of file api_server.h.

◆ state_subs_

std::vector<HomeAssistantStateSubscription> esphome::api::APIServer::state_subs_
protected

Definition at line 123 of file api_server.h.

◆ user_services_

std::vector<UserServiceDescriptor *> esphome::api::APIServer::user_services_
protected

Definition at line 124 of file api_server.h.


The documentation for this class was generated from the following files: