Skip to content

Commit

Permalink
Add resistance_sampler interface for config validation (esphome#5718)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesserockz authored Nov 9, 2023
1 parent bc7519f commit 01d28ce
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ esphome/components/radon_eye_rd200/* @jeffeb3
esphome/components/rc522/* @glmnet
esphome/components/rc522_i2c/* @glmnet
esphome/components/rc522_spi/* @glmnet
esphome/components/resistance_sampler/* @jesserockz
esphome/components/restart/* @esphome/core
esphome/components/rf_bridge/* @jesserockz
esphome/components/rgbct/* @jesserockz
Expand Down
6 changes: 4 additions & 2 deletions esphome/components/ntc/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import esphome.config_validation as cv
import esphome.codegen as cg
from esphome.components import sensor
from esphome.components import sensor, resistance_sampler
from esphome.const import (
CONF_CALIBRATION,
CONF_REFERENCE_RESISTANCE,
Expand All @@ -15,6 +15,8 @@
UNIT_CELSIUS,
)

AUTO_LOAD = ["resistance_sampler"]

ntc_ns = cg.esphome_ns.namespace("ntc")
NTC = ntc_ns.class_("NTC", cg.Component, sensor.Sensor)

Expand Down Expand Up @@ -124,7 +126,7 @@ def process_calibration(value):
)
.extend(
{
cv.Required(CONF_SENSOR): cv.use_id(sensor.Sensor),
cv.Required(CONF_SENSOR): cv.use_id(resistance_sampler.ResistanceSampler),
cv.Required(CONF_CALIBRATION): process_calibration,
}
)
Expand Down
5 changes: 3 additions & 2 deletions esphome/components/resistance/resistance_sensor.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#include "esphome/core/component.h"
#include "esphome/components/resistance_sampler/resistance_sampler.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/core/component.h"

namespace esphome {
namespace resistance {
Expand All @@ -11,7 +12,7 @@ enum ResistanceConfiguration {
DOWNSTREAM,
};

class ResistanceSensor : public Component, public sensor::Sensor {
class ResistanceSensor : public Component, public sensor::Sensor, resistance_sampler::ResistanceSampler {
public:
void set_sensor(Sensor *sensor) { sensor_ = sensor; }
void set_configuration(ResistanceConfiguration configuration) { configuration_ = configuration; }
Expand Down
11 changes: 9 additions & 2 deletions esphome/components/resistance/sensor.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor
from esphome.components import sensor, resistance_sampler
from esphome.const import (
CONF_SENSOR,
STATE_CLASS_MEASUREMENT,
UNIT_OHM,
ICON_FLASH,
)

AUTO_LOAD = ["resistance_sampler"]

resistance_ns = cg.esphome_ns.namespace("resistance")
ResistanceSensor = resistance_ns.class_("ResistanceSensor", cg.Component, sensor.Sensor)
ResistanceSensor = resistance_ns.class_(
"ResistanceSensor",
cg.Component,
sensor.Sensor,
resistance_sampler.ResistanceSampler,
)

CONF_REFERENCE_VOLTAGE = "reference_voltage"
CONF_CONFIGURATION = "configuration"
Expand Down
6 changes: 6 additions & 0 deletions esphome/components/resistance_sampler/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import esphome.codegen as cg

resistance_sampler_ns = cg.esphome_ns.namespace("resistance_sampler")
ResistanceSampler = resistance_sampler_ns.class_("ResistanceSampler")

CODEOWNERS = ["@jesserockz"]
10 changes: 10 additions & 0 deletions esphome/components/resistance_sampler/resistance_sampler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

namespace esphome {
namespace resistance_sampler {

/// Abstract interface to mark components that provide resistance values.
class ResistanceSampler {};

} // namespace resistance_sampler
} // namespace esphome

0 comments on commit 01d28ce

Please sign in to comment.