....................
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import light, output
|
||||
from esphome.components import light, output, i2c
|
||||
from esphome.const import CONF_OUTPUT_ID, CONF_OUTPUT
|
||||
|
||||
CONF_I2C_ADDR = 0x09
|
||||
|
||||
UPPER_OUTPUT = "upper"
|
||||
LOWER_OUTPUT = "lower"
|
||||
|
||||
c_monochromatic_ns = cg.esphome_ns.namespace("c_monochromatic")
|
||||
MonochromaticLightOutput = c_monochromatic_ns.class_(
|
||||
"MonochromaticLightOutput", light.LightOutput
|
||||
"MonochromaticLightOutput", light.LightOutput, cg.Component
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = light.BRIGHTNESS_ONLY_LIGHT_SCHEMA.extend(
|
||||
@@ -16,8 +18,9 @@ CONFIG_SCHEMA = light.BRIGHTNESS_ONLY_LIGHT_SCHEMA.extend(
|
||||
cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(MonochromaticLightOutput),
|
||||
cv.Required(UPPER_OUTPUT): cv.use_id(output.FloatOutput),
|
||||
cv.Required(LOWER_OUTPUT): cv.use_id(output.FloatOutput),
|
||||
|
||||
}
|
||||
)
|
||||
).extend(i2c.i2c_device_schema(CONF_I2C_ADDR)).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
@@ -27,3 +30,6 @@ async def to_code(config):
|
||||
upper = await cg.get_variable(config[UPPER_OUTPUT])
|
||||
lower = await cg.get_variable(config[LOWER_OUTPUT])
|
||||
cg.add(var.set_output(upper, lower))
|
||||
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/output/float_output.h"
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
#include "esphome/components/light/light_output.h"
|
||||
#include "esphome/components/output/float_output.h"
|
||||
#include "esphome/core/component.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace c_monochromatic {
|
||||
|
||||
class MonochromaticLightOutput : public light::LightOutput {
|
||||
public:
|
||||
void set_output(output::FloatOutput *upper, output::FloatOutput *lower) { upper_ = upper; lower_ = lower; }
|
||||
class MonochromaticLightOutput : public light::LightOutput,
|
||||
public i2c::I2CDevice,
|
||||
public Component {
|
||||
public:
|
||||
void set_output(output::FloatOutput *upper, output::FloatOutput *lower) {
|
||||
upper_ = upper;
|
||||
lower_ = lower;
|
||||
}
|
||||
light::LightTraits get_traits() override {
|
||||
auto traits = light::LightTraits();
|
||||
traits.set_supported_color_modes({light::ColorMode::BRIGHTNESS});
|
||||
@@ -22,10 +28,10 @@ class MonochromaticLightOutput : public light::LightOutput {
|
||||
this->lower_->set_level(bright);
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
output::FloatOutput *upper_;
|
||||
output::FloatOutput *lower_;
|
||||
};
|
||||
|
||||
} // namespace monochromatic
|
||||
} // namespace c_monochromatic
|
||||
} // namespace esphome
|
||||
|
||||
Reference in New Issue
Block a user