ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
sml_sensor.cpp
Go to the documentation of this file.
1#include "esphome/core/log.h"
2#include "sml_sensor.h"
3#include "../sml_parser.h"
4
5namespace esphome::sml {
6
7static const char *const TAG = "sml_sensor";
8
9SmlSensor::SmlSensor(std::string server_id, std::string obis_code)
10 : SmlListener(std::move(server_id), std::move(obis_code)) {}
11
12void SmlSensor::publish_val(const ObisInfo &obis_info) {
13 switch (obis_info.value_type) {
14 case SML_INT: {
16 break;
17 }
18 case SML_BOOL:
19 case SML_UINT: {
21 break;
22 }
23 case SML_OCTET: {
24 ESP_LOGW(TAG, "No number conversion for (%s) %s. Consider using SML TextSensor instead.",
25 bytes_repr(obis_info.server_id).c_str(), obis_info.code_repr().c_str());
26 break;
27 }
28 }
29}
30
32 LOG_SENSOR("", "SML", this);
33 if (!this->server_id.empty()) {
34 ESP_LOGCONFIG(TAG, " Server ID: %s", this->server_id.c_str());
35 }
36 ESP_LOGCONFIG(TAG, " OBIS Code: %s", this->obis_code.c_str());
37}
38
39} // namespace esphome::sml
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:68
std::string code_repr() const
std::string server_id
Definition sml.h:14
std::string obis_code
Definition sml.h:15
void dump_config() override
void publish_val(const ObisInfo &obis_info) override
SmlSensor(std::string server_id, std::string obis_code)
Definition sml_sensor.cpp:9
std::string bytes_repr(const BytesView &buffer)
int64_t bytes_to_int(const BytesView &buffer)
uint64_t bytes_to_uint(const BytesView &buffer)