8 namespace homeassistant {
10 static const char *
const TAG =
"homeassistant.number";
13 auto number_value = parse_number<float>(
state);
14 if (!number_value.has_value()) {
15 ESP_LOGW(TAG,
"'%s': Can't convert '%s' to number!", this->
entity_id_.c_str(), state.c_str());
19 if (this->state == number_value.value()) {
22 ESP_LOGD(TAG,
"'%s': Got state %s", this->
entity_id_.c_str(), state.c_str());
27 auto min_value = parse_number<float>(min);
28 if (!min_value.has_value()) {
29 ESP_LOGE(TAG,
"'%s': Can't convert 'min' value '%s' to number!", this->
entity_id_.c_str(), min.c_str());
32 ESP_LOGD(TAG,
"'%s': Min retrieved: %s",
get_name().c_str(), min.
c_str());
37 auto max_value = parse_number<float>(max);
38 if (!max_value.has_value()) {
39 ESP_LOGE(TAG,
"'%s': Can't convert 'max' value '%s' to number!", this->
entity_id_.c_str(), max.c_str());
42 ESP_LOGD(TAG,
"'%s': Max retrieved: %s",
get_name().c_str(), max.
c_str());
47 auto step_value = parse_number<float>(step);
48 if (!step_value.has_value()) {
49 ESP_LOGE(TAG,
"'%s': Can't convert 'step' value '%s' to number!", this->
entity_id_.c_str(), step.c_str());
52 ESP_LOGD(TAG,
"'%s': Step Retrieved %s",
get_name().c_str(), step.
c_str());
72 LOG_NUMBER(
"",
"Homeassistant Number",
this);
73 ESP_LOGCONFIG(TAG,
" Entity ID: '%s'", this->
entity_id_.c_str());
80 ESP_LOGE(TAG,
"No clients connected to API server");
87 resp.
service =
"number.set_value";
90 entity_id.
key =
"entity_id";
92 resp.
data.push_back(entity_id);
95 entity_value.
key =
"value";
97 resp.
data.push_back(entity_value);
const float AFTER_CONNECTION
For components that should be initialized after a data connection (API/MQTT) is connected.
void state_changed_(const std::string &state)
void max_retrieved_(const std::string &max)
void set_step(float step)
void control(float value) override
void publish_state(float state)
void send_homeassistant_service_call(const HomeassistantServiceResponse &call)
bool is_connected()
Return whether the node is connected to the network (through wifi, eth, ...)
void dump_config() override
const nullopt_t nullopt((nullopt_t::init()))
void set_min_value(float min_value)
void set_max_value(float max_value)
constexpr const char * c_str() const
std::string to_string(int value)
Implementation of SPI Controller mode.
void min_retrieved_(const std::string &min)
void subscribe_home_assistant_state(std::string entity_id, optional< std::string > attribute, std::function< void(std::string)> f)
void get_home_assistant_state(std::string entity_id, optional< std::string > attribute, std::function< void(std::string)> f)
std::vector< HomeassistantServiceMap > data
float get_setup_priority() const override
APIServer * global_api_server
const StringRef & get_name() const
void step_retrieved_(const std::string &step)