esphome-api-client 0.5.0
Modern C++17 client for the ESPHome native API (plaintext + Noise)
Loading...
Searching...
No Matches
sync_client.hpp
Go to the documentation of this file.
1#pragma once
2
6
14
15#include <chrono>
16#include <functional>
17
18namespace esphome::api {
19
23public:
24 explicit SyncClient(const ClientOptions& options);
25
28 void connect() const;
29
31 void disconnect() const;
32
33 [[nodiscard]] bool is_connected() const {
34 return client_.is_connected();
35 }
36 [[nodiscard]] ConnectionState state() const {
37 return client_.state();
38 }
39 [[nodiscard]] const ServerHello& server_hello() const {
40 return client_.server_hello();
41 }
42
45
48 void list_entities() const;
49
52 void subscribe_states() const;
53
56 [[nodiscard]] EntityRegistry entities() {
57 return client_.entities();
58 }
60 [[nodiscard]] EntityStore& store() noexcept {
61 return client_.store();
62 }
63 [[nodiscard]] const EntityStore& store() const noexcept {
64 return client_.store();
65 }
66
67 // --- Subsystems (delegated to the async client) --------------------------
68 [[nodiscard]] BluetoothProxy& bluetooth() {
69 return client_.bluetooth();
70 }
71 [[nodiscard]] LogStream& logs() {
72 return client_.logs();
73 }
75 return client_.home_assistant();
76 }
77 [[nodiscard]] VoiceAssistant& voice() {
78 return client_.voice();
79 }
80 [[nodiscard]] ZWaveProxy& zwave() {
81 return client_.zwave();
82 }
83 [[nodiscard]] SerialProxy& serial() {
84 return client_.serial();
85 }
87 [[nodiscard]] SerialPort serial_proxy(std::uint32_t instance);
88
91 [[nodiscard]] SerialPort serial_proxy(const std::string& name);
92
95 void set_request_timeout(const std::chrono::milliseconds timeout) {
96 request_timeout_ = timeout;
97 }
98
101 void pump_until(const std::function<bool()>& predicate,
102 std::chrono::milliseconds timeout) const;
103
105 [[nodiscard]] Client& async() {
106 return client_;
107 }
108
109private:
110 Client client_;
111 bool subscribe_on_connect_ = true;
112 std::chrono::milliseconds request_timeout_{30000};
113 std::chrono::milliseconds connect_pump_timeout_;
114};
115
116} // namespace esphome::api
Scans for, connects to, and talks GATT to BLE devices through the device's Bluetooth proxy.
Definition bluetooth_proxy.hpp:175
Async client for a single device.
Definition client.hpp:38
SerialProxy & serial()
ConnectionState state() const
VoiceAssistant & voice()
bool is_connected() const
EntityRegistry entities()
Typed, object-oriented view over the entity store: entities().switches(), entities()....
HomeAssistantServices & home_assistant()
LogStream & logs()
const ServerHello & server_hello() const
BluetoothProxy & bluetooth()
EntityStore & store()
The store of discovered entities and their latest states (auto-populated from every inbound message).
ZWaveProxy & zwave()
Object-oriented façade over the entity store.
Definition entity_registry.hpp:60
Collects a device's entity descriptions and live states.
Definition entity_store.hpp:60
Discovers user-defined services and invokes them.
Definition home_assistant_services.hpp:43
Subscribes to and surfaces the device's log stream.
Definition log_stream.hpp:21
A single serial-proxy instance bound to its index — the instance-aware, ergonomic front end to Serial...
Definition serial_proxy.hpp:129
Proxies a UART on the device, forwarding data and control to clients.
Definition serial_proxy.hpp:68
Synchronous, single-threaded client.
Definition sync_client.hpp:22
LogStream & logs()
Definition sync_client.hpp:71
SerialPort serial_proxy(std::uint32_t instance)
Instance-bound serial-proxy handle: sync.serial_proxy(0).write(...).
void list_entities() const
Request the full entity list and block until ListEntitiesDoneResponse.
VoiceAssistant & voice()
Definition sync_client.hpp:77
SerialPort serial_proxy(const std::string &name)
Serial-proxy handle by advertised name.
SerialProxy & serial()
Definition sync_client.hpp:83
void disconnect() const
Gracefully disconnect, blocking briefly for the close to settle.
EntityStore & store() noexcept
The underlying entity store (raw typed info/state access).
Definition sync_client.hpp:60
HomeAssistantServices & home_assistant()
Definition sync_client.hpp:74
DeviceInfo device_info() const
Request the device's DeviceInfoResponse and return it as a typed struct.
void connect() const
Connect and complete the handshake, blocking until ready.
EntityRegistry entities()
Object-oriented view of the discovered entities: entities().switches(), entities()....
Definition sync_client.hpp:56
const ServerHello & server_hello() const
Definition sync_client.hpp:39
Client & async()
Access the underlying async client (register handlers, send raw, etc.).
Definition sync_client.hpp:105
ConnectionState state() const
Definition sync_client.hpp:36
SyncClient(const ClientOptions &options)
BluetoothProxy & bluetooth()
Definition sync_client.hpp:68
bool is_connected() const
Definition sync_client.hpp:33
void set_request_timeout(const std::chrono::milliseconds timeout)
Default per-request deadline (does not apply to connect, which uses the connection's own handshake ti...
Definition sync_client.hpp:95
ZWaveProxy & zwave()
Definition sync_client.hpp:80
void subscribe_states() const
Subscribe to live state updates.
const EntityStore & store() const noexcept
Definition sync_client.hpp:63
void pump_until(const std::function< bool()> &predicate, std::chrono::milliseconds timeout) const
Pump the loop until predicate is true or timeout elapses.
Drives the device's voice-assistant pipeline: subscribing to start/stop requests, relaying events and...
Definition voice_assistant.hpp:79
Bridges raw Z-Wave frames between a client and the device's Z-Wave radio.
Definition zwave_proxy.hpp:20
Asynchronous orchestrator: owns the event loop and a Connection, and exposes connect/send/subscribe p...
Top-level connection parameters for Client / SyncClient.
Connection: the ESPHome native-API protocol state machine.
Connection state-machine states.
Typed view of the device's DeviceInfoResponse.
std::string name
Definition emit_registry.cpp:14
EntityRegistry: typed, object-oriented access to the entity store.
Typed store of a device's entities: ingest ListEntities*‍/State messages, query typed info/state per ...
Definition bytes.hpp:10
ConnectionState
Lifecycle of a Connection.
Definition connection_state.hpp:11
Everything needed to reach and authenticate with one ESPHome device.
Definition client_options.hpp:16
Ergonomic, copyable snapshot of a device's identity and capabilities, converted from the raw DeviceIn...
Definition device_info.hpp:27
Information returned by the device in its HelloResponse.
Definition connection.hpp:27