esphome-api-client 0.5.0
Modern C++17 client for the ESPHome native API (plaintext + Noise)
Loading...
Searching...
No Matches
home_assistant_services.hpp
Go to the documentation of this file.
1#pragma once
2
5
8
9#include <cstdint>
10#include <functional>
11#include <string>
12#include <variant>
13#include <vector>
14
15namespace esphome::api {
16
22
25 std::string name;
26 std::uint32_t key = 0;
27 std::vector<UserServiceArg> args;
29};
30
33using ServiceValue = std::variant<bool,
34 std::int32_t,
35 float,
36 std::string,
37 std::vector<bool>,
38 std::vector<std::int32_t>,
39 std::vector<float>,
40 std::vector<std::string>>;
41
44public:
45 using ServiceHandler = std::function<void(const UserService&)>;
46
47 explicit HomeAssistantServices(Client& client) : Subsystem(client) {}
48
52
54 void
55 execute(std::uint32_t key, const std::vector<ServiceValue>& args, bool return_response = false);
56
57 [[nodiscard]] const std::vector<UserService>& services() const noexcept {
58 return services_;
59 }
60
61private:
62 ServiceHandler handler_;
63 std::vector<UserService> services_;
64 std::uint32_t next_call_id_ = 1;
65};
66
67} // namespace esphome::api
Async client for a single device.
Definition client.hpp:38
Discovers user-defined services and invokes them.
Definition home_assistant_services.hpp:43
void on_service(ServiceHandler handler)
Register a callback fired for each ListEntitiesServicesResponse (call before list_entities()).
std::function< void(const UserService &)> ServiceHandler
Definition home_assistant_services.hpp:45
HomeAssistantServices(Client &client)
Definition home_assistant_services.hpp:47
void execute(std::uint32_t key, const std::vector< ServiceValue > &args, bool return_response=false)
Invoke a service by key with positional arguments.
const std::vector< UserService > & services() const noexcept
Definition home_assistant_services.hpp:57
Shared base for the subsystems exposed by Client (log streaming, the various proxies,...
Definition subsystem.hpp:18
Typed mirrors of the ESPHome protobuf enums.
Definition bytes.hpp:10
std::variant< bool, std::int32_t, float, std::string, std::vector< bool >, std::vector< std::int32_t >, std::vector< float >, std::vector< std::string > > ServiceValue
A value passed to a service invocation.
Definition home_assistant_services.hpp:40
SupportsResponseType
Mirror of proto enum SupportsResponseType.
Definition enums.hpp:123
ServiceArgType
Mirror of proto enum ServiceArgType.
Definition enums.hpp:111
One argument of a user-defined service.
Definition home_assistant_services.hpp:18
ServiceArgType type
Definition home_assistant_services.hpp:20
std::string name
Definition home_assistant_services.hpp:19
A user-defined service advertised by the device (api: api.services).
Definition home_assistant_services.hpp:24
std::uint32_t key
Definition home_assistant_services.hpp:26
SupportsResponseType supports_response
Definition home_assistant_services.hpp:28
std::vector< UserServiceArg > args
Definition home_assistant_services.hpp:27
std::string name
Definition home_assistant_services.hpp:25
Common base for the Client-owned subsystems.