Feature/m5angle8: Add support for m5angle8 input device (#6799)
Co-authored-by: Richard Nauber <richard@nauber.dev> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
20 files changed
+474
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import binary_sensor
|
||||
|
||||
from .. import M5Stack8AngleComponent, m5stack_8angle_ns, CONF_M5STACK_8ANGLE_ID
|
||||
|
||||
|
||||
M5Stack8AngleSwitchBinarySensor = m5stack_8angle_ns.class_(
|
||||
"M5Stack8AngleSwitchBinarySensor",
|
||||
binary_sensor.BinarySensor,
|
||||
cg.PollingComponent,
|
||||
)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(CONF_M5STACK_8ANGLE_ID): cv.use_id(M5Stack8AngleComponent),
|
||||
}
|
||||
)
|
||||
.extend(binary_sensor.binary_sensor_schema(M5Stack8AngleSwitchBinarySensor))
|
||||
.extend(cv.polling_component_schema("10s"))
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
hub = await cg.get_variable(config[CONF_M5STACK_8ANGLE_ID])
|
||||
sens = await binary_sensor.new_binary_sensor(config)
|
||||
cg.add(sens.set_parent(hub))
|
||||
await cg.register_component(sens, config)
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "m5stack_8angle_binary_sensor.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace m5stack_8angle {
|
||||
|
||||
void M5Stack8AngleSwitchBinarySensor::update() {
|
||||
int8_t out = this->parent_->read_switch();
|
||||
if (out == -1) {
|
||||
this->status_set_warning("Could not read binary sensor state from M5Stack 8Angle.");
|
||||
return;
|
||||
}
|
||||
this->publish_state(out != 0);
|
||||
this->status_clear_warning();
|
||||
}
|
||||
|
||||
} // namespace m5stack_8angle
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
#include "../m5stack_8angle.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace m5stack_8angle {
|
||||
|
||||
class M5Stack8AngleSwitchBinarySensor : public binary_sensor::BinarySensor,
|
||||
public PollingComponent,
|
||||
public Parented<M5Stack8AngleComponent> {
|
||||
public:
|
||||
void update() override;
|
||||
};
|
||||
|
||||
} // namespace m5stack_8angle
|
||||
} // namespace esphome
|
||||
Reference in new issue
Block a user