|
esphome-api-client 0.5.0
Modern C++17 client for the ESPHome native API (plaintext + Noise)
|
Async client for a single device. More...
#include <client.hpp>
Public Types | |
| using | ConnectHandler = std::function< void(std::error_code)> |
| using | MessageHandler = std::function< void(const ProtoMessage &)> |
| using | RawHandler = std::function< void(std::uint32_t msg_type, ByteView payload)> |
| using | StateHandler = std::function< void(ConnectionState)> |
| using | ErrorHandler = std::function< void(std::error_code, const std::string &)> |
Public Member Functions | |
| Client (ClientOptions options) | |
| ~Client () | |
| Client (const Client &)=delete | |
| Client & | operator= (const Client &)=delete |
| void | async_connect (ConnectHandler on_done) const |
Begin connecting + handshaking; on_done fires once when the session is ready (or with an error). | |
| void | disconnect () const |
| Begin a graceful disconnect. | |
| ConnectionState | state () const |
| bool | is_connected () const |
| const ServerHello & | server_hello () const |
| void | send (const ProtoMessage &msg) const |
| void | send_raw (std::uint32_t msg_type, ByteView payload) const |
| void | on (std::uint32_t msg_type, MessageHandler handler) const |
| void | on_any (MessageHandler handler) const |
| void | on_raw (RawHandler handler) const |
| void | on_state (StateHandler handler) const |
| void | on_error (ErrorHandler handler) const |
| void | run () const |
| Run the loop until stopped (blocking). Typically used on a worker thread. | |
| std::size_t | run_for (std::chrono::milliseconds duration) const |
Run ready handlers for up to duration; returns handlers executed. | |
| std::size_t | run_one () const |
| Run a single handler, blocking until one is available; returns count. | |
| std::size_t | poll () const |
| Execute any ready handlers without blocking; returns handlers executed. | |
| void | stop () const |
Stop the loop (causes run to return). | |
| void | restart () const |
| Reset a stopped loop so it can run again. | |
| void | post (std::function< void()> fn) const |
Post fn to run on the client's executor. | |
| Connection & | connection () const |
| Access the underlying Connection (advanced/raw use). | |
| EntityStore & | store () |
| The store of discovered entities and their latest states (auto-populated from every inbound message). | |
| const EntityStore & | store () const |
| EntityRegistry | entities () |
Typed, object-oriented view over the entity store: entities().switches(), entities().light("ceiling"), etc. | |
| void | request_entity_list () const |
| Ask the device to enumerate its entities (ListEntitiesRequest). | |
| void | subscribe_to_states () const |
| Ask the device to stream state updates (SubscribeStatesRequest). | |
| BluetoothProxy & | bluetooth () |
| LogStream & | logs () |
| HomeAssistantServices & | home_assistant () |
| VoiceAssistant & | voice () |
| ZWaveProxy & | zwave () |
| SerialProxy & | serial () |
| SerialPort | serial_proxy (std::uint32_t instance) |
An instance-bound serial-proxy handle: client.serial_proxy(0).write(...). | |
| SerialPort | serial_proxy (const std::string &name) |
| Look up a serial-proxy handle by its advertised name. | |
| bool | has_device_info () const |
| The most recently received DeviceInfo (populated when a DeviceInfoResponse is seen). | |
| const DeviceInfo & | device_info () const |
Async client for a single device.
Not thread-safe: drive it from one thread (or post work onto its executor with post). SyncClient wraps this with blocking convenience methods.
| using esphome::api::Client::ConnectHandler = std::function<void(std::error_code)> |
| using esphome::api::Client::ErrorHandler = std::function<void(std::error_code, const std::string&)> |
| using esphome::api::Client::MessageHandler = std::function<void(const ProtoMessage&)> |
| using esphome::api::Client::RawHandler = std::function<void(std::uint32_t msg_type, ByteView payload)> |
| using esphome::api::Client::StateHandler = std::function<void(ConnectionState)> |
|
explicit |
| esphome::api::Client::~Client | ( | ) |
|
delete |
| void esphome::api::Client::async_connect | ( | ConnectHandler | on_done | ) | const |
Begin connecting + handshaking; on_done fires once when the session is ready (or with an error).
Must be driven by the event loop afterwards.
| BluetoothProxy & esphome::api::Client::bluetooth | ( | ) |
| Connection & esphome::api::Client::connection | ( | ) | const |
Access the underlying Connection (advanced/raw use).
| const DeviceInfo & esphome::api::Client::device_info | ( | ) | const |
| void esphome::api::Client::disconnect | ( | ) | const |
Begin a graceful disconnect.
| EntityRegistry esphome::api::Client::entities | ( | ) |
Typed, object-oriented view over the entity store: entities().switches(), entities().light("ceiling"), etc.
| bool esphome::api::Client::has_device_info | ( | ) | const |
The most recently received DeviceInfo (populated when a DeviceInfoResponse is seen).
has_device_info() reports whether it is valid yet.
| HomeAssistantServices & esphome::api::Client::home_assistant | ( | ) |
| bool esphome::api::Client::is_connected | ( | ) | const |
| LogStream & esphome::api::Client::logs | ( | ) |
| void esphome::api::Client::on | ( | std::uint32_t | msg_type, |
| MessageHandler | handler | ||
| ) | const |
| void esphome::api::Client::on_any | ( | MessageHandler | handler | ) | const |
| void esphome::api::Client::on_error | ( | ErrorHandler | handler | ) | const |
| void esphome::api::Client::on_raw | ( | RawHandler | handler | ) | const |
| void esphome::api::Client::on_state | ( | StateHandler | handler | ) | const |
| std::size_t esphome::api::Client::poll | ( | ) | const |
Execute any ready handlers without blocking; returns handlers executed.
| void esphome::api::Client::post | ( | std::function< void()> | fn | ) | const |
Post fn to run on the client's executor.
| void esphome::api::Client::request_entity_list | ( | ) | const |
Ask the device to enumerate its entities (ListEntitiesRequest).
| void esphome::api::Client::restart | ( | ) | const |
Reset a stopped loop so it can run again.
| void esphome::api::Client::run | ( | ) | const |
Run the loop until stopped (blocking). Typically used on a worker thread.
| std::size_t esphome::api::Client::run_for | ( | std::chrono::milliseconds | duration | ) | const |
Run ready handlers for up to duration; returns handlers executed.
| std::size_t esphome::api::Client::run_one | ( | ) | const |
Run a single handler, blocking until one is available; returns count.
| void esphome::api::Client::send | ( | const ProtoMessage & | msg | ) | const |
| void esphome::api::Client::send_raw | ( | std::uint32_t | msg_type, |
| ByteView | payload | ||
| ) | const |
| SerialProxy & esphome::api::Client::serial | ( | ) |
| SerialPort esphome::api::Client::serial_proxy | ( | const std::string & | name | ) |
Look up a serial-proxy handle by its advertised name.
Requires the device's DeviceInfo to have been received (the client caches it); throws ApiError if absent or the name is unknown.
| SerialPort esphome::api::Client::serial_proxy | ( | std::uint32_t | instance | ) |
An instance-bound serial-proxy handle: client.serial_proxy(0).write(...).
| const ServerHello & esphome::api::Client::server_hello | ( | ) | const |
| ConnectionState esphome::api::Client::state | ( | ) | const |
| void esphome::api::Client::stop | ( | ) | const |
Stop the loop (causes run to return).
| EntityStore & esphome::api::Client::store | ( | ) |
The store of discovered entities and their latest states (auto-populated from every inbound message).
| const EntityStore & esphome::api::Client::store | ( | ) | const |
| void esphome::api::Client::subscribe_to_states | ( | ) | const |
Ask the device to stream state updates (SubscribeStatesRequest).
| VoiceAssistant & esphome::api::Client::voice | ( | ) |
| ZWaveProxy & esphome::api::Client::zwave | ( | ) |