12static const char *
const TAG =
"homeassistant.number";
16 if (!number_value.has_value()) {
17 ESP_LOGW(TAG,
"'%s': Can't convert '%s' to number!", this->
entity_id_, state.
c_str());
21 if (this->state == number_value.value()) {
30 if (!min_value.has_value()) {
31 ESP_LOGE(TAG,
"'%s': Can't convert 'min' value '%s' to number!", this->
entity_id_, min.
c_str());
34 ESP_LOGD(TAG,
"'%s': Min retrieved: %s",
get_name().c_str(), min.
c_str());
40 if (!max_value.has_value()) {
41 ESP_LOGE(TAG,
"'%s': Can't convert 'max' value '%s' to number!", this->
entity_id_, max.
c_str());
44 ESP_LOGD(TAG,
"'%s': Max retrieved: %s",
get_name().c_str(), max.
c_str());
50 if (!step_value.has_value()) {
51 ESP_LOGE(TAG,
"'%s': Can't convert 'step' value '%s' to number!", this->
entity_id_, step.
c_str());
54 ESP_LOGD(TAG,
"'%s': Step Retrieved %s",
get_name().c_str(), step.
c_str());
71 LOG_NUMBER(
"",
"Homeassistant Number",
this);
72 ESP_LOGCONFIG(TAG,
" Entity ID: '%s'", this->
entity_id_);
79 ESP_LOGE(TAG,
"No clients connected to API server");
83#ifdef USE_API_WIZARD_LINKED_INPUTS
85 ESP_LOGW(TAG,
"'%s': No entity ID set yet", this->
get_name().c_str());
93 static constexpr auto INPUT_NUMBER_SERVICE_NAME =
StringRef::from_lit(
"input_number.set_value");
94 static constexpr char INPUT_PREFIX[] =
"input_";
100 if (strncmp(this->
entity_id_, INPUT_PREFIX,
sizeof(INPUT_PREFIX) - 1) == 0) {
101 resp.
service = INPUT_NUMBER_SERVICE_NAME;
103 resp.
service = NUMBER_SERVICE_NAME;
107 auto &entity_id = resp.
data.emplace_back();
108 entity_id.key = ENTITY_ID_KEY;
111 auto &entity_value = resp.
data.emplace_back();
112 entity_value.key = VALUE_KEY;
115 buf_append_printf(value_buf,
sizeof(value_buf), 0,
"%g", value);
116 entity_value.value =
StringRef(value_buf);
const StringRef & get_name() const
StringRef is a reference to a string owned by something else.
constexpr const char * c_str() const
static constexpr StringRef from_lit(const CharT(&s)[N])
void get_home_assistant_state(const char *entity_id, const char *attribute, std::function< void(StringRef)> &&f)
void send_homeassistant_action(const HomeassistantActionRequest &call)
void subscribe_home_assistant_state(const char *entity_id, const char *attribute, std::function< void(StringRef)> &&f)
FixedVector< HomeassistantServiceMap > data
void control(float value) override
void max_retrieved_(StringRef max)
void dump_config() override
void step_retrieved_(StringRef step)
float get_setup_priority() const override
void min_retrieved_(StringRef min)
void state_changed_(StringRef state)
void publish_state(float state)
void set_min_value(float min_value)
void set_step(float step)
void set_max_value(float max_value)
APIServer * global_api_server
constexpr float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.