ESPHome 2025.5.0
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 {
6namespace sml {
7
8static const char *const TAG = "sml_sensor";
9
10SmlSensor::SmlSensor(std::string server_id, std::string obis_code)
11 : SmlListener(std::move(server_id), std::move(obis_code)) {}
12
13void SmlSensor::publish_val(const ObisInfo &obis_info) {
14 switch (obis_info.value_type) {
15 case SML_INT: {
17 break;
18 }
19 case SML_BOOL:
20 case SML_UINT: {
22 break;
23 }
24 case SML_OCTET: {
25 ESP_LOGW(TAG, "No number conversion for (%s) %s. Consider using SML TextSensor instead.",
26 bytes_repr(obis_info.server_id).c_str(), obis_info.code_repr().c_str());
27 break;
28 }
29 }
30}
31
33 LOG_SENSOR("", "SML", this);
34 if (!this->server_id.empty()) {
35 ESP_LOGCONFIG(TAG, " Server ID: %s", this->server_id.c_str());
36 }
37 ESP_LOGCONFIG(TAG, " OBIS Code: %s", this->obis_code.c_str());
38}
39
40} // namespace sml
41} // namespace esphome
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:39
std::string code_repr() const
std::string server_id
Definition sml.h:15
std::string obis_code
Definition sml.h:16
void dump_config() override
void publish_val(const ObisInfo &obis_info) override
SmlSensor(std::string server_id, std::string obis_code)
std::string bytes_repr(const BytesView &buffer)
int64_t bytes_to_int(const BytesView &buffer)
uint64_t bytes_to_uint(const BytesView &buffer)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7