9namespace homeassistant {
11static const char *
const TAG =
"homeassistant.number";
15 if (!number_value.has_value()) {
16 ESP_LOGW(TAG,
"'%s': Can't convert '%s' to number!", this->
entity_id_, state.
c_str());
20 if (this->state == number_value.value()) {
29 if (!min_value.has_value()) {
30 ESP_LOGE(TAG,
"'%s': Can't convert 'min' value '%s' to number!", this->
entity_id_, min.
c_str());
33 ESP_LOGD(TAG,
"'%s': Min retrieved: %s",
get_name().c_str(), min.
c_str());
39 if (!max_value.has_value()) {
40 ESP_LOGE(TAG,
"'%s': Can't convert 'max' value '%s' to number!", this->
entity_id_, max.
c_str());
43 ESP_LOGD(TAG,
"'%s': Max retrieved: %s",
get_name().c_str(), max.
c_str());
49 if (!step_value.has_value()) {
50 ESP_LOGE(TAG,
"'%s': Can't convert 'step' value '%s' to number!", this->
entity_id_, step.
c_str());
53 ESP_LOGD(TAG,
"'%s': Step Retrieved %s",
get_name().c_str(), step.
c_str());
70 LOG_NUMBER(
"",
"Homeassistant Number",
this);
71 ESP_LOGCONFIG(TAG,
" Entity ID: '%s'", this->
entity_id_);
78 ESP_LOGE(TAG,
"No clients connected to API server");
92 auto &entity_id = resp.
data.emplace_back();
93 entity_id.key = ENTITY_ID_KEY;
96 auto &entity_value = resp.
data.emplace_back();
97 entity_value.key = VALUE_KEY;
100 buf_append_printf(value_buf,
sizeof(value_buf), 0,
"%g", value);
101 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 send_homeassistant_action(const HomeassistantActionRequest &call)
void subscribe_home_assistant_state(const char *entity_id, const char *attribute, std::function< void(StringRef)> f)
void get_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
const float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
Providing packet encoding functions for exchanging data with a remote host.
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.