...................
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
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
|
from esphome.const import CONF_ID
|
||||||
|
|
||||||
DEPENDENCIES = ['i2c']
|
DEPENDENCIES = ['i2c']
|
||||||
@@ -8,9 +8,9 @@ DEPENDENCIES = ['i2c']
|
|||||||
CONF_I2C_ADDR = 0x09
|
CONF_I2C_ADDR = 0x09
|
||||||
|
|
||||||
showcase_component_ns = cg.esphome_ns.namespace('showcase_component')
|
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),
|
cv.GenerateID(): cv.declare_id(ShowcaseComponent),
|
||||||
|
|
||||||
|
|||||||
@@ -5,17 +5,34 @@
|
|||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/components/i2c/i2c.h"
|
#include "esphome/components/i2c/i2c.h"
|
||||||
#include "esphome/components/output/float_output.h"
|
#include "esphome/components/output/float_output.h"
|
||||||
// TODO: maybe use monochrome leds instead of floatoutput directly?:
|
#include "esphome/components/light/light_output.h"
|
||||||
#include "esphome/components/monochromatic/monochromatic_light_output.h"
|
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace showcase_component {
|
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 };
|
enum State{ Off, Auto, On };
|
||||||
|
|
||||||
static const char *TAG = "showcase_component.component";
|
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:
|
public:
|
||||||
State s_{Off};
|
State s_{Off};
|
||||||
float b_upper_{1.0};
|
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_upper(output::FloatOutput *upper) {this->upper_ = upper;}
|
||||||
void set_lower(output::FloatOutput *lower) {this->lower_ = lower;}
|
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){
|
void write_state(State s){
|
||||||
ESP_LOGI(TAG, "Write_state");
|
ESP_LOGI(TAG, "Write_state");
|
||||||
@@ -85,8 +100,6 @@ class ShowcaseComponent : public i2c::I2CDevice, public Component, public Entity
|
|||||||
|
|
||||||
output::FloatOutput *upper_;
|
output::FloatOutput *upper_;
|
||||||
output::FloatOutput *lower_;
|
output::FloatOutput *lower_;
|
||||||
monochromatic::MonochromaticLightOutput *upper2_;
|
|
||||||
monochromatic::MonochromaticLightOutput *lower2_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace empty_i2c_component
|
} // namespace empty_i2c_component
|
||||||
|
|||||||
Reference in New Issue
Block a user