From 48f0cb517e69ef14ae3a22d4db6e5c1a8014c537 Mon Sep 17 00:00:00 2001 From: gnxlxnxx Date: Wed, 24 Jan 2024 21:35:25 +0100 Subject: [PATCH] .................... --- components/custom_monochromatic/light.py | 12 +++++++--- .../monochromatic_light_output.h | 22 ++++++++++++------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/components/custom_monochromatic/light.py b/components/custom_monochromatic/light.py index a97dc9b..960ec4a 100644 --- a/components/custom_monochromatic/light.py +++ b/components/custom_monochromatic/light.py @@ -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) diff --git a/components/custom_monochromatic/monochromatic_light_output.h b/components/custom_monochromatic/monochromatic_light_output.h index a1e4f51..3483405 100644 --- a/components/custom_monochromatic/monochromatic_light_output.h +++ b/components/custom_monochromatic/monochromatic_light_output.h @@ -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 esphome +} // namespace c_monochromatic +} // namespace esphome