Skip to content

Commit ba06112

Browse files
committed
ESPHome DSMR component. Remove dependency on Arduino framework. Add missing sensors.
1 parent 7394cbf commit ba06112

File tree

7 files changed

+486
-35
lines changed

7 files changed

+486
-35
lines changed

.clang-tidy.hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3d46b63015d761c85ca9cb77ab79a389509e5776701fb22aed16e7b79d432c0c
1+
88a205b0fefeb3d1d1dc249944c3137ccc69c5b165d6a845468d9a3e18133ba3

esphome/components/dsmr/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ def _validate_key(value):
6161
): cv.positive_time_period_milliseconds,
6262
}
6363
).extend(uart.UART_DEVICE_SCHEMA),
64-
cv.only_with_arduino,
6564
)
6665

6766

@@ -83,7 +82,7 @@ async def to_code(config):
8382
cg.add_build_flag("-DDSMR_WATER_MBUS_ID=" + str(config[CONF_WATER_MBUS_ID]))
8483

8584
# DSMR Parser
86-
cg.add_library("glmnet/Dsmr", "0.8")
85+
cg.add_library("polargoose/arduino-dsmr-2", "9.0")
8786

8887
# Crypto
89-
cg.add_library("rweather/Crypto", "0.4.0")
88+
cg.add_library("polargoose/Crypto-no-arduino", "0.4.0")

esphome/components/dsmr/dsmr.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#ifdef USE_ARDUINO
2-
31
#include "dsmr.h"
42
#include "esphome/core/log.h"
53

@@ -257,9 +255,9 @@ bool Dsmr::parse_telegram() {
257255
ESP_LOGV(TAG, "Trying to parse telegram");
258256
this->stop_requesting_data_();
259257

260-
::dsmr::ParseResult<void> res =
261-
::dsmr::P1Parser::parse(&data, this->telegram_, this->bytes_read_, false,
262-
this->crc_check_); // Parse telegram according to data definition. Ignore unknown values.
258+
const auto &res = arduino_dsmr_2::P1Parser::parse(
259+
&data, this->telegram_, this->bytes_read_, false,
260+
this->crc_check_); // Parse telegram according to data definition. Ignore unknown values.
263261
if (res.err) {
264262
// Parsing error, show it
265263
auto err_str = res.fullError(this->telegram_, this->telegram_ + this->bytes_read_);
@@ -331,5 +329,3 @@ void Dsmr::set_decryption_key(const std::string &decryption_key) {
331329

332330
} // namespace dsmr
333331
} // namespace esphome
334-
335-
#endif // USE_ARDUINO

esphome/components/dsmr/dsmr.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
#pragma once
22

3-
#ifdef USE_ARDUINO
4-
53
#include "esphome/core/component.h"
64
#include "esphome/components/sensor/sensor.h"
75
#include "esphome/components/text_sensor/text_sensor.h"
86
#include "esphome/components/uart/uart.h"
97
#include "esphome/core/log.h"
10-
#include "esphome/core/defines.h"
11-
12-
// don't include <dsmr.h> because it puts everything in global namespace
13-
#include <dsmr/parser.h>
14-
#include <dsmr/fields.h>
15-
8+
#include <arduino-dsmr-2/fields.h>
9+
#include <arduino-dsmr-2/parser.h>
1610
#include <vector>
1711

1812
namespace esphome {
1913
namespace dsmr {
2014

21-
using namespace ::dsmr::fields;
15+
using namespace arduino_dsmr_2::fields;
2216

2317
// DSMR_**_LIST generated by ESPHome and written in esphome/core/defines
2418

@@ -44,8 +38,8 @@ using namespace ::dsmr::fields;
4438
#define DSMR_DATA_SENSOR(s) s
4539
#define DSMR_COMMA ,
4640

47-
using MyData = ::dsmr::ParsedData<DSMR_TEXT_SENSOR_LIST(DSMR_DATA_SENSOR, DSMR_COMMA)
48-
DSMR_BOTH DSMR_SENSOR_LIST(DSMR_DATA_SENSOR, DSMR_COMMA)>;
41+
using MyData = arduino_dsmr_2::ParsedData<DSMR_TEXT_SENSOR_LIST(DSMR_DATA_SENSOR, DSMR_COMMA)
42+
DSMR_BOTH DSMR_SENSOR_LIST(DSMR_DATA_SENSOR, DSMR_COMMA)>;
4943

5044
class Dsmr : public Component, public uart::UARTDevice {
5145
public:
@@ -142,5 +136,3 @@ class Dsmr : public Component, public uart::UARTDevice {
142136
};
143137
} // namespace dsmr
144138
} // namespace esphome
145-
146-
#endif // USE_ARDUINO

0 commit comments

Comments
 (0)