Skip to content

Commit

Permalink
p1 out support dsmr sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
mhendriks committed Jul 13, 2024
1 parent 77a29ad commit a550a24
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 331 deletions.
9 changes: 7 additions & 2 deletions components/dsmr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@

CODEOWNERS = ["@glmnet", "@zuidwijk"]

MULTI_CONF = True

DEPENDENCIES = ["uart"]
AUTO_LOAD = ["sensor", "text_sensor"]

CONF_CRC_CHECK = "crc_check"
CONF_DECRYPTION_KEY = "decryption_key"
CONF_DSMR_ID = "dsmr_id"
CONF_GAS_MBUS_ID = "gas_mbus_id"
CONF_WATER_MBUS_ID = "water_mbus_id"
CONF_MAX_TELEGRAM_LENGTH = "max_telegram_length"
CONF_REQUEST_INTERVAL = "request_interval"
CONF_REQUEST_PIN = "request_pin"
Expand Down Expand Up @@ -51,6 +54,7 @@ def _validate_key(value):
cv.Optional(CONF_DECRYPTION_KEY): _validate_key,
cv.Optional(CONF_CRC_CHECK, default=True): cv.boolean,
cv.Optional(CONF_GAS_MBUS_ID, default=1): cv.int_,
cv.Optional(CONF_WATER_MBUS_ID, default=2): cv.int_,
cv.Optional(CONF_MAX_TELEGRAM_LENGTH, default=1500): cv.int_,
cv.Optional(CONF_REQUEST_PIN): pins.gpio_output_pin_schema,
cv.Optional(
Expand Down Expand Up @@ -79,10 +83,11 @@ async def to_code(config):
cg.add(var.set_request_interval(config[CONF_REQUEST_INTERVAL].total_milliseconds))
cg.add(var.set_receive_timeout(config[CONF_RECEIVE_TIMEOUT].total_milliseconds))

cg.add_define("DSMR_GAS_MBUS_ID", config[CONF_GAS_MBUS_ID])
cg.add_build_flag("-DDSMR_GAS_MBUS_ID=" + str(config[CONF_GAS_MBUS_ID]))
cg.add_build_flag("-DDSMR_WATER_MBUS_ID=" + str(config[CONF_WATER_MBUS_ID]))

# DSMR Parser
cg.add_library("glmnet/Dsmr", "0.5")
cg.add_library("glmnet/Dsmr", "0.9")

# Crypto
cg.add_library("rweather/Crypto", "0.4.0")
327 changes: 0 additions & 327 deletions components/dsmr/dsmr.cpp

This file was deleted.

8 changes: 8 additions & 0 deletions components/dsmr/dsmr.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <dsmr/parser.h>
#include <dsmr/fields.h>

#include <vector>

namespace esphome {
namespace dsmr {

Expand Down Expand Up @@ -83,6 +85,9 @@ class Dsmr : public Component, public uart::UARTDevice {
void set_##s(text_sensor::TextSensor *sensor) { s_##s##_ = sensor; }
DSMR_TEXT_SENSOR_LIST(DSMR_SET_TEXT_SENSOR, )

// handled outside dsmr
void set_telegram(text_sensor::TextSensor *sensor) { s_telegram_ = sensor; }

protected:
void receive_telegram_();
void receive_encrypted_telegram_();
Expand Down Expand Up @@ -122,6 +127,9 @@ class Dsmr : public Component, public uart::UARTDevice {
bool header_found_{false};
bool footer_found_{false};

// handled outside dsmr
text_sensor::TextSensor *s_telegram_{nullptr};

// Sensor member pointers
#define DSMR_DECLARE_SENSOR(s) sensor::Sensor *s_##s##_{nullptr};
DSMR_SENSOR_LIST(DSMR_DECLARE_SENSOR, )
Expand Down
Loading

0 comments on commit a550a24

Please sign in to comment.