esphome-api-client 0.5.0
Modern C++17 client for the ESPHome native API (plaintext + Noise)
Loading...
Searching...
No Matches
entity_handles.hpp
Go to the documentation of this file.
1#pragma once
2
10
15
16#include <cstdint>
17#include <optional>
18#include <string>
19#include <utility>
20#include <vector>
21
22namespace esphome::api {
23
25class Entity {
26public:
27 Entity(Client& client, const std::uint32_t key, std::string object_id, std::string name)
28 : client_(&client), key_(key), object_id_(std::move(object_id)), name_(std::move(name)) {}
29 [[nodiscard]] std::uint32_t key() const noexcept {
30 return key_;
31 }
32 [[nodiscard]] const std::string& object_id() const noexcept {
33 return object_id_;
34 }
35 [[nodiscard]] const std::string& name() const noexcept {
36 return name_;
37 }
38
39protected:
41 std::uint32_t key_;
42 std::string object_id_;
43 std::string name_;
44};
45
47template <class Derived>
48class TypedEntity : public Entity {
49public:
51 [[nodiscard]] std::string icon() const {
52 auto i = self().info();
53 return i ? i->icon : std::string{};
54 }
55 [[nodiscard]] bool disabled_by_default() const {
56 auto i = self().info();
57 return i && i->disabled_by_default;
58 }
59 [[nodiscard]] EntityCategory entity_category() const {
60 auto i = self().info();
61 return i ? i->entity_category : EntityCategory::None;
62 }
63 [[nodiscard]] std::uint32_t device_id() const {
64 auto i = self().info();
65 return i ? i->device_id : 0U;
66 }
67
68private:
69 const Derived& self() const {
70 return *static_cast<const Derived*>(this);
71 }
72};
73
75template <class Derived>
76class ToggleEntity : public TypedEntity<Derived> {
77public:
78 using TypedEntity<Derived>::TypedEntity;
79 [[nodiscard]] bool is_on() const {
80 auto s = static_cast<const Derived*>(this)->state();
81 return s && s->state;
82 }
83 void turn_on() {
84 static_cast<Derived*>(this)->set_power(true);
85 }
86 void turn_off() {
87 static_cast<Derived*>(this)->set_power(false);
88 }
89 void toggle() {
90 static_cast<Derived*>(this)->set_power(!is_on());
91 }
92};
93
95class BinarySensorEntity : public TypedEntity<BinarySensorEntity> {
96public:
97 using TypedEntity<BinarySensorEntity>::TypedEntity;
98 [[nodiscard]] static constexpr EntityType type() {
100 }
101 [[nodiscard]] std::optional<BinarySensorInfo> info() const {
103 }
104 [[nodiscard]] std::optional<BinarySensorState> state() const {
106 }
107 [[nodiscard]] std::string device_class() const {
108 auto i = info();
109 return i ? i->device_class : std::string{};
110 }
111 [[nodiscard]] bool is_status_binary_sensor() const {
112 const auto i = info();
113 return i ? i->is_status_binary_sensor : bool{};
114 }
115 [[nodiscard]] bool missing_state() const {
116 const auto s = state();
117 return s ? s->missing_state : bool{};
118 }
120 bool is_on() const {
121 const auto s = state();
122 return s && s->state;
123 }
124};
125
127class SensorEntity : public TypedEntity<SensorEntity> {
128public:
129 using TypedEntity<SensorEntity>::TypedEntity;
130 [[nodiscard]] static constexpr EntityType type() {
131 return EntityType::Sensor;
132 }
133 [[nodiscard]] std::optional<SensorInfo> info() const {
134 return client_->store().sensor_info(key_);
135 }
136 [[nodiscard]] std::optional<SensorState> state() const {
137 return client_->store().sensor_state(key_);
138 }
139 [[nodiscard]] std::string unit_of_measurement() const {
140 auto i = info();
141 return i ? i->unit_of_measurement : std::string{};
142 }
143 [[nodiscard]] std::int32_t accuracy_decimals() const {
144 const auto i = info();
145 return i ? i->accuracy_decimals : std::int32_t{};
146 }
147 [[nodiscard]] bool force_update() const {
148 const auto i = info();
149 return i ? i->force_update : bool{};
150 }
151 [[nodiscard]] std::string device_class() const {
152 auto i = info();
153 return i ? i->device_class : std::string{};
154 }
155 [[nodiscard]] SensorStateClass state_class() const {
156 const auto i = info();
157 return i ? i->state_class : SensorStateClass{};
158 }
159 [[nodiscard]] bool missing_state() const {
160 const auto s = state();
161 return s ? s->missing_state : bool{};
162 }
164 float value() const {
165 const auto s = state();
166 return s ? s->state : 0.0F;
167 }
168 bool has_value() const {
169 const auto s = state();
170 return s && !s->missing_state;
171 }
172};
173
175class TextSensorEntity : public TypedEntity<TextSensorEntity> {
176public:
177 using TypedEntity<TextSensorEntity>::TypedEntity;
178 [[nodiscard]] static constexpr EntityType type() {
180 }
181 [[nodiscard]] std::optional<TextSensorInfo> info() const {
183 }
184 [[nodiscard]] std::optional<TextSensorState> state() const {
186 }
187 [[nodiscard]] std::string device_class() const {
188 auto i = info();
189 return i ? i->device_class : std::string{};
190 }
191 [[nodiscard]] bool missing_state() const {
192 const auto s = state();
193 return s ? s->missing_state : bool{};
194 }
195 std::string text() const {
196 auto s = state();
197 return s ? s->state : std::string{};
198 }
199};
200
202class SwitchEntity : public ToggleEntity<SwitchEntity> {
203public:
204 using ToggleEntity<SwitchEntity>::ToggleEntity;
205 [[nodiscard]] static constexpr EntityType type() {
206 return EntityType::Switch;
207 }
208 [[nodiscard]] std::optional<SwitchInfo> info() const {
209 return client_->store().switch_info(key_);
210 }
211 [[nodiscard]] std::optional<SwitchState> state() const {
212 return client_->store().switch_state(key_);
213 }
214 [[nodiscard]] bool assumed_state() const {
215 const auto i = info();
216 return i ? i->assumed_state : bool{};
217 }
218 [[nodiscard]] std::string device_class() const {
219 auto i = info();
220 return i ? i->device_class : std::string{};
221 }
223 void command(SwitchCommand c) const {
224 c.key = key_;
226 }
228 void set_power(const bool on) const {
230 }
231};
232
234class LightEntity : public ToggleEntity<LightEntity> {
235public:
236 using ToggleEntity<LightEntity>::ToggleEntity;
237 [[nodiscard]] static constexpr EntityType type() {
238 return EntityType::Light;
239 }
240 [[nodiscard]] std::optional<LightInfo> info() const {
241 return client_->store().light_info(key_);
242 }
243 [[nodiscard]] std::optional<LightState> state() const {
244 return client_->store().light_state(key_);
245 }
246 [[nodiscard]] std::vector<ColorMode> supported_color_modes() const {
247 auto i = info();
248 return i ? i->supported_color_modes : std::vector<ColorMode>{};
249 }
250 [[nodiscard]] float min_mireds() const {
251 const auto i = info();
252 return i ? i->min_mireds : float{};
253 }
254 [[nodiscard]] float max_mireds() const {
255 const auto i = info();
256 return i ? i->max_mireds : float{};
257 }
258 [[nodiscard]] std::vector<std::string> effects() const {
259 auto i = info();
260 return i ? i->effects : std::vector<std::string>{};
261 }
262 [[nodiscard]] float brightness() const {
263 const auto s = state();
264 return s ? s->brightness : float{};
265 }
266 [[nodiscard]] ColorMode color_mode() const {
267 const auto s = state();
268 return s ? s->color_mode : ColorMode{};
269 }
270 [[nodiscard]] float color_brightness() const {
271 const auto s = state();
272 return s ? s->color_brightness : float{};
273 }
274 [[nodiscard]] float red() const {
275 const auto s = state();
276 return s ? s->red : float{};
277 }
278 [[nodiscard]] float green() const {
279 const auto s = state();
280 return s ? s->green : float{};
281 }
282 [[nodiscard]] float blue() const {
283 const auto s = state();
284 return s ? s->blue : float{};
285 }
286 [[nodiscard]] float white() const {
287 const auto s = state();
288 return s ? s->white : float{};
289 }
290 [[nodiscard]] float color_temperature() const {
291 const auto s = state();
292 return s ? s->color_temperature : float{};
293 }
294 [[nodiscard]] float cold_white() const {
295 const auto s = state();
296 return s ? s->cold_white : float{};
297 }
298 [[nodiscard]] float warm_white() const {
299 const auto s = state();
300 return s ? s->warm_white : float{};
301 }
302 [[nodiscard]] std::string effect() const {
303 auto s = state();
304 return s ? s->effect : std::string{};
305 }
307 void command(LightCommand c) const {
308 c.key = key_;
310 }
312 void set_power(bool on) const {
313 LightCommand c;
314 c.key = key_;
315 c.state = on;
317 }
318 void set_brightness(float b) const {
319 LightCommand c;
320 c.key = key_;
321 c.state = true;
322 c.brightness = b;
324 }
325 void set_rgb(const float r, const float g, const float b) const {
326 LightCommand c;
327 c.key = key_;
328 c.state = true;
329 c.rgb = LightRgb{r, g, b};
331 }
332};
333
335class CoverEntity : public TypedEntity<CoverEntity> {
336public:
337 using TypedEntity<CoverEntity>::TypedEntity;
338 [[nodiscard]] static constexpr EntityType type() {
339 return EntityType::Cover;
340 }
341 [[nodiscard]] std::optional<CoverInfo> info() const {
342 return client_->store().cover_info(key_);
343 }
344 [[nodiscard]] std::optional<CoverState> state() const {
345 return client_->store().cover_state(key_);
346 }
347 [[nodiscard]] bool assumed_state() const {
348 const auto i = info();
349 return i ? i->assumed_state : bool{};
350 }
351 [[nodiscard]] bool supports_position() const {
352 const auto i = info();
353 return i ? i->supports_position : bool{};
354 }
355 [[nodiscard]] bool supports_tilt() const {
356 const auto i = info();
357 return i ? i->supports_tilt : bool{};
358 }
359 [[nodiscard]] std::string device_class() const {
360 auto i = info();
361 return i ? i->device_class : std::string{};
362 }
363 [[nodiscard]] bool supports_stop() const {
364 const auto i = info();
365 return i ? i->supports_stop : bool{};
366 }
367 [[nodiscard]] float position() const {
368 const auto s = state();
369 return s ? s->position : float{};
370 }
371 [[nodiscard]] float tilt() const {
372 const auto s = state();
373 return s ? s->tilt : float{};
374 }
375 [[nodiscard]] CoverOperation current_operation() const {
376 const auto s = state();
377 return s ? s->current_operation : CoverOperation{};
378 }
380 void command(CoverCommand c) const {
381 c.key = key_;
383 }
384 void open() const {
385 CoverCommand c;
386 c.key = key_;
387 c.position = 1.0F;
389 }
390 void close() const {
391 CoverCommand c;
392 c.key = key_;
393 c.position = 0.0F;
395 }
396 void stop() const {
397 CoverCommand c;
398 c.key = key_;
399 c.stop = true;
401 }
402 void set_position(float p) const {
403 CoverCommand c;
404 c.key = key_;
405 c.position = p;
407 }
408};
409
411class FanEntity : public ToggleEntity<FanEntity> {
412public:
413 using ToggleEntity<FanEntity>::ToggleEntity;
414 [[nodiscard]] static constexpr EntityType type() {
415 return EntityType::Fan;
416 }
417 [[nodiscard]] std::optional<FanInfo> info() const {
418 return client_->store().fan_info(key_);
419 }
420 [[nodiscard]] std::optional<FanState> state() const {
421 return client_->store().fan_state(key_);
422 }
423 [[nodiscard]] bool supports_oscillation() const {
424 const auto i = info();
425 return i ? i->supports_oscillation : bool{};
426 }
427 [[nodiscard]] bool supports_speed() const {
428 const auto i = info();
429 return i ? i->supports_speed : bool{};
430 }
431 [[nodiscard]] bool supports_direction() const {
432 const auto i = info();
433 return i ? i->supports_direction : bool{};
434 }
435 [[nodiscard]] std::int32_t supported_speed_count() const {
436 const auto i = info();
437 return i ? i->supported_speed_count : std::int32_t{};
438 }
439 [[nodiscard]] std::vector<std::string> supported_preset_modes() const {
440 auto i = info();
441 return i ? i->supported_preset_modes : std::vector<std::string>{};
442 }
443 [[nodiscard]] bool oscillating() const {
444 const auto s = state();
445 return s ? s->oscillating : bool{};
446 }
447 [[nodiscard]] FanDirection direction() const {
448 const auto s = state();
449 return s ? s->direction : FanDirection{};
450 }
451 [[nodiscard]] std::int32_t speed_level() const {
452 const auto s = state();
453 return s ? s->speed_level : std::int32_t{};
454 }
455 [[nodiscard]] std::string preset_mode() const {
456 auto s = state();
457 return s ? s->preset_mode : std::string{};
458 }
460 void command(FanCommand c) const {
461 c.key = key_;
463 }
465 void set_power(bool on) const {
466 FanCommand c;
467 c.key = key_;
468 c.state = on;
470 }
471 void set_speed(std::int32_t level) const {
472 FanCommand c;
473 c.key = key_;
474 c.speed_level = level;
476 }
477};
478
480class ClimateEntity : public TypedEntity<ClimateEntity> {
481public:
482 using TypedEntity<ClimateEntity>::TypedEntity;
483 [[nodiscard]] static constexpr EntityType type() {
484 return EntityType::Climate;
485 }
486 [[nodiscard]] std::optional<ClimateInfo> info() const {
487 return client_->store().climate_info(key_);
488 }
489 [[nodiscard]] std::optional<ClimateState> state() const {
490 return client_->store().climate_state(key_);
491 }
492 [[nodiscard]] std::vector<ClimateMode> supported_modes() const {
493 auto i = info();
494 return i ? i->supported_modes : std::vector<ClimateMode>{};
495 }
496 [[nodiscard]] float visual_min_temperature() const {
497 const auto i = info();
498 return i ? i->visual_min_temperature : float{};
499 }
500 [[nodiscard]] float visual_max_temperature() const {
501 const auto i = info();
502 return i ? i->visual_max_temperature : float{};
503 }
504 [[nodiscard]] float visual_target_temperature_step() const {
505 const auto i = info();
506 return i ? i->visual_target_temperature_step : float{};
507 }
508 [[nodiscard]] std::vector<ClimateFanMode> supported_fan_modes() const {
509 auto i = info();
510 return i ? i->supported_fan_modes : std::vector<ClimateFanMode>{};
511 }
512 [[nodiscard]] std::vector<ClimateSwingMode> supported_swing_modes() const {
513 auto i = info();
514 return i ? i->supported_swing_modes : std::vector<ClimateSwingMode>{};
515 }
516 [[nodiscard]] std::vector<std::string> supported_custom_fan_modes() const {
517 auto i = info();
518 return i ? i->supported_custom_fan_modes : std::vector<std::string>{};
519 }
520 [[nodiscard]] std::vector<ClimatePreset> supported_presets() const {
521 auto i = info();
522 return i ? i->supported_presets : std::vector<ClimatePreset>{};
523 }
524 [[nodiscard]] std::vector<std::string> supported_custom_presets() const {
525 auto i = info();
526 return i ? i->supported_custom_presets : std::vector<std::string>{};
527 }
528 [[nodiscard]] float visual_current_temperature_step() const {
529 const auto i = info();
530 return i ? i->visual_current_temperature_step : float{};
531 }
532 [[nodiscard]] float visual_min_humidity() const {
533 const auto i = info();
534 return i ? i->visual_min_humidity : float{};
535 }
536 [[nodiscard]] float visual_max_humidity() const {
537 const auto i = info();
538 return i ? i->visual_max_humidity : float{};
539 }
540 [[nodiscard]] std::uint32_t feature_flags() const {
541 const auto i = info();
542 return i ? i->feature_flags : std::uint32_t{};
543 }
544 [[nodiscard]] TemperatureUnit temperature_unit() const {
545 const auto i = info();
546 return i ? i->temperature_unit : TemperatureUnit{};
547 }
548 [[nodiscard]] ClimateMode mode() const {
549 const auto s = state();
550 return s ? s->mode : ClimateMode{};
551 }
552 [[nodiscard]] float current_temperature() const {
553 const auto s = state();
554 return s ? s->current_temperature : float{};
555 }
556 [[nodiscard]] float target_temperature() const {
557 const auto s = state();
558 return s ? s->target_temperature : float{};
559 }
560 [[nodiscard]] float target_temperature_low() const {
561 const auto s = state();
562 return s ? s->target_temperature_low : float{};
563 }
564 [[nodiscard]] float target_temperature_high() const {
565 const auto s = state();
566 return s ? s->target_temperature_high : float{};
567 }
568 [[nodiscard]] ClimateAction action() const {
569 const auto s = state();
570 return s ? s->action : ClimateAction{};
571 }
572 [[nodiscard]] ClimateFanMode fan_mode() const {
573 const auto s = state();
574 return s ? s->fan_mode : ClimateFanMode{};
575 }
576 [[nodiscard]] ClimateSwingMode swing_mode() const {
577 const auto s = state();
578 return s ? s->swing_mode : ClimateSwingMode{};
579 }
580 [[nodiscard]] std::string custom_fan_mode() const {
581 auto s = state();
582 return s ? s->custom_fan_mode : std::string{};
583 }
584 [[nodiscard]] ClimatePreset preset() const {
585 const auto s = state();
586 return s ? s->preset : ClimatePreset{};
587 }
588 [[nodiscard]] std::string custom_preset() const {
589 auto s = state();
590 return s ? s->custom_preset : std::string{};
591 }
592 [[nodiscard]] float current_humidity() const {
593 const auto s = state();
594 return s ? s->current_humidity : float{};
595 }
596 [[nodiscard]] float target_humidity() const {
597 const auto s = state();
598 return s ? s->target_humidity : float{};
599 }
601 void command(ClimateCommand c) const {
602 c.key = key_;
604 }
605 void set_mode(ClimateMode m) const {
607 c.key = key_;
608 c.mode = m;
610 }
611 void set_target_temperature(float t) const {
613 c.key = key_;
614 c.target_temperature = t;
616 }
617};
618
620class NumberEntity : public TypedEntity<NumberEntity> {
621public:
622 using TypedEntity<NumberEntity>::TypedEntity;
623 [[nodiscard]] static constexpr EntityType type() {
624 return EntityType::Number;
625 }
626 [[nodiscard]] std::optional<NumberInfo> info() const {
627 return client_->store().number_info(key_);
628 }
629 [[nodiscard]] std::optional<NumberState> state() const {
630 return client_->store().number_state(key_);
631 }
632 [[nodiscard]] float min_value() const {
633 const auto i = info();
634 return i ? i->min_value : float{};
635 }
636 [[nodiscard]] float max_value() const {
637 const auto i = info();
638 return i ? i->max_value : float{};
639 }
640 [[nodiscard]] float step() const {
641 const auto i = info();
642 return i ? i->step : float{};
643 }
644 [[nodiscard]] std::string unit_of_measurement() const {
645 auto i = info();
646 return i ? i->unit_of_measurement : std::string{};
647 }
648 [[nodiscard]] NumberMode mode() const {
649 const auto i = info();
650 return i ? i->mode : NumberMode{};
651 }
652 [[nodiscard]] std::string device_class() const {
653 auto i = info();
654 return i ? i->device_class : std::string{};
655 }
656 [[nodiscard]] bool missing_state() const {
657 const auto s = state();
658 return s ? s->missing_state : bool{};
659 }
661 void command(NumberCommand c) const {
662 c.key = key_;
664 }
665 void set(const float v) const {
667 }
668};
669
671class SelectEntity : public TypedEntity<SelectEntity> {
672public:
673 using TypedEntity<SelectEntity>::TypedEntity;
674 [[nodiscard]] static constexpr EntityType type() {
675 return EntityType::Select;
676 }
677 [[nodiscard]] std::optional<SelectInfo> info() const {
678 return client_->store().select_info(key_);
679 }
680 [[nodiscard]] std::optional<SelectState> state() const {
681 return client_->store().select_state(key_);
682 }
683 [[nodiscard]] std::vector<std::string> options() const {
684 auto i = info();
685 return i ? i->options : std::vector<std::string>{};
686 }
687 [[nodiscard]] bool missing_state() const {
688 const auto s = state();
689 return s ? s->missing_state : bool{};
690 }
692 void command(SelectCommand c) const {
693 c.key = key_;
695 }
696 void set(const std::string& v) const {
698 }
699};
700
702class TextEntity : public TypedEntity<TextEntity> {
703public:
704 using TypedEntity<TextEntity>::TypedEntity;
705 [[nodiscard]] static constexpr EntityType type() {
706 return EntityType::Text;
707 }
708 [[nodiscard]] std::optional<TextInfo> info() const {
709 return client_->store().text_info(key_);
710 }
711 [[nodiscard]] std::optional<TextState> state() const {
712 return client_->store().text_state(key_);
713 }
714 [[nodiscard]] std::uint32_t min_length() const {
715 const auto i = info();
716 return i ? i->min_length : std::uint32_t{};
717 }
718 [[nodiscard]] std::uint32_t max_length() const {
719 const auto i = info();
720 return i ? i->max_length : std::uint32_t{};
721 }
722 [[nodiscard]] std::string pattern() const {
723 auto i = info();
724 return i ? i->pattern : std::string{};
725 }
726 [[nodiscard]] TextMode mode() const {
727 const auto i = info();
728 return i ? i->mode : TextMode{};
729 }
730 [[nodiscard]] bool missing_state() const {
731 const auto s = state();
732 return s ? s->missing_state : bool{};
733 }
735 void command(TextCommand c) const {
736 c.key = key_;
738 }
739 void set(const std::string& v) const {
741 }
742};
743
745class ButtonEntity : public TypedEntity<ButtonEntity> {
746public:
747 using TypedEntity<ButtonEntity>::TypedEntity;
748 [[nodiscard]] static constexpr EntityType type() {
749 return EntityType::Button;
750 }
751 [[nodiscard]] std::optional<ButtonInfo> info() const {
752 return client_->store().button_info(key_);
753 }
754 [[nodiscard]] std::string device_class() const {
755 auto i = info();
756 return i ? i->device_class : std::string{};
757 }
759 void command(ButtonCommand c) const {
760 c.key = key_;
762 }
763 void press() const {
765 }
766};
767
769class LockEntity : public TypedEntity<LockEntity> {
770public:
771 using TypedEntity<LockEntity>::TypedEntity;
772 [[nodiscard]] static constexpr EntityType type() {
773 return EntityType::Lock;
774 }
775 [[nodiscard]] std::optional<LockInfo> info() const {
776 return client_->store().lock_info(key_);
777 }
778 [[nodiscard]] std::optional<LockEntityState> state() const {
779 return client_->store().lock_state(key_);
780 }
781 [[nodiscard]] bool assumed_state() const {
782 const auto i = info();
783 return i ? i->assumed_state : bool{};
784 }
785 [[nodiscard]] bool supports_open() const {
786 const auto i = info();
787 return i ? i->supports_open : bool{};
788 }
789 [[nodiscard]] bool requires_code() const {
790 const auto i = info();
791 return i ? i->requires_code : bool{};
792 }
793 [[nodiscard]] std::string code_format() const {
794 auto i = info();
795 return i ? i->code_format : std::string{};
796 }
798 void command(LockCommandData c) const {
799 c.key = key_;
801 }
802 void lock() const {
804 c.key = key_;
807 }
808 void unlock() const {
810 c.key = key_;
813 }
814 void open() const {
816 c.key = key_;
819 }
820};
821
823class MediaPlayerEntity : public TypedEntity<MediaPlayerEntity> {
824public:
825 using TypedEntity<MediaPlayerEntity>::TypedEntity;
826 [[nodiscard]] static constexpr EntityType type() {
828 }
829 [[nodiscard]] std::optional<MediaPlayerInfo> info() const {
831 }
832 [[nodiscard]] std::optional<MediaPlayerStatus> state() const {
834 }
835 [[nodiscard]] bool supports_pause() const {
836 const auto i = info();
837 return i ? i->supports_pause : bool{};
838 }
839 [[nodiscard]] std::vector<MediaPlayerSupportedFormat> supported_formats() const {
840 auto i = info();
841 return i ? i->supported_formats : std::vector<MediaPlayerSupportedFormat>{};
842 }
843 [[nodiscard]] float volume() const {
844 const auto s = state();
845 return s ? s->volume : float{};
846 }
847 [[nodiscard]] bool muted() const {
848 const auto s = state();
849 return s ? s->muted : bool{};
850 }
853 c.key = key_;
855 }
856 void play() const {
858 c.key = key_;
861 }
862 void pause() const {
864 c.key = key_;
867 }
868 void stop() const {
870 c.key = key_;
873 }
874 void set_volume(float v) const {
876 c.key = key_;
877 c.volume = v;
879 }
880};
881
883class CameraEntity : public TypedEntity<CameraEntity> {
884public:
885 using TypedEntity<CameraEntity>::TypedEntity;
886 [[nodiscard]] static constexpr EntityType type() {
887 return EntityType::Camera;
888 }
889 [[nodiscard]] std::optional<CameraInfo> info() const {
890 return client_->store().camera_info(key_);
891 }
893 void request_image(const bool single = true, const bool stream = false) const {
894 request_camera_image(*client_, single, stream);
895 }
896};
897
899class SirenEntity : public ToggleEntity<SirenEntity> {
900public:
901 using ToggleEntity<SirenEntity>::ToggleEntity;
902 [[nodiscard]] static constexpr EntityType type() {
903 return EntityType::Siren;
904 }
905 [[nodiscard]] std::optional<SirenInfo> info() const {
906 return client_->store().siren_info(key_);
907 }
908 [[nodiscard]] std::optional<SirenState> state() const {
909 return client_->store().siren_state(key_);
910 }
911 [[nodiscard]] std::vector<std::string> tones() const {
912 auto i = info();
913 return i ? i->tones : std::vector<std::string>{};
914 }
915 [[nodiscard]] bool supports_duration() const {
916 const auto i = info();
917 return i ? i->supports_duration : bool{};
918 }
919 [[nodiscard]] bool supports_volume() const {
920 const auto i = info();
921 return i ? i->supports_volume : bool{};
922 }
924 void command(SirenCommand c) const {
925 c.key = key_;
927 }
929 void set_power(bool on) const {
930 SirenCommand c;
931 c.key = key_;
932 c.state = on;
934 }
935};
936
938class AlarmControlPanelEntity : public TypedEntity<AlarmControlPanelEntity> {
939public:
940 using TypedEntity<AlarmControlPanelEntity>::TypedEntity;
941 [[nodiscard]] static constexpr EntityType type() {
943 }
944 [[nodiscard]] std::optional<AlarmControlPanelInfo> info() const {
946 }
947 [[nodiscard]] std::optional<AlarmControlPanelStatus> state() const {
949 }
950 [[nodiscard]] std::uint32_t supported_features() const {
951 const auto i = info();
952 return i ? i->supported_features : std::uint32_t{};
953 }
954 [[nodiscard]] bool requires_code() const {
955 const auto i = info();
956 return i ? i->requires_code : bool{};
957 }
958 [[nodiscard]] bool requires_code_to_arm() const {
959 const auto i = info();
960 return i ? i->requires_code_to_arm : bool{};
961 }
964 c.key = key_;
966 }
967 void disarm(const std::string& code = {}) const {
970 }
971 void arm_away(const std::string& code = {}) const {
974 }
975 void arm_home(const std::string& code = {}) const {
978 }
979};
980
982class DateEntity : public TypedEntity<DateEntity> {
983public:
984 using TypedEntity<DateEntity>::TypedEntity;
985 [[nodiscard]] static constexpr EntityType type() {
986 return EntityType::Date;
987 }
988 [[nodiscard]] std::optional<DateInfo> info() const {
989 return client_->store().date_info(key_);
990 }
991 [[nodiscard]] std::optional<DateState> state() const {
992 return client_->store().date_state(key_);
993 }
994 [[nodiscard]] bool missing_state() const {
995 const auto s = state();
996 return s ? s->missing_state : bool{};
997 }
998 [[nodiscard]] std::uint32_t year() const {
999 const auto s = state();
1000 return s ? s->year : std::uint32_t{};
1001 }
1002 [[nodiscard]] std::uint32_t month() const {
1003 const auto s = state();
1004 return s ? s->month : std::uint32_t{};
1005 }
1006 [[nodiscard]] std::uint32_t day() const {
1007 const auto s = state();
1008 return s ? s->day : std::uint32_t{};
1009 }
1011 void command(DateCommand c) const {
1012 c.key = key_;
1013 send_command(*client_, c);
1014 }
1015 void set(const std::uint32_t year, const std::uint32_t month, const std::uint32_t day) const {
1017 }
1018};
1019
1021class TimeEntity : public TypedEntity<TimeEntity> {
1022public:
1023 using TypedEntity<TimeEntity>::TypedEntity;
1024 [[nodiscard]] static constexpr EntityType type() {
1025 return EntityType::Time;
1026 }
1027 [[nodiscard]] std::optional<TimeInfo> info() const {
1028 return client_->store().time_info(key_);
1029 }
1030 [[nodiscard]] std::optional<TimeState> state() const {
1031 return client_->store().time_state(key_);
1032 }
1033 [[nodiscard]] bool missing_state() const {
1034 const auto s = state();
1035 return s ? s->missing_state : bool{};
1036 }
1037 [[nodiscard]] std::uint32_t hour() const {
1038 const auto s = state();
1039 return s ? s->hour : std::uint32_t{};
1040 }
1041 [[nodiscard]] std::uint32_t minute() const {
1042 const auto s = state();
1043 return s ? s->minute : std::uint32_t{};
1044 }
1045 [[nodiscard]] std::uint32_t second() const {
1046 const auto s = state();
1047 return s ? s->second : std::uint32_t{};
1048 }
1050 void command(TimeCommand c) const {
1051 c.key = key_;
1052 send_command(*client_, c);
1053 }
1054 void
1055 set(const std::uint32_t hour, const std::uint32_t minute, const std::uint32_t second) const {
1057 }
1058};
1059
1061class DateTimeEntity : public TypedEntity<DateTimeEntity> {
1062public:
1063 using TypedEntity<DateTimeEntity>::TypedEntity;
1064 [[nodiscard]] static constexpr EntityType type() {
1065 return EntityType::DateTime;
1066 }
1067 [[nodiscard]] std::optional<DateTimeInfo> info() const {
1068 return client_->store().datetime_info(key_);
1069 }
1070 [[nodiscard]] std::optional<DateTimeState> state() const {
1071 return client_->store().datetime_state(key_);
1072 }
1073 [[nodiscard]] bool missing_state() const {
1074 const auto s = state();
1075 return s ? s->missing_state : bool{};
1076 }
1077 [[nodiscard]] std::uint32_t epoch_seconds() const {
1078 const auto s = state();
1079 return s ? s->epoch_seconds : std::uint32_t{};
1080 }
1082 void command(DateTimeCommand c) const {
1083 c.key = key_;
1084 send_command(*client_, c);
1085 }
1086 void set(const std::uint32_t epoch_seconds) const {
1088 }
1089};
1090
1092class ValveEntity : public TypedEntity<ValveEntity> {
1093public:
1094 using TypedEntity<ValveEntity>::TypedEntity;
1095 [[nodiscard]] static constexpr EntityType type() {
1096 return EntityType::Valve;
1097 }
1098 [[nodiscard]] std::optional<ValveInfo> info() const {
1099 return client_->store().valve_info(key_);
1100 }
1101 [[nodiscard]] std::optional<ValveState> state() const {
1102 return client_->store().valve_state(key_);
1103 }
1104 [[nodiscard]] std::string device_class() const {
1105 auto i = info();
1106 return i ? i->device_class : std::string{};
1107 }
1108 [[nodiscard]] bool assumed_state() const {
1109 const auto i = info();
1110 return i ? i->assumed_state : bool{};
1111 }
1112 [[nodiscard]] bool supports_position() const {
1113 const auto i = info();
1114 return i ? i->supports_position : bool{};
1115 }
1116 [[nodiscard]] bool supports_stop() const {
1117 const auto i = info();
1118 return i ? i->supports_stop : bool{};
1119 }
1120 [[nodiscard]] float position() const {
1121 const auto s = state();
1122 return s ? s->position : float{};
1123 }
1124 [[nodiscard]] ValveOperation current_operation() const {
1125 const auto s = state();
1126 return s ? s->current_operation : ValveOperation{};
1127 }
1129 void command(ValveCommand c) const {
1130 c.key = key_;
1131 send_command(*client_, c);
1132 }
1133 void open() const {
1134 ValveCommand c;
1135 c.key = key_;
1136 c.position = 1.0F;
1137 send_command(*client_, c);
1138 }
1139 void close() const {
1140 ValveCommand c;
1141 c.key = key_;
1142 c.position = 0.0F;
1143 send_command(*client_, c);
1144 }
1145 void stop() const {
1146 ValveCommand c;
1147 c.key = key_;
1148 c.stop = true;
1149 send_command(*client_, c);
1150 }
1151};
1152
1154class EventEntity : public TypedEntity<EventEntity> {
1155public:
1156 using TypedEntity<EventEntity>::TypedEntity;
1157 [[nodiscard]] static constexpr EntityType type() {
1158 return EntityType::Event;
1159 }
1160 [[nodiscard]] std::optional<EventInfo> info() const {
1161 return client_->store().event_info(key_);
1162 }
1163 [[nodiscard]] std::optional<EventState> state() const {
1164 return client_->store().event_state(key_);
1165 }
1166 [[nodiscard]] std::string device_class() const {
1167 auto i = info();
1168 return i ? i->device_class : std::string{};
1169 }
1170 [[nodiscard]] std::vector<std::string> event_types() const {
1171 auto i = info();
1172 return i ? i->event_types : std::vector<std::string>{};
1173 }
1174 [[nodiscard]] std::string event_type() const {
1175 auto s = state();
1176 return s ? s->event_type : std::string{};
1177 }
1178};
1179
1181class UpdateEntity : public TypedEntity<UpdateEntity> {
1182public:
1183 using TypedEntity<UpdateEntity>::TypedEntity;
1184 [[nodiscard]] static constexpr EntityType type() {
1185 return EntityType::Update;
1186 }
1187 [[nodiscard]] std::optional<UpdateInfo> info() const {
1188 return client_->store().update_info(key_);
1189 }
1190 [[nodiscard]] std::optional<UpdateState> state() const {
1191 return client_->store().update_state(key_);
1192 }
1193 [[nodiscard]] std::string device_class() const {
1194 auto i = info();
1195 return i ? i->device_class : std::string{};
1196 }
1197 [[nodiscard]] bool missing_state() const {
1198 const auto s = state();
1199 return s ? s->missing_state : bool{};
1200 }
1201 [[nodiscard]] bool in_progress() const {
1202 const auto s = state();
1203 return s ? s->in_progress : bool{};
1204 }
1205 [[nodiscard]] bool has_progress() const {
1206 const auto s = state();
1207 return s ? s->has_progress : bool{};
1208 }
1209 [[nodiscard]] float progress() const {
1210 const auto s = state();
1211 return s ? s->progress : float{};
1212 }
1213 [[nodiscard]] std::string current_version() const {
1214 auto s = state();
1215 return s ? s->current_version : std::string{};
1216 }
1217 [[nodiscard]] std::string latest_version() const {
1218 auto s = state();
1219 return s ? s->latest_version : std::string{};
1220 }
1221 [[nodiscard]] std::string title() const {
1222 auto s = state();
1223 return s ? s->title : std::string{};
1224 }
1225 [[nodiscard]] std::string release_summary() const {
1226 auto s = state();
1227 return s ? s->release_summary : std::string{};
1228 }
1229 [[nodiscard]] std::string release_url() const {
1230 auto s = state();
1231 return s ? s->release_url : std::string{};
1232 }
1234 void command(UpdateControl c) const {
1235 c.key = key_;
1236 send_command(*client_, c);
1237 }
1244};
1245
1247class WaterHeaterEntity : public TypedEntity<WaterHeaterEntity> {
1248public:
1249 using TypedEntity<WaterHeaterEntity>::TypedEntity;
1250 [[nodiscard]] static constexpr EntityType type() {
1252 }
1253 [[nodiscard]] std::optional<WaterHeaterInfo> info() const {
1255 }
1256 [[nodiscard]] std::optional<WaterHeaterState> state() const {
1258 }
1259 [[nodiscard]] float min_temperature() const {
1260 const auto i = info();
1261 return i ? i->min_temperature : float{};
1262 }
1263 [[nodiscard]] float max_temperature() const {
1264 const auto i = info();
1265 return i ? i->max_temperature : float{};
1266 }
1267 [[nodiscard]] float target_temperature_step() const {
1268 const auto i = info();
1269 return i ? i->target_temperature_step : float{};
1270 }
1271 [[nodiscard]] std::vector<WaterHeaterMode> supported_modes() const {
1272 auto i = info();
1273 return i ? i->supported_modes : std::vector<WaterHeaterMode>{};
1274 }
1275 [[nodiscard]] std::uint32_t supported_features() const {
1276 const auto i = info();
1277 return i ? i->supported_features : std::uint32_t{};
1278 }
1279 [[nodiscard]] TemperatureUnit temperature_unit() const {
1280 const auto i = info();
1281 return i ? i->temperature_unit : TemperatureUnit{};
1282 }
1283 [[nodiscard]] float current_temperature() const {
1284 const auto s = state();
1285 return s ? s->current_temperature : float{};
1286 }
1287 [[nodiscard]] float target_temperature() const {
1288 const auto s = state();
1289 return s ? s->target_temperature : float{};
1290 }
1291 [[nodiscard]] WaterHeaterMode mode() const {
1292 const auto s = state();
1293 return s ? s->mode : WaterHeaterMode{};
1294 }
1295 [[nodiscard]] float target_temperature_low() const {
1296 const auto s = state();
1297 return s ? s->target_temperature_low : float{};
1298 }
1299 [[nodiscard]] float target_temperature_high() const {
1300 const auto s = state();
1301 return s ? s->target_temperature_high : float{};
1302 }
1305 c.key = key_;
1306 send_command(*client_, c);
1307 }
1308};
1309
1311class InfraredEntity : public TypedEntity<InfraredEntity> {
1312public:
1313 using TypedEntity<InfraredEntity>::TypedEntity;
1314 [[nodiscard]] static constexpr EntityType type() {
1315 return EntityType::Infrared;
1316 }
1317 [[nodiscard]] std::optional<InfraredInfo> info() const {
1318 return client_->store().infrared_info(key_);
1319 }
1320 [[nodiscard]] std::uint32_t capabilities() const {
1321 const auto i = info();
1322 return i ? i->capabilities : std::uint32_t{};
1323 }
1324 [[nodiscard]] std::uint32_t receiver_frequency() const {
1325 const auto i = info();
1326 return i ? i->receiver_frequency : std::uint32_t{};
1327 }
1328};
1329
1331class RadioFrequencyEntity : public TypedEntity<RadioFrequencyEntity> {
1332public:
1333 using TypedEntity<RadioFrequencyEntity>::TypedEntity;
1334 [[nodiscard]] static constexpr EntityType type() {
1336 }
1337 [[nodiscard]] std::optional<RadioFrequencyInfo> info() const {
1339 }
1340 [[nodiscard]] std::uint32_t capabilities() const {
1341 const auto i = info();
1342 return i ? i->capabilities : std::uint32_t{};
1343 }
1344 [[nodiscard]] std::uint32_t frequency_min() const {
1345 const auto i = info();
1346 return i ? i->frequency_min : std::uint32_t{};
1347 }
1348 [[nodiscard]] std::uint32_t frequency_max() const {
1349 const auto i = info();
1350 return i ? i->frequency_max : std::uint32_t{};
1351 }
1352 [[nodiscard]] std::uint32_t supported_modulations() const {
1353 const auto i = info();
1354 return i ? i->supported_modulations : std::uint32_t{};
1355 }
1356};
1357
1358} // namespace esphome::api
Handle to a AlarmControlPanel entity.
Definition entity_handles.hpp:938
void arm_away(const std::string &code={}) const
Definition entity_handles.hpp:971
bool requires_code() const
Definition entity_handles.hpp:954
std::optional< AlarmControlPanelInfo > info() const
Definition entity_handles.hpp:944
void command(AlarmControlPanelCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:963
void arm_home(const std::string &code={}) const
Definition entity_handles.hpp:975
bool requires_code_to_arm() const
Definition entity_handles.hpp:958
std::optional< AlarmControlPanelStatus > state() const
Definition entity_handles.hpp:947
static constexpr EntityType type()
Definition entity_handles.hpp:941
void disarm(const std::string &code={}) const
Definition entity_handles.hpp:967
std::uint32_t supported_features() const
Definition entity_handles.hpp:950
Handle to a BinarySensor entity.
Definition entity_handles.hpp:95
std::optional< BinarySensorInfo > info() const
Definition entity_handles.hpp:101
static constexpr EntityType type()
Definition entity_handles.hpp:98
std::optional< BinarySensorState > state() const
Definition entity_handles.hpp:104
bool is_status_binary_sensor() const
Definition entity_handles.hpp:111
bool is_on() const
Whether the sensor currently reads active.
Definition entity_handles.hpp:120
std::string device_class() const
Definition entity_handles.hpp:107
bool missing_state() const
Definition entity_handles.hpp:115
Handle to a Button entity.
Definition entity_handles.hpp:745
std::optional< ButtonInfo > info() const
Definition entity_handles.hpp:751
void press() const
Definition entity_handles.hpp:763
std::string device_class() const
Definition entity_handles.hpp:754
void command(ButtonCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:759
static constexpr EntityType type()
Definition entity_handles.hpp:748
Handle to a Camera entity.
Definition entity_handles.hpp:883
void request_image(const bool single=true, const bool stream=false) const
Request a still image (single) or start a stream.
Definition entity_handles.hpp:893
static constexpr EntityType type()
Definition entity_handles.hpp:886
std::optional< CameraInfo > info() const
Definition entity_handles.hpp:889
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).
Handle to a Climate entity.
Definition entity_handles.hpp:480
std::uint32_t feature_flags() const
Definition entity_handles.hpp:540
float target_temperature_low() const
Definition entity_handles.hpp:560
float target_temperature_high() const
Definition entity_handles.hpp:564
ClimateAction action() const
Definition entity_handles.hpp:568
std::vector< ClimateFanMode > supported_fan_modes() const
Definition entity_handles.hpp:508
float current_temperature() const
Definition entity_handles.hpp:552
std::string custom_fan_mode() const
Definition entity_handles.hpp:580
ClimateSwingMode swing_mode() const
Definition entity_handles.hpp:576
std::vector< std::string > supported_custom_presets() const
Definition entity_handles.hpp:524
std::vector< std::string > supported_custom_fan_modes() const
Definition entity_handles.hpp:516
void set_target_temperature(float t) const
Definition entity_handles.hpp:611
float target_temperature() const
Definition entity_handles.hpp:556
float target_humidity() const
Definition entity_handles.hpp:596
float current_humidity() const
Definition entity_handles.hpp:592
std::vector< ClimateSwingMode > supported_swing_modes() const
Definition entity_handles.hpp:512
std::optional< ClimateState > state() const
Definition entity_handles.hpp:489
static constexpr EntityType type()
Definition entity_handles.hpp:483
ClimatePreset preset() const
Definition entity_handles.hpp:584
ClimateMode mode() const
Definition entity_handles.hpp:548
float visual_target_temperature_step() const
Definition entity_handles.hpp:504
float visual_current_temperature_step() const
Definition entity_handles.hpp:528
std::vector< ClimatePreset > supported_presets() const
Definition entity_handles.hpp:520
ClimateFanMode fan_mode() const
Definition entity_handles.hpp:572
std::vector< ClimateMode > supported_modes() const
Definition entity_handles.hpp:492
float visual_min_temperature() const
Definition entity_handles.hpp:496
float visual_max_temperature() const
Definition entity_handles.hpp:500
float visual_min_humidity() const
Definition entity_handles.hpp:532
void command(ClimateCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:601
float visual_max_humidity() const
Definition entity_handles.hpp:536
std::optional< ClimateInfo > info() const
Definition entity_handles.hpp:486
std::string custom_preset() const
Definition entity_handles.hpp:588
TemperatureUnit temperature_unit() const
Definition entity_handles.hpp:544
void set_mode(ClimateMode m) const
Definition entity_handles.hpp:605
Handle to a Cover entity.
Definition entity_handles.hpp:335
float position() const
Definition entity_handles.hpp:367
void open() const
Definition entity_handles.hpp:384
bool supports_tilt() const
Definition entity_handles.hpp:355
void stop() const
Definition entity_handles.hpp:396
bool supports_position() const
Definition entity_handles.hpp:351
void close() const
Definition entity_handles.hpp:390
bool supports_stop() const
Definition entity_handles.hpp:363
std::string device_class() const
Definition entity_handles.hpp:359
static constexpr EntityType type()
Definition entity_handles.hpp:338
std::optional< CoverInfo > info() const
Definition entity_handles.hpp:341
void command(CoverCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:380
CoverOperation current_operation() const
Definition entity_handles.hpp:375
bool assumed_state() const
Definition entity_handles.hpp:347
std::optional< CoverState > state() const
Definition entity_handles.hpp:344
void set_position(float p) const
Definition entity_handles.hpp:402
float tilt() const
Definition entity_handles.hpp:371
Handle to a Date entity.
Definition entity_handles.hpp:982
std::optional< DateState > state() const
Definition entity_handles.hpp:991
std::uint32_t month() const
Definition entity_handles.hpp:1002
bool missing_state() const
Definition entity_handles.hpp:994
std::uint32_t day() const
Definition entity_handles.hpp:1006
std::uint32_t year() const
Definition entity_handles.hpp:998
void command(DateCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:1011
static constexpr EntityType type()
Definition entity_handles.hpp:985
std::optional< DateInfo > info() const
Definition entity_handles.hpp:988
void set(const std::uint32_t year, const std::uint32_t month, const std::uint32_t day) const
Definition entity_handles.hpp:1015
Handle to a DateTime entity.
Definition entity_handles.hpp:1061
std::optional< DateTimeInfo > info() const
Definition entity_handles.hpp:1067
std::optional< DateTimeState > state() const
Definition entity_handles.hpp:1070
static constexpr EntityType type()
Definition entity_handles.hpp:1064
void command(DateTimeCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:1082
bool missing_state() const
Definition entity_handles.hpp:1073
std::uint32_t epoch_seconds() const
Definition entity_handles.hpp:1077
void set(const std::uint32_t epoch_seconds) const
Definition entity_handles.hpp:1086
std::optional< BinarySensorInfo > binary_sensor_info(std::uint32_t key) const
std::optional< SelectInfo > select_info(std::uint32_t key) const
std::optional< WaterHeaterState > water_heater_state(std::uint32_t key) const
std::optional< AlarmControlPanelInfo > alarm_control_panel_info(std::uint32_t key) const
std::optional< DateTimeInfo > datetime_info(std::uint32_t key) const
std::optional< LockEntityState > lock_state(std::uint32_t key) const
std::optional< ClimateState > climate_state(std::uint32_t key) const
std::optional< LightInfo > light_info(std::uint32_t key) const
std::optional< TimeInfo > time_info(std::uint32_t key) const
std::optional< CoverInfo > cover_info(std::uint32_t key) const
std::optional< TextState > text_state(std::uint32_t key) const
std::optional< SirenInfo > siren_info(std::uint32_t key) const
std::optional< MediaPlayerStatus > media_player_state(std::uint32_t key) const
std::optional< CameraInfo > camera_info(std::uint32_t key) const
std::optional< AlarmControlPanelStatus > alarm_control_panel_state(std::uint32_t key) const
std::optional< EventInfo > event_info(std::uint32_t key) const
std::optional< DateTimeState > datetime_state(std::uint32_t key) const
std::optional< RadioFrequencyInfo > radio_frequency_info(std::uint32_t key) const
std::optional< LockInfo > lock_info(std::uint32_t key) const
std::optional< ClimateInfo > climate_info(std::uint32_t key) const
std::optional< MediaPlayerInfo > media_player_info(std::uint32_t key) const
std::optional< EventState > event_state(std::uint32_t key) const
std::optional< CoverState > cover_state(std::uint32_t key) const
std::optional< FanState > fan_state(std::uint32_t key) const
std::optional< WaterHeaterInfo > water_heater_info(std::uint32_t key) const
std::optional< SwitchInfo > switch_info(std::uint32_t key) const
std::optional< ValveInfo > valve_info(std::uint32_t key) const
std::optional< SensorState > sensor_state(std::uint32_t key) const
std::optional< UpdateInfo > update_info(std::uint32_t key) const
std::optional< DateInfo > date_info(std::uint32_t key) const
std::optional< SensorInfo > sensor_info(std::uint32_t key) const
std::optional< TimeState > time_state(std::uint32_t key) const
std::optional< DateState > date_state(std::uint32_t key) const
std::optional< TextInfo > text_info(std::uint32_t key) const
std::optional< NumberState > number_state(std::uint32_t key) const
std::optional< ButtonInfo > button_info(std::uint32_t key) const
std::optional< TextSensorState > text_sensor_state(std::uint32_t key) const
std::optional< ValveState > valve_state(std::uint32_t key) const
std::optional< LightState > light_state(std::uint32_t key) const
std::optional< SwitchState > switch_state(std::uint32_t key) const
std::optional< TextSensorInfo > text_sensor_info(std::uint32_t key) const
std::optional< NumberInfo > number_info(std::uint32_t key) const
std::optional< UpdateState > update_state(std::uint32_t key) const
std::optional< SelectState > select_state(std::uint32_t key) const
std::optional< BinarySensorState > binary_sensor_state(std::uint32_t key) const
std::optional< SirenState > siren_state(std::uint32_t key) const
std::optional< InfraredInfo > infrared_info(std::uint32_t key) const
std::optional< FanInfo > fan_info(std::uint32_t key) const
Common base: entity identity and the owning client.
Definition entity_handles.hpp:25
Client * client_
Definition entity_handles.hpp:40
std::string name_
Definition entity_handles.hpp:43
std::uint32_t key() const noexcept
Definition entity_handles.hpp:29
std::string object_id_
Definition entity_handles.hpp:42
const std::string & object_id() const noexcept
Definition entity_handles.hpp:32
Entity(Client &client, const std::uint32_t key, std::string object_id, std::string name)
Definition entity_handles.hpp:27
std::uint32_t key_
Definition entity_handles.hpp:41
const std::string & name() const noexcept
Definition entity_handles.hpp:35
Handle to a Event entity.
Definition entity_handles.hpp:1154
static constexpr EntityType type()
Definition entity_handles.hpp:1157
std::vector< std::string > event_types() const
Definition entity_handles.hpp:1170
std::optional< EventState > state() const
Definition entity_handles.hpp:1163
std::optional< EventInfo > info() const
Definition entity_handles.hpp:1160
std::string device_class() const
Definition entity_handles.hpp:1166
std::string event_type() const
Definition entity_handles.hpp:1174
Handle to a Fan entity.
Definition entity_handles.hpp:411
std::optional< FanState > state() const
Definition entity_handles.hpp:420
bool oscillating() const
Definition entity_handles.hpp:443
bool supports_oscillation() const
Definition entity_handles.hpp:423
bool supports_speed() const
Definition entity_handles.hpp:427
void set_power(bool on) const
Set on/off power (used by turn_on/turn_off/toggle).
Definition entity_handles.hpp:465
std::optional< FanInfo > info() const
Definition entity_handles.hpp:417
bool supports_direction() const
Definition entity_handles.hpp:431
std::int32_t supported_speed_count() const
Definition entity_handles.hpp:435
void set_speed(std::int32_t level) const
Definition entity_handles.hpp:471
std::int32_t speed_level() const
Definition entity_handles.hpp:451
std::string preset_mode() const
Definition entity_handles.hpp:455
FanDirection direction() const
Definition entity_handles.hpp:447
void command(FanCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:460
static constexpr EntityType type()
Definition entity_handles.hpp:414
std::vector< std::string > supported_preset_modes() const
Definition entity_handles.hpp:439
Handle to a Infrared entity.
Definition entity_handles.hpp:1311
std::optional< InfraredInfo > info() const
Definition entity_handles.hpp:1317
std::uint32_t receiver_frequency() const
Definition entity_handles.hpp:1324
std::uint32_t capabilities() const
Definition entity_handles.hpp:1320
static constexpr EntityType type()
Definition entity_handles.hpp:1314
Handle to a Light entity.
Definition entity_handles.hpp:234
std::optional< LightInfo > info() const
Definition entity_handles.hpp:240
float green() const
Definition entity_handles.hpp:278
float white() const
Definition entity_handles.hpp:286
float color_temperature() const
Definition entity_handles.hpp:290
void set_rgb(const float r, const float g, const float b) const
Definition entity_handles.hpp:325
std::optional< LightState > state() const
Definition entity_handles.hpp:243
float cold_white() const
Definition entity_handles.hpp:294
std::vector< ColorMode > supported_color_modes() const
Definition entity_handles.hpp:246
std::string effect() const
Definition entity_handles.hpp:302
void set_brightness(float b) const
Definition entity_handles.hpp:318
float brightness() const
Definition entity_handles.hpp:262
float blue() const
Definition entity_handles.hpp:282
float min_mireds() const
Definition entity_handles.hpp:250
ColorMode color_mode() const
Definition entity_handles.hpp:266
float max_mireds() const
Definition entity_handles.hpp:254
float red() const
Definition entity_handles.hpp:274
static constexpr EntityType type()
Definition entity_handles.hpp:237
float color_brightness() const
Definition entity_handles.hpp:270
float warm_white() const
Definition entity_handles.hpp:298
void command(LightCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:307
std::vector< std::string > effects() const
Definition entity_handles.hpp:258
void set_power(bool on) const
Set on/off power (used by turn_on/turn_off/toggle).
Definition entity_handles.hpp:312
Handle to a Lock entity.
Definition entity_handles.hpp:769
void open() const
Definition entity_handles.hpp:814
bool requires_code() const
Definition entity_handles.hpp:789
bool supports_open() const
Definition entity_handles.hpp:785
std::optional< LockEntityState > state() const
Definition entity_handles.hpp:778
void unlock() const
Definition entity_handles.hpp:808
std::optional< LockInfo > info() const
Definition entity_handles.hpp:775
bool assumed_state() const
Definition entity_handles.hpp:781
void lock() const
Definition entity_handles.hpp:802
void command(LockCommandData c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:798
static constexpr EntityType type()
Definition entity_handles.hpp:772
std::string code_format() const
Definition entity_handles.hpp:793
Handle to a MediaPlayer entity.
Definition entity_handles.hpp:823
std::optional< MediaPlayerStatus > state() const
Definition entity_handles.hpp:832
void play() const
Definition entity_handles.hpp:856
std::vector< MediaPlayerSupportedFormat > supported_formats() const
Definition entity_handles.hpp:839
float volume() const
Definition entity_handles.hpp:843
std::optional< MediaPlayerInfo > info() const
Definition entity_handles.hpp:829
void stop() const
Definition entity_handles.hpp:868
static constexpr EntityType type()
Definition entity_handles.hpp:826
void command(MediaPlayerControl c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:852
void set_volume(float v) const
Definition entity_handles.hpp:874
bool muted() const
Definition entity_handles.hpp:847
bool supports_pause() const
Definition entity_handles.hpp:835
void pause() const
Definition entity_handles.hpp:862
Handle to a Number entity.
Definition entity_handles.hpp:620
NumberMode mode() const
Definition entity_handles.hpp:648
float max_value() const
Definition entity_handles.hpp:636
std::string device_class() const
Definition entity_handles.hpp:652
void set(const float v) const
Definition entity_handles.hpp:665
std::optional< NumberInfo > info() const
Definition entity_handles.hpp:626
bool missing_state() const
Definition entity_handles.hpp:656
std::string unit_of_measurement() const
Definition entity_handles.hpp:644
float min_value() const
Definition entity_handles.hpp:632
static constexpr EntityType type()
Definition entity_handles.hpp:623
float step() const
Definition entity_handles.hpp:640
std::optional< NumberState > state() const
Definition entity_handles.hpp:629
void command(NumberCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:661
Handle to a RadioFrequency entity.
Definition entity_handles.hpp:1331
std::uint32_t capabilities() const
Definition entity_handles.hpp:1340
static constexpr EntityType type()
Definition entity_handles.hpp:1334
std::uint32_t supported_modulations() const
Definition entity_handles.hpp:1352
std::uint32_t frequency_min() const
Definition entity_handles.hpp:1344
std::uint32_t frequency_max() const
Definition entity_handles.hpp:1348
std::optional< RadioFrequencyInfo > info() const
Definition entity_handles.hpp:1337
Handle to a Select entity.
Definition entity_handles.hpp:671
void set(const std::string &v) const
Definition entity_handles.hpp:696
void command(SelectCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:692
std::optional< SelectInfo > info() const
Definition entity_handles.hpp:677
std::vector< std::string > options() const
Definition entity_handles.hpp:683
std::optional< SelectState > state() const
Definition entity_handles.hpp:680
bool missing_state() const
Definition entity_handles.hpp:687
static constexpr EntityType type()
Definition entity_handles.hpp:674
Handle to a Sensor entity.
Definition entity_handles.hpp:127
std::int32_t accuracy_decimals() const
Definition entity_handles.hpp:143
static constexpr EntityType type()
Definition entity_handles.hpp:130
std::string unit_of_measurement() const
Definition entity_handles.hpp:139
std::optional< SensorState > state() const
Definition entity_handles.hpp:136
std::optional< SensorInfo > info() const
Definition entity_handles.hpp:133
bool missing_state() const
Definition entity_handles.hpp:159
SensorStateClass state_class() const
Definition entity_handles.hpp:155
bool force_update() const
Definition entity_handles.hpp:147
bool has_value() const
Definition entity_handles.hpp:168
float value() const
Latest numeric value (0 if unknown).
Definition entity_handles.hpp:164
std::string device_class() const
Definition entity_handles.hpp:151
Handle to a Siren entity.
Definition entity_handles.hpp:899
static constexpr EntityType type()
Definition entity_handles.hpp:902
std::optional< SirenState > state() const
Definition entity_handles.hpp:908
std::optional< SirenInfo > info() const
Definition entity_handles.hpp:905
std::vector< std::string > tones() const
Definition entity_handles.hpp:911
bool supports_volume() const
Definition entity_handles.hpp:919
bool supports_duration() const
Definition entity_handles.hpp:915
void command(SirenCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:924
void set_power(bool on) const
Set on/off power (used by turn_on/turn_off/toggle).
Definition entity_handles.hpp:929
Handle to a Switch entity.
Definition entity_handles.hpp:202
std::optional< SwitchState > state() const
Definition entity_handles.hpp:211
static constexpr EntityType type()
Definition entity_handles.hpp:205
void set_power(const bool on) const
Set on/off power (used by turn_on/turn_off/toggle).
Definition entity_handles.hpp:228
std::string device_class() const
Definition entity_handles.hpp:218
bool assumed_state() const
Definition entity_handles.hpp:214
void command(SwitchCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:223
std::optional< SwitchInfo > info() const
Definition entity_handles.hpp:208
Handle to a Text entity.
Definition entity_handles.hpp:702
void set(const std::string &v) const
Definition entity_handles.hpp:739
std::uint32_t min_length() const
Definition entity_handles.hpp:714
TextMode mode() const
Definition entity_handles.hpp:726
std::uint32_t max_length() const
Definition entity_handles.hpp:718
std::optional< TextState > state() const
Definition entity_handles.hpp:711
std::optional< TextInfo > info() const
Definition entity_handles.hpp:708
std::string pattern() const
Definition entity_handles.hpp:722
bool missing_state() const
Definition entity_handles.hpp:730
static constexpr EntityType type()
Definition entity_handles.hpp:705
void command(TextCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:735
Handle to a TextSensor entity.
Definition entity_handles.hpp:175
std::optional< TextSensorInfo > info() const
Definition entity_handles.hpp:181
std::string text() const
Definition entity_handles.hpp:195
bool missing_state() const
Definition entity_handles.hpp:191
static constexpr EntityType type()
Definition entity_handles.hpp:178
std::optional< TextSensorState > state() const
Definition entity_handles.hpp:184
std::string device_class() const
Definition entity_handles.hpp:187
Handle to a Time entity.
Definition entity_handles.hpp:1021
std::uint32_t hour() const
Definition entity_handles.hpp:1037
std::optional< TimeInfo > info() const
Definition entity_handles.hpp:1027
std::optional< TimeState > state() const
Definition entity_handles.hpp:1030
void command(TimeCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:1050
std::uint32_t second() const
Definition entity_handles.hpp:1045
std::uint32_t minute() const
Definition entity_handles.hpp:1041
bool missing_state() const
Definition entity_handles.hpp:1033
static constexpr EntityType type()
Definition entity_handles.hpp:1024
void set(const std::uint32_t hour, const std::uint32_t minute, const std::uint32_t second) const
Definition entity_handles.hpp:1055
Adds on/off helpers. Derived must provide state() (bool state) and set_power(bool).
Definition entity_handles.hpp:76
void turn_on()
Definition entity_handles.hpp:83
void toggle()
Definition entity_handles.hpp:89
bool is_on() const
Definition entity_handles.hpp:79
void turn_off()
Definition entity_handles.hpp:86
Adds the shared EntityInfo accessors, reading from Derived::info().
Definition entity_handles.hpp:48
bool disabled_by_default() const
Definition entity_handles.hpp:55
std::uint32_t device_id() const
Definition entity_handles.hpp:63
std::string icon() const
Definition entity_handles.hpp:51
EntityCategory entity_category() const
Definition entity_handles.hpp:59
Handle to a Update entity.
Definition entity_handles.hpp:1181
std::string device_class() const
Definition entity_handles.hpp:1193
bool missing_state() const
Definition entity_handles.hpp:1197
std::string release_summary() const
Definition entity_handles.hpp:1225
std::string release_url() const
Definition entity_handles.hpp:1229
void install() const
Definition entity_handles.hpp:1238
std::string title() const
Definition entity_handles.hpp:1221
bool has_progress() const
Definition entity_handles.hpp:1205
static constexpr EntityType type()
Definition entity_handles.hpp:1184
void check() const
Definition entity_handles.hpp:1241
std::optional< UpdateState > state() const
Definition entity_handles.hpp:1190
void command(UpdateControl c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:1234
float progress() const
Definition entity_handles.hpp:1209
std::string latest_version() const
Definition entity_handles.hpp:1217
std::string current_version() const
Definition entity_handles.hpp:1213
bool in_progress() const
Definition entity_handles.hpp:1201
std::optional< UpdateInfo > info() const
Definition entity_handles.hpp:1187
Handle to a Valve entity.
Definition entity_handles.hpp:1092
std::optional< ValveState > state() const
Definition entity_handles.hpp:1101
bool assumed_state() const
Definition entity_handles.hpp:1108
void command(ValveCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:1129
std::string device_class() const
Definition entity_handles.hpp:1104
void open() const
Definition entity_handles.hpp:1133
bool supports_position() const
Definition entity_handles.hpp:1112
float position() const
Definition entity_handles.hpp:1120
static constexpr EntityType type()
Definition entity_handles.hpp:1095
void stop() const
Definition entity_handles.hpp:1145
bool supports_stop() const
Definition entity_handles.hpp:1116
ValveOperation current_operation() const
Definition entity_handles.hpp:1124
void close() const
Definition entity_handles.hpp:1139
std::optional< ValveInfo > info() const
Definition entity_handles.hpp:1098
Handle to a WaterHeater entity.
Definition entity_handles.hpp:1247
std::uint32_t supported_features() const
Definition entity_handles.hpp:1275
std::optional< WaterHeaterState > state() const
Definition entity_handles.hpp:1256
float target_temperature_high() const
Definition entity_handles.hpp:1299
std::vector< WaterHeaterMode > supported_modes() const
Definition entity_handles.hpp:1271
float target_temperature_step() const
Definition entity_handles.hpp:1267
float target_temperature() const
Definition entity_handles.hpp:1287
void command(WaterHeaterCommand c) const
Send a fully-specified command (its key is set automatically).
Definition entity_handles.hpp:1304
TemperatureUnit temperature_unit() const
Definition entity_handles.hpp:1279
float max_temperature() const
Definition entity_handles.hpp:1263
static constexpr EntityType type()
Definition entity_handles.hpp:1250
float current_temperature() const
Definition entity_handles.hpp:1283
WaterHeaterMode mode() const
Definition entity_handles.hpp:1291
std::optional< WaterHeaterInfo > info() const
Definition entity_handles.hpp:1253
float min_temperature() const
Definition entity_handles.hpp:1259
float target_temperature_low() const
Definition entity_handles.hpp:1295
Asynchronous orchestrator: owns the event loop and a Connection, and exposes connect/send/subscribe p...
Convenience senders that translate a typed command struct into its protobuf CommandRequest and dispat...
Typed store of a device's entities: ingest ListEntities*‍/State messages, query typed info/state per ...
Enumeration of ESPHome entity domains and name conversion helpers.
Definition bytes.hpp:10
TextMode
Mirror of proto enum TextMode.
Definition enums.hpp:364
TemperatureUnit
Mirror of proto enum TemperatureUnit.
Definition enums.hpp:131
CoverOperation
Mirror of proto enum CoverOperation.
Definition enums.hpp:33
ClimateSwingMode
Mirror of proto enum ClimateSwingMode.
Definition enums.hpp:163
ColorMode
Mirror of proto enum ColorMode.
Definition enums.hpp:60
FanDirection
Mirror of proto enum FanDirection.
Definition enums.hpp:54
void send_command(const Client &client, const SwitchCommand &cmd)
Send a SwitchCommand to the device.
NumberMode
Mirror of proto enum NumberMode.
Definition enums.hpp:217
WaterHeaterMode
Mirror of proto enum WaterHeaterMode.
Definition enums.hpp:194
EntityType
One per ESPHome entity domain (the <X> in ListEntities<X>Response).
Definition entity_type.hpp:11
EntityCategory
Mirror of proto enum EntityCategory.
Definition enums.hpp:20
ClimateMode
Mirror of proto enum ClimateMode.
Definition enums.hpp:138
ClimatePreset
Mirror of proto enum ClimatePreset.
Definition enums.hpp:182
SensorStateClass
Mirror of proto enum SensorStateClass.
Definition enums.hpp:75
ValveOperation
Mirror of proto enum ValveOperation.
Definition enums.hpp:370
ClimateAction
Mirror of proto enum ClimateAction.
Definition enums.hpp:171
void request_camera_image(const Client &client, bool single, bool stream)
Request a camera still image (single) or start/stop a stream.
ClimateFanMode
Mirror of proto enum ClimateFanMode.
Definition enums.hpp:149
A command to change an alarm control panel's state.
Definition alarm_control_panel.hpp:39
std::uint32_t key
Definition alarm_control_panel.hpp:40
A command to press a button.
Definition button.hpp:27
std::uint32_t key
Definition button.hpp:28
A command to mutate a climate entity. Each optional field is sent only when engaged.
Definition climate.hpp:61
std::optional< float > target_temperature
Definition climate.hpp:64
std::optional< ClimateMode > mode
Definition climate.hpp:63
std::uint32_t key
Definition climate.hpp:62
A command targeting a cover entity.
Definition cover.hpp:41
std::optional< float > position
Definition cover.hpp:43
std::uint32_t key
Definition cover.hpp:42
bool stop
Definition cover.hpp:45
A command to set a date's value.
Definition date.hpp:35
std::uint32_t key
Definition date.hpp:36
A command to set a datetime's value.
Definition datetime.hpp:33
std::uint32_t key
Definition datetime.hpp:34
A command to mutate a fan. Each optional field is sent only when engaged.
Definition fan.hpp:44
std::optional< bool > state
Definition fan.hpp:46
std::uint32_t key
Definition fan.hpp:45
std::optional< std::int32_t > speed_level
Definition fan.hpp:49
A command to mutate a light. Each optional field is sent only when engaged.
Definition light.hpp:57
std::optional< float > brightness
Definition light.hpp:60
std::uint32_t key
Definition light.hpp:58
std::optional< LightRgb > rgb
Definition light.hpp:63
std::optional< bool > state
Definition light.hpp:59
RGB triple, set together via the single has_rgb command flag.
Definition light.hpp:50
A command targeting a lock entity.
Definition lock.hpp:46
std::uint32_t key
Definition lock.hpp:47
LockCommand command
Definition lock.hpp:48
A command to mutate a media player.
Definition media_player.hpp:54
std::optional< MediaPlayerCommand > command
Definition media_player.hpp:56
std::uint32_t key
Definition media_player.hpp:55
std::optional< float > volume
Definition media_player.hpp:57
A command to set a number's value.
Definition number.hpp:41
std::uint32_t key
Definition number.hpp:42
A command to set a select's value.
Definition select.hpp:37
std::uint32_t key
Definition select.hpp:38
A command targeting a siren entity.
Definition siren.hpp:38
std::optional< bool > state
Definition siren.hpp:40
std::uint32_t key
Definition siren.hpp:39
A command to change a switch's state.
Definition switch.hpp:35
std::uint32_t key
Definition switch.hpp:36
A command to set a text entity's value.
Definition text.hpp:39
std::uint32_t key
Definition text.hpp:40
A command to set a time's value.
Definition time.hpp:35
std::uint32_t key
Definition time.hpp:36
A command to control an update entity.
Definition update.hpp:44
std::uint32_t key
Definition update.hpp:45
A command targeting a valve entity.
Definition valve.hpp:39
bool stop
Definition valve.hpp:42
std::optional< float > position
Definition valve.hpp:41
std::uint32_t key
Definition valve.hpp:40
A command to mutate a water heater.
Definition water_heater.hpp:50
std::uint32_t key
Definition water_heater.hpp:51