ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
mk2pvrouter_sensor.cpp
Go to the documentation of this file.
2#include "esphome/core/log.h"
3
4namespace esphome::mk2pvrouter {
5
6ESPHOME_LOG_TAG(TAG, "mk2pvrouter_sensor");
7
8Mk2PVRouterSensor::Mk2PVRouterSensor(const char *tag, bool scale_centi)
9 : Mk2PVRouterListener(tag), scale_centi_(scale_centi) {}
10
12 auto result = parse_number<float>(val);
13 if (!result.has_value()) {
14 ESP_LOGW(TAG, "Failed to parse value '%s' for tag '%s'", val, this->get_tag());
15 return;
16 }
17 float value = result.value();
18 if (this->scale_centi_) {
19 value *= 0.01f;
20 }
21 this->publish_state(value);
22}
23
25 LOG_SENSOR(" ", "Mk2PVRouter Sensor", this);
26 ESP_LOGCONFIG(TAG, " Tag: %s", this->get_tag());
27}
28
29} // namespace esphome::mk2pvrouter
Mk2PVRouterSensor(const char *tag, bool scale_centi)
void publish_val(const char *val) override
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:65
mopeka_std_values val[3]
ESPHOME_LOG_TAG(TAG, "mk2pvrouter_binary_sensor")
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.
Definition helpers.h:1276