23 explicit EntityList(std::vector<E> items) : items_(std::move(items)) {}
24 [[nodiscard]] std::size_t
size() const noexcept {
27 [[nodiscard]]
bool empty() const noexcept {
28 return items_.empty();
33 [[nodiscard]]
const E&
at(std::size_t i)
const {
36 [[nodiscard]]
auto begin()
const {
37 return items_.begin();
39 [[nodiscard]]
auto end()
const {
42 [[nodiscard]] std::optional<E>
find(std::uint32_t key)
const {
43 for (
const E& e : items_)
48 [[nodiscard]] std::optional<E>
find(std::string_view object_id)
const {
49 for (
const E& e : items_)
50 if (e.object_id() == object_id)
56 std::vector<E> items_;
65 [[nodiscard]] std::size_t
size()
const {
72 [[nodiscard]] std::optional<BinarySensorEntity>
binary_sensor(
const std::uint32_t key)
const {
75 [[nodiscard]] std::optional<BinarySensorEntity>
83 [[nodiscard]] std::optional<SensorEntity>
sensor(
const std::uint32_t key)
const {
86 [[nodiscard]] std::optional<SensorEntity>
sensor(
const std::string_view object_id)
const {
93 [[nodiscard]] std::optional<TextSensorEntity>
text_sensor(
const std::uint32_t key)
const {
96 [[nodiscard]] std::optional<TextSensorEntity>
106 [[nodiscard]] std::optional<SwitchEntity>
switch_(
const std::uint32_t key)
const {
110 [[nodiscard]] std::optional<SwitchEntity>
switch_(
const std::string_view object_id)
const {
117 [[nodiscard]] std::optional<LightEntity>
light(
const std::uint32_t key)
const {
120 [[nodiscard]] std::optional<LightEntity>
light(
const std::string_view object_id)
const {
127 [[nodiscard]] std::optional<CoverEntity>
cover(
const std::uint32_t key)
const {
130 [[nodiscard]] std::optional<CoverEntity>
cover(
const std::string_view object_id)
const {
137 [[nodiscard]] std::optional<FanEntity>
fan(
const std::uint32_t key)
const {
140 [[nodiscard]] std::optional<FanEntity>
fan(
const std::string_view object_id)
const {
147 [[nodiscard]] std::optional<ClimateEntity>
climate(
const std::uint32_t key)
const {
150 [[nodiscard]] std::optional<ClimateEntity>
climate(
const std::string_view object_id)
const {
157 [[nodiscard]] std::optional<NumberEntity>
number(
const std::uint32_t key)
const {
160 [[nodiscard]] std::optional<NumberEntity>
number(
const std::string_view object_id)
const {
167 [[nodiscard]] std::optional<SelectEntity>
select(
const std::uint32_t key)
const {
170 [[nodiscard]] std::optional<SelectEntity>
select(
const std::string_view object_id)
const {
177 [[nodiscard]] std::optional<TextEntity>
text(
const std::uint32_t key)
const {
180 [[nodiscard]] std::optional<TextEntity>
text(
const std::string_view object_id)
const {
187 [[nodiscard]] std::optional<ButtonEntity>
button(
const std::uint32_t key)
const {
190 [[nodiscard]] std::optional<ButtonEntity>
button(
const std::string_view object_id)
const {
197 [[nodiscard]] std::optional<LockEntity>
lock(
const std::uint32_t key)
const {
200 [[nodiscard]] std::optional<LockEntity>
lock(
const std::string_view object_id)
const {
207 [[nodiscard]] std::optional<MediaPlayerEntity>
media_player(
const std::uint32_t key)
const {
210 [[nodiscard]] std::optional<MediaPlayerEntity>
218 [[nodiscard]] std::optional<CameraEntity>
camera(
const std::uint32_t key)
const {
221 [[nodiscard]] std::optional<CameraEntity>
camera(
const std::string_view object_id)
const {
228 [[nodiscard]] std::optional<SirenEntity>
siren(
const std::uint32_t key)
const {
231 [[nodiscard]] std::optional<SirenEntity>
siren(
const std::string_view object_id)
const {
238 [[nodiscard]] std::optional<AlarmControlPanelEntity>
243 [[nodiscard]] std::optional<AlarmControlPanelEntity>
245 return one<AlarmControlPanelEntity>(
252 [[nodiscard]] std::optional<DateEntity>
date(
const std::uint32_t key)
const {
255 [[nodiscard]] std::optional<DateEntity>
date(
const std::string_view object_id)
const {
262 [[nodiscard]] std::optional<TimeEntity>
time(
const std::uint32_t key)
const {
265 [[nodiscard]] std::optional<TimeEntity>
time(
const std::string_view object_id)
const {
272 [[nodiscard]] std::optional<DateTimeEntity>
datetime(
const std::uint32_t key)
const {
275 [[nodiscard]] std::optional<DateTimeEntity>
datetime(
const std::string_view object_id)
const {
282 [[nodiscard]] std::optional<ValveEntity>
valve(
const std::uint32_t key)
const {
285 [[nodiscard]] std::optional<ValveEntity>
valve(
const std::string_view object_id)
const {
292 [[nodiscard]] std::optional<EventEntity>
event(
const std::uint32_t key)
const {
295 [[nodiscard]] std::optional<EventEntity>
event(
const std::string_view object_id)
const {
302 [[nodiscard]] std::optional<UpdateEntity>
update(
const std::uint32_t key)
const {
305 [[nodiscard]] std::optional<UpdateEntity>
update(
const std::string_view object_id)
const {
312 [[nodiscard]] std::optional<WaterHeaterEntity>
water_heater(
const std::uint32_t key)
const {
315 [[nodiscard]] std::optional<WaterHeaterEntity>
323 [[nodiscard]] std::optional<InfraredEntity>
infrared(
const std::uint32_t key)
const {
326 [[nodiscard]] std::optional<InfraredEntity>
infrared(
const std::string_view object_id)
const {
333 [[nodiscard]] std::optional<RadioFrequencyEntity>
337 [[nodiscard]] std::optional<RadioFrequencyEntity>
339 return one<RadioFrequencyEntity>(
347 for (
const StoredEntity* e : client_->store().entities())
349 out.emplace_back(*client_, e->key, e->object_id, e->
name);
353 std::optional<E> one(
const EntityType type,
const StoredEntity* e)
const {
354 if (e ==
nullptr || e->type != type)
356 return E(*client_, e->key, e->object_id, e->name);
Async client for a single device.
Definition client.hpp:38
EntityStore & store()
The store of discovered entities and their latest states (auto-populated from every inbound message).
A snapshot list of entity handles of one domain, with index + lookup access.
Definition entity_registry.hpp:21
std::optional< E > find(std::string_view object_id) const
Definition entity_registry.hpp:48
std::size_t size() const noexcept
Definition entity_registry.hpp:24
auto begin() const
Definition entity_registry.hpp:36
std::optional< E > find(std::uint32_t key) const
Definition entity_registry.hpp:42
EntityList(std::vector< E > items)
Definition entity_registry.hpp:23
bool empty() const noexcept
Definition entity_registry.hpp:27
auto end() const
Definition entity_registry.hpp:39
const E & operator[](std::size_t i) const
Definition entity_registry.hpp:30
const E & at(std::size_t i) const
Definition entity_registry.hpp:33
Object-oriented façade over the entity store.
Definition entity_registry.hpp:60
std::optional< SwitchEntity > switch_(const std::uint32_t key) const
Definition entity_registry.hpp:106
std::optional< WaterHeaterEntity > water_heater(const std::uint32_t key) const
Definition entity_registry.hpp:312
std::optional< ButtonEntity > button(const std::string_view object_id) const
Definition entity_registry.hpp:190
EntityList< MediaPlayerEntity > media_players() const
Definition entity_registry.hpp:204
EntityList< BinarySensorEntity > binary_sensors() const
Definition entity_registry.hpp:69
std::optional< LockEntity > lock(const std::string_view object_id) const
Definition entity_registry.hpp:200
EntityList< UpdateEntity > updates() const
Definition entity_registry.hpp:299
EntityList< EventEntity > events() const
Definition entity_registry.hpp:289
EntityList< SwitchEntity > switches() const
Definition entity_registry.hpp:101
EntityList< WaterHeaterEntity > water_heaters() const
Definition entity_registry.hpp:309
std::optional< TextEntity > text(const std::uint32_t key) const
Definition entity_registry.hpp:177
std::optional< InfraredEntity > infrared(const std::string_view object_id) const
Definition entity_registry.hpp:326
std::optional< CameraEntity > camera(const std::string_view object_id) const
Definition entity_registry.hpp:221
std::optional< BinarySensorEntity > binary_sensor(const std::string_view object_id) const
Definition entity_registry.hpp:76
std::optional< DateEntity > date(const std::uint32_t key) const
Definition entity_registry.hpp:252
std::optional< TextEntity > text(const std::string_view object_id) const
Definition entity_registry.hpp:180
std::optional< CoverEntity > cover(const std::uint32_t key) const
Definition entity_registry.hpp:127
EntityList< SirenEntity > sirens() const
Definition entity_registry.hpp:225
std::size_t size() const
Total number of discovered entities (all domains).
Definition entity_registry.hpp:65
std::optional< LightEntity > light(const std::string_view object_id) const
Definition entity_registry.hpp:120
std::optional< LightEntity > light(const std::uint32_t key) const
Definition entity_registry.hpp:117
std::optional< MediaPlayerEntity > media_player(const std::uint32_t key) const
Definition entity_registry.hpp:207
std::optional< SirenEntity > siren(const std::uint32_t key) const
Definition entity_registry.hpp:228
std::optional< FanEntity > fan(const std::string_view object_id) const
Definition entity_registry.hpp:140
EntityList< LockEntity > locks() const
Definition entity_registry.hpp:194
EntityList< ValveEntity > valves() const
Definition entity_registry.hpp:279
std::optional< SirenEntity > siren(const std::string_view object_id) const
Definition entity_registry.hpp:231
std::optional< BinarySensorEntity > binary_sensor(const std::uint32_t key) const
Definition entity_registry.hpp:72
std::optional< CoverEntity > cover(const std::string_view object_id) const
Definition entity_registry.hpp:130
std::optional< RadioFrequencyEntity > radio_frequency(const std::uint32_t key) const
Definition entity_registry.hpp:334
EntityList< TimeEntity > times() const
Definition entity_registry.hpp:259
EntityList< LightEntity > lights() const
Definition entity_registry.hpp:114
std::optional< ValveEntity > valve(const std::uint32_t key) const
Definition entity_registry.hpp:282
std::optional< DateTimeEntity > datetime(const std::string_view object_id) const
Definition entity_registry.hpp:275
std::optional< SelectEntity > select(const std::uint32_t key) const
Definition entity_registry.hpp:167
std::optional< TimeEntity > time(const std::string_view object_id) const
Definition entity_registry.hpp:265
std::optional< WaterHeaterEntity > water_heater(const std::string_view object_id) const
Definition entity_registry.hpp:316
std::optional< EventEntity > event(const std::uint32_t key) const
Definition entity_registry.hpp:292
EntityList< DateEntity > dates() const
Definition entity_registry.hpp:249
EntityList< FanEntity > fans() const
Definition entity_registry.hpp:134
std::optional< ClimateEntity > climate(const std::string_view object_id) const
Definition entity_registry.hpp:150
std::optional< TextSensorEntity > text_sensor(const std::string_view object_id) const
Definition entity_registry.hpp:97
std::optional< SelectEntity > select(const std::string_view object_id) const
Definition entity_registry.hpp:170
std::optional< NumberEntity > number(const std::string_view object_id) const
Definition entity_registry.hpp:160
std::optional< ClimateEntity > climate(const std::uint32_t key) const
Definition entity_registry.hpp:147
std::optional< SensorEntity > sensor(const std::uint32_t key) const
Definition entity_registry.hpp:83
std::optional< RadioFrequencyEntity > radio_frequency(const std::string_view object_id) const
Definition entity_registry.hpp:338
std::optional< UpdateEntity > update(const std::string_view object_id) const
Definition entity_registry.hpp:305
std::optional< EventEntity > event(const std::string_view object_id) const
Definition entity_registry.hpp:295
std::optional< SwitchEntity > switch_(const std::string_view object_id) const
Definition entity_registry.hpp:110
EntityList< SensorEntity > sensors() const
Definition entity_registry.hpp:80
EntityList< AlarmControlPanelEntity > alarm_control_panels() const
Definition entity_registry.hpp:235
std::optional< LockEntity > lock(const std::uint32_t key) const
Definition entity_registry.hpp:197
EntityList< ClimateEntity > climates() const
Definition entity_registry.hpp:144
std::optional< DateEntity > date(const std::string_view object_id) const
Definition entity_registry.hpp:255
EntityList< ButtonEntity > buttons() const
Definition entity_registry.hpp:184
std::optional< InfraredEntity > infrared(const std::uint32_t key) const
Definition entity_registry.hpp:323
std::optional< ValveEntity > valve(const std::string_view object_id) const
Definition entity_registry.hpp:285
EntityList< InfraredEntity > infrareds() const
Definition entity_registry.hpp:320
EntityList< NumberEntity > numbers() const
Definition entity_registry.hpp:154
std::optional< ButtonEntity > button(const std::uint32_t key) const
Definition entity_registry.hpp:187
std::optional< UpdateEntity > update(const std::uint32_t key) const
Definition entity_registry.hpp:302
EntityList< SelectEntity > selects() const
Definition entity_registry.hpp:164
EntityList< TextSensorEntity > text_sensors() const
Definition entity_registry.hpp:90
std::optional< SensorEntity > sensor(const std::string_view object_id) const
Definition entity_registry.hpp:86
std::optional< FanEntity > fan(const std::uint32_t key) const
Definition entity_registry.hpp:137
std::optional< AlarmControlPanelEntity > alarm_control_panel(const std::uint32_t key) const
Definition entity_registry.hpp:239
std::optional< NumberEntity > number(const std::uint32_t key) const
Definition entity_registry.hpp:157
EntityList< DateTimeEntity > datetimes() const
Definition entity_registry.hpp:269
EntityRegistry(Client &client)
Definition entity_registry.hpp:62
std::optional< MediaPlayerEntity > media_player(const std::string_view object_id) const
Definition entity_registry.hpp:211
std::optional< TextSensorEntity > text_sensor(const std::uint32_t key) const
Definition entity_registry.hpp:93
std::optional< TimeEntity > time(const std::uint32_t key) const
Definition entity_registry.hpp:262
EntityList< CoverEntity > covers() const
Definition entity_registry.hpp:124
std::optional< CameraEntity > camera(const std::uint32_t key) const
Definition entity_registry.hpp:218
EntityList< RadioFrequencyEntity > radio_frequencys() const
Definition entity_registry.hpp:330
std::optional< DateTimeEntity > datetime(const std::uint32_t key) const
Definition entity_registry.hpp:272
EntityList< CameraEntity > cameras() const
Definition entity_registry.hpp:215
EntityList< TextEntity > texts() const
Definition entity_registry.hpp:174
std::optional< AlarmControlPanelEntity > alarm_control_panel(const std::string_view object_id) const
Definition entity_registry.hpp:244
std::size_t size() const noexcept
Definition entity_store.hpp:77
const StoredEntity * find_by_object_id(const std::string &object_id) const
const StoredEntity * find(std::uint32_t key) const
Asynchronous orchestrator: owns the event loop and a Connection, and exposes connect/send/subscribe p...
std::string name
Definition emit_registry.cpp:14
Object-oriented entity handles.
Typed store of a device's entities: ingest ListEntities*/State messages, query typed info/state per ...
EntityType
One per ESPHome entity domain (the <X> in ListEntities<X>Response).
Definition entity_type.hpp:11
A single tracked entity: its domain, identity, and the latest raw info/ state protobuf messages (deco...
Definition entity_store.hpp:49