ESPHome  2022.5.1
number.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "esphome/core/helpers.h"
6 #include "number_call.h"
7 #include "number_traits.h"
8 
9 namespace esphome {
10 namespace number {
11 
12 #define LOG_NUMBER(prefix, type, obj) \
13  if ((obj) != nullptr) { \
14  ESP_LOGCONFIG(TAG, "%s%s '%s'", prefix, LOG_STR_LITERAL(type), (obj)->get_name().c_str()); \
15  if (!(obj)->get_icon().empty()) { \
16  ESP_LOGCONFIG(TAG, "%s Icon: '%s'", prefix, (obj)->get_icon().c_str()); \
17  } \
18  if (!(obj)->traits.get_unit_of_measurement().empty()) { \
19  ESP_LOGCONFIG(TAG, "%s Unit of Measurement: '%s'", prefix, (obj)->traits.get_unit_of_measurement().c_str()); \
20  } \
21  }
22 
23 class Number;
24 
29 class Number : public EntityBase {
30  public:
31  float state;
32 
33  void publish_state(float state);
34 
35  NumberCall make_call() { return NumberCall(this); }
36 
37  void add_on_state_callback(std::function<void(float)> &&callback);
38 
40 
42  bool has_state() const { return has_state_; }
43 
44  protected:
45  friend class NumberCall;
46 
53  virtual void control(float value) = 0;
54 
55  uint32_t hash_base() override;
56 
58  bool has_state_{false};
59 };
60 
61 } // namespace number
62 } // namespace esphome
uint32_t hash_base() override
Definition: number.cpp:20
bool has_state() const
Return whether this number has gotten a full state yet.
Definition: number.h:42
void add_on_state_callback(std::function< void(float)> &&callback)
Definition: number.cpp:16
void publish_state(float state)
Definition: number.cpp:9
CallbackManager< void(float)> state_callback_
Definition: number.h:57
virtual void control(float value)=0
Set the value of the number, this is a virtual method that each number integration must implement...
Base-class for all numbers.
Definition: number.h:29
NumberTraits traits
Definition: number.h:39
NumberCall make_call()
Definition: number.h:35
Definition: a4988.cpp:4
friend class NumberCall
Definition: number.h:45