diff --git a/CODEOWNERS b/CODEOWNERS index f47b36ff73..62e49055a2 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -96,6 +96,7 @@ esphome/components/mcp23x08_base/* @jesserockz esphome/components/mcp23x17_base/* @jesserockz esphome/components/mcp23xxx_base/* @jesserockz esphome/components/mcp2515/* @danielschramm @mvturnho +esphome/components/mcp47a1/* @jesserockz esphome/components/mcp9808/* @k7hpn esphome/components/md5/* @esphome/core esphome/components/mdns/* @esphome/core diff --git a/esphome/components/mcp47a1/__init__.py b/esphome/components/mcp47a1/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/esphome/components/mcp47a1/mcp47a1.cpp b/esphome/components/mcp47a1/mcp47a1.cpp new file mode 100644 index 0000000000..58f3b2ac72 --- /dev/null +++ b/esphome/components/mcp47a1/mcp47a1.cpp @@ -0,0 +1,21 @@ +#include "mcp47a1.h" +#include "esphome/core/helpers.h" +#include "esphome/core/log.h" + +namespace esphome { +namespace mcp47a1 { + +static const char *const TAG = "mcp47a1"; + +void MCP47A1::dump_config() { + ESP_LOGCONFIG(TAG, "MCP47A1 Output:"); + LOG_I2C_DEVICE(this); +} + +void MCP47A1::write_state(float state) { + const uint8_t value = remap(state, 0.0f, 1.0f, 63, 0); + this->write_byte(0, value); +} + +} // namespace mcp47a1 +} // namespace esphome diff --git a/esphome/components/mcp47a1/mcp47a1.h b/esphome/components/mcp47a1/mcp47a1.h new file mode 100644 index 0000000000..5c02e062ad --- /dev/null +++ b/esphome/components/mcp47a1/mcp47a1.h @@ -0,0 +1,17 @@ +#pragma once + +#include "esphome/components/i2c/i2c.h" +#include "esphome/components/output/float_output.h" +#include "esphome/core/component.h" + +namespace esphome { +namespace mcp47a1 { + +class MCP47A1 : public Component, public output::FloatOutput, public i2c::I2CDevice { + public: + void dump_config() override; + void write_state(float state) override; +}; + +} // namespace mcp47a1 +} // namespace esphome diff --git a/esphome/components/mcp47a1/output.py b/esphome/components/mcp47a1/output.py new file mode 100644 index 0000000000..60235107e9 --- /dev/null +++ b/esphome/components/mcp47a1/output.py @@ -0,0 +1,27 @@ +import esphome.config_validation as cv +import esphome.codegen as cg +from esphome.components import output, i2c +from esphome.const import CONF_ID + +CODEOWNERS = ["@jesserockz"] +DEPENDENCIES = ["i2c"] + +mcp47a1_ns = cg.esphome_ns.namespace("mcp47a1") +MCP47A1 = mcp47a1_ns.class_("MCP47A1", output.FloatOutput, cg.Component, i2c.I2CDevice) + +CONFIG_SCHEMA = ( + output.FLOAT_OUTPUT_SCHEMA.extend( + { + cv.Required(CONF_ID): cv.declare_id(MCP47A1), + } + ) + .extend(cv.COMPONENT_SCHEMA) + .extend(i2c.i2c_device_schema(0x2E)) +) + + +async def to_code(config): + var = cg.new_Pvariable(config[CONF_ID]) + await cg.register_component(var, config) + await i2c.register_i2c_device(var, config) + await output.register_output(var, config) diff --git a/tests/test5.yaml b/tests/test5.yaml index 40db645097..d6acbf1e65 100644 --- a/tests/test5.yaml +++ b/tests/test5.yaml @@ -72,6 +72,9 @@ output: channel: 0 max_power: 0.8 + - platform: mcp47a1 + id: output_mcp47a1 + demo: esp32_ble: