...................

master
Roman Kretschmer 2 years ago
parent 36ae7a47bd
commit 72908bdf26

@ -1,6 +1,6 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import i2c, sensor, monochromatic, output
from esphome.components import i2c, sensor, monochromatic, output, light
from esphome.const import CONF_ID
DEPENDENCIES = ['i2c']
@ -8,9 +8,9 @@ DEPENDENCIES = ['i2c']
CONF_I2C_ADDR = 0x09
showcase_component_ns = cg.esphome_ns.namespace('showcase_component')
ShowcaseComponent = showcase_component_ns.class_('ShowcaseComponent', cg.Component, i2c.I2CDevice)
ShowcaseComponent = showcase_component_ns.class_('ShowcaseComponent', cg.Component, i2c.I2CDevice, light.LightOutput)
CONFIG_SCHEMA = cv.Schema(
CONFIG_SCHEMA = light.BRIGHTNESS_ONLY_LIGHT_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(ShowcaseComponent),

@ -5,17 +5,34 @@
#include "esphome/core/component.h"
#include "esphome/components/i2c/i2c.h"
#include "esphome/components/output/float_output.h"
// TODO: maybe use monochrome leds instead of floatoutput directly?:
#include "esphome/components/monochromatic/monochromatic_light_output.h"
#include "esphome/components/light/light_output.h"
namespace esphome {
namespace showcase_component {
/* class Output: public light::LightOutput{ */
/* public: */
/* void set_output(output::FloatOutput *output) { output_ = output; } */
/* light::LightTraits get_traits() override { */
/* auto traits = light::LightTraits(); */
/* traits.set_supported_color_modes({light::ColorMode::BRIGHTNESS}); */
/* return traits; */
/* } */
/* void write_state(light::LightState *state) override { */
/* float bright; */
/* state->current_values_as_brightness(&bright); */
/* this->output_->set_level(bright); */
/* } */
/* protected: */
/* output::FloatOutput *output_; */
/* }; */
enum State{ Off, Auto, On };
static const char *TAG = "showcase_component.component";
class ShowcaseComponent : public i2c::I2CDevice, public Component, public EntityBase {
class ShowcaseComponent : public i2c::I2CDevice, public Component, public EntityBase, public light::LightOutput {
public:
State s_{Off};
float b_upper_{1.0};
@ -36,8 +53,6 @@ class ShowcaseComponent : public i2c::I2CDevice, public Component, public Entity
void set_upper(output::FloatOutput *upper) {this->upper_ = upper;}
void set_lower(output::FloatOutput *lower) {this->lower_ = lower;}
/* void set_upper(monochromatic::MonochromaticLightOutput *upper) {this->upper_ = upper;} */
/* void set_lower(monochromatic::MonochromaticLightOutput *lower) {this->lower_ = lower;} */
void write_state(State s){
ESP_LOGI(TAG, "Write_state");
@ -85,8 +100,6 @@ class ShowcaseComponent : public i2c::I2CDevice, public Component, public Entity
output::FloatOutput *upper_;
output::FloatOutput *lower_;
monochromatic::MonochromaticLightOutput *upper2_;
monochromatic::MonochromaticLightOutput *lower2_;
};
} // namespace empty_i2c_component

Loading…
Cancel
Save