diff --git a/custom_components/empty_cover/cover.py b/custom_components/empty_cover/cover.py new file mode 100644 index 0000000..45fd743 --- /dev/null +++ b/custom_components/empty_cover/cover.py @@ -0,0 +1,18 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome import automation +from esphome.components import cover +from esphome.const import CONF_ID + +empty_cover_ns = cg.esphome_ns.namespace('empty_cover') +EmptyCover = empty_cover_ns.class_('EmptyCover', cover.Cover, cg.Component) + +CONFIG_SCHEMA = cover.COVER_SCHEMA.extend({ + cv.GenerateID(): cv.declare_id(EmptyCover) +}).extend(cv.COMPONENT_SCHEMA) + + +def to_code(config): + var = cg.new_Pvariable(config[CONF_ID]) + yield cg.register_component(var, config) + yield cover.register_cover(var, config) \ No newline at end of file diff --git a/custom_components/empty_cover/empty_cover.cpp b/custom_components/empty_cover/empty_cover.cpp new file mode 100644 index 0000000..c932b22 --- /dev/null +++ b/custom_components/empty_cover/empty_cover.cpp @@ -0,0 +1,35 @@ +#include "esphome/core/log.h" +#include "empty_cover.h" + +namespace esphome { +namespace empty_cover { + +static const char *TAG = "empty_cover.cover"; + +void EmptyCover::setup() { + +} + +void EmptyCover::loop() { + +} + +void EmptyCover::dump_config() { + ESP_LOGCONFIG(TAG, "Empty cover"); +} + +cover::CoverTraits EmptyCover::get_traits() { + auto traits = cover::CoverTraits(); + traits.set_is_assumed_state(false); + traits.set_supports_position(false); + traits.set_supports_tilt(false); + + return traits; +} + +void EmptyCover::control(const cover::CoverCall &call) { + +} + +} // namespace empty_cover +} // namespace esphome diff --git a/custom_components/empty_cover/empty_cover.h b/custom_components/empty_cover/empty_cover.h new file mode 100644 index 0000000..fc514f2 --- /dev/null +++ b/custom_components/empty_cover/empty_cover.h @@ -0,0 +1,21 @@ +#pragma once + +#include "esphome/core/component.h" +#include "esphome/components/cover/cover.h" + +namespace esphome { +namespace empty_cover { + +class EmptyCover : public cover::Cover, public Component { + public: + void setup() override; + void loop() override; + void dump_config() override; + cover::CoverTraits get_traits() override; + + protected: + void control(const cover::CoverCall &call) override; +}; + +} // namespace empty_cover +} // namespace esphome \ No newline at end of file diff --git a/custom_components/empty_custom_binary_output/empty_custom_binary_output.cpp b/custom_components/empty_custom_binary_output/empty_custom_binary_output.cpp index 85f23df..3a3f4ef 100644 --- a/custom_components/empty_custom_binary_output/empty_custom_binary_output.cpp +++ b/custom_components/empty_custom_binary_output/empty_custom_binary_output.cpp @@ -1,8 +1,11 @@ +#include "esphome/core/log.h" #include "empty_custom_binary_output.h" namespace esphome { namespace empty_custom_binary_output { +static const char *TAG = "empty_custom_binary_output.binary_output"; + void EmptyCustomBinaryOutput::setup(){ } @@ -12,7 +15,7 @@ void EmptyCustomBinaryOutput::write_state(bool state){ } void EmptyCustomBinaryOutput::dump_config() { - + ESP_LOGCONFIG(TAG, "Custom binary output"); } } //namespace empty_custom_binary_output diff --git a/custom_components/empty_custom_binary_sensor/empty_custom_binary_sensor.cpp b/custom_components/empty_custom_binary_sensor/empty_custom_binary_sensor.cpp index d5a8dc3..09b1e86 100644 --- a/custom_components/empty_custom_binary_sensor/empty_custom_binary_sensor.cpp +++ b/custom_components/empty_custom_binary_sensor/empty_custom_binary_sensor.cpp @@ -1,9 +1,11 @@ -#include "esphome.h" +#include "esphome/core/log.h" #include "empty_custom_binary_sensor.h" namespace esphome { namespace empty_custom_binary_sensor { +static const char *TAG = "empty_custom_binary_sensor.binary_sensor"; + void EmptyCustomBinarySensor::setup() { } @@ -13,7 +15,7 @@ void EmptyCustomBinarySensor::update() { } void EmptyCustomBinarySensor::dump_config() { - + ESP_LOGCONFIG(TAG, "Custom binary sensor"); } } //namespace empty_custom_binary_sensor diff --git a/custom_components/empty_custom_fan/__init__.py b/custom_components/empty_custom_fan/__init__.py new file mode 100644 index 0000000..ed0015c --- /dev/null +++ b/custom_components/empty_custom_fan/__init__.py @@ -0,0 +1,3 @@ +import esphome.codegen as cg + +empty_custom_fan_ns = cg.esphome_ns.namespace('empty_custom_fan') \ No newline at end of file diff --git a/custom_components/empty_custom_fan/fan/__init__.py b/custom_components/empty_custom_fan/fan/__init__.py new file mode 100644 index 0000000..d2e4c40 --- /dev/null +++ b/custom_components/empty_custom_fan/fan/__init__.py @@ -0,0 +1,33 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import fan, output +from esphome.const import CONF_DIRECTION_OUTPUT, CONF_OSCILLATION_OUTPUT, \ + CONF_OUTPUT, CONF_OUTPUT_ID +from .. import empty_custom_fan_ns + +EmptyCustomFan = empty_custom_fan_ns.class_('EmptyCustomFan', cg.Component) + +CONFIG_SCHEMA = fan.FAN_SCHEMA.extend({ + cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(EmptyCustomFan), + cv.Required(CONF_OUTPUT): cv.use_id(output.BinaryOutput), + cv.Optional(CONF_DIRECTION_OUTPUT): cv.use_id(output.BinaryOutput), + cv.Optional(CONF_OSCILLATION_OUTPUT): cv.use_id(output.BinaryOutput), +}).extend(cv.COMPONENT_SCHEMA) + + +def to_code(config): + var = cg.new_Pvariable(config[CONF_OUTPUT_ID]) + yield cg.register_component(var, config) + + fan_ = yield fan.create_fan_state(config) + cg.add(var.set_fan(fan_)) + output_ = yield cg.get_variable(config[CONF_OUTPUT]) + cg.add(var.set_output(output_)) + + if CONF_OSCILLATION_OUTPUT in config: + oscillation_output = yield cg.get_variable(config[CONF_OSCILLATION_OUTPUT]) + cg.add(var.set_oscillating(oscillation_output)) + + if CONF_DIRECTION_OUTPUT in config: + direction_output = yield cg.get_variable(config[CONF_DIRECTION_OUTPUT]) + cg.add(var.set_direction(direction_output)) \ No newline at end of file diff --git a/custom_components/empty_custom_fan/fan/empty_custom_fan.cpp b/custom_components/empty_custom_fan/fan/empty_custom_fan.cpp new file mode 100644 index 0000000..6916254 --- /dev/null +++ b/custom_components/empty_custom_fan/fan/empty_custom_fan.cpp @@ -0,0 +1,24 @@ +#include "empty_custom_fan.h" +#include "esphome/core/log.h" + +namespace esphome { +namespace empty_custom_fan { + +static const char *TAG = "empty_custom_fan.fan"; + +void EmptyCustomFan::setup() { + auto traits = fan::FanTraits(this->oscillating_ != nullptr, false, this->direction_ != nullptr); + this->fan_->set_traits(traits); + this->fan_->add_on_state_callback([this]() { this->next_update_ = true; }); +} + +void EmptyCustomFan::loop() { + +} + +void EmptyCustomFan::dump_config() { + ESP_LOGCONFIG(TAG, "Fan '%s':", this->fan_->get_name().c_str()); +} + +} // namespace binary +} // namespace empty_custom_fan diff --git a/custom_components/empty_custom_fan/fan/empty_custom_fan.h b/custom_components/empty_custom_fan/fan/empty_custom_fan.h new file mode 100644 index 0000000..f460c2c --- /dev/null +++ b/custom_components/empty_custom_fan/fan/empty_custom_fan.h @@ -0,0 +1,29 @@ +#pragma once + +#include "esphome/core/component.h" +#include "esphome/components/output/binary_output.h" +#include "esphome/components/fan/fan_state.h" + +namespace esphome { +namespace empty_custom_fan { + +class EmptyCustomFan : public Component { + public: + void set_fan(fan::FanState *fan) { fan_ = fan; } + void set_output(output::BinaryOutput *output) { output_ = output; } + void setup() override; + void loop() override; + void dump_config() override; + void set_oscillating(output::BinaryOutput *oscillating) { this->oscillating_ = oscillating; } + void set_direction(output::BinaryOutput *direction) { this->direction_ = direction; } + + protected: + fan::FanState *fan_; + output::BinaryOutput *output_; + output::BinaryOutput *oscillating_{nullptr}; + output::BinaryOutput *direction_{nullptr}; + bool next_update_{true}; +}; + +} // namespace empty_custom_fan +} // namespace esphome \ No newline at end of file diff --git a/custom_components/empty_custom_float_output/empty_custom_float_output.cpp b/custom_components/empty_custom_float_output/empty_custom_float_output.cpp index 9143f48..05c5532 100644 --- a/custom_components/empty_custom_float_output/empty_custom_float_output.cpp +++ b/custom_components/empty_custom_float_output/empty_custom_float_output.cpp @@ -1,8 +1,11 @@ +#include "esphome/core/log.h" #include "empty_custom_float_output.h" namespace esphome { namespace empty_custom_float_output { +static const char *TAG = "empty_custom_float_output.output"; + void EmptyCustomFloatOutput::setup(){ } @@ -12,7 +15,7 @@ void EmptyCustomFloatOutput::write_state(float state){ } void EmptyCustomFloatOutput::dump_config() { - + ESP_LOGCONFIG(TAG, "Empty custom float output"); } } //namespace empty_custom_float_output diff --git a/custom_components/empty_custom_light/empty_custom_light.cpp b/custom_components/empty_custom_light/empty_custom_light.cpp index 2680d13..d7c50b8 100644 --- a/custom_components/empty_custom_light/empty_custom_light.cpp +++ b/custom_components/empty_custom_light/empty_custom_light.cpp @@ -1,9 +1,11 @@ -#include "esphome.h" +#include "esphome/core/log.h" #include "empty_custom_light.h" namespace esphome { namespace empty_custom_light { +static const char *TAG = "empty_custom_light.light"; + void EmptyCustomLightOutput::setup() { } @@ -23,7 +25,7 @@ void EmptyCustomLightOutput::write_state(light::LightState *state) { } void EmptyCustomLightOutput::dump_config(){ - + ESP_LOGCONFIG(TAG, "Empty custom light"); } } //namespace empty_custom_light diff --git a/custom_components/empty_custom_light/empty_custom_light.h b/custom_components/empty_custom_light/empty_custom_light.h index 7d8b13d..6667731 100644 --- a/custom_components/empty_custom_light/empty_custom_light.h +++ b/custom_components/empty_custom_light/empty_custom_light.h @@ -1,6 +1,7 @@ #pragma once #include "esphome/core/component.h" +#include "esphome/components/output/float_output.h" #include "esphome/components/light/light_output.h" namespace esphome { diff --git a/custom_components/empty_custom_sensor/empty_custom_sensor.cpp b/custom_components/empty_custom_sensor/empty_custom_sensor.cpp index f0385df..71d1352 100644 --- a/custom_components/empty_custom_sensor/empty_custom_sensor.cpp +++ b/custom_components/empty_custom_sensor/empty_custom_sensor.cpp @@ -1,9 +1,11 @@ -#include "esphome.h" +#include "esphome/core/log.h" #include "empty_custom_sensor.h" namespace esphome { namespace empty_custom_sensor { +static const char *TAG = "empty_custom_sensor.sensor"; + void EmptyCustomSensor::setup() { } @@ -17,7 +19,7 @@ void EmptyCustomSensor::update() { } void EmptyCustomSensor::dump_config() { - + ESP_LOGCONFIG(TAG, "Empty custom sensor"); } } //namespace empty_custom_sensor diff --git a/custom_components/empty_custom_switch/empty_custom_switch.cpp b/custom_components/empty_custom_switch/empty_custom_switch.cpp index 88ef417..d7e38fc 100644 --- a/custom_components/empty_custom_switch/empty_custom_switch.cpp +++ b/custom_components/empty_custom_switch/empty_custom_switch.cpp @@ -1,9 +1,10 @@ -#include "esphome.h" +#include "esphome/core/log.h" #include "empty_custom_switch.h" namespace esphome { namespace empty_custom_switch { +static const char *TAG = "empty_custom_switch.switch"; void EmptyCustomSwitch::setup() { @@ -13,5 +14,9 @@ void EmptyCustomSwitch::write_state(bool state) { } +void EmptyCustomSwitch::dump_config(){ + ESP_LOGCONFIG(TAG, "Empty custom switch"); +} + } //namespace empty_custom_switch } //namespace esphome \ No newline at end of file diff --git a/custom_components/empty_custom_switch/empty_custom_switch.h b/custom_components/empty_custom_switch/empty_custom_switch.h index bcaa613..e192b19 100644 --- a/custom_components/empty_custom_switch/empty_custom_switch.h +++ b/custom_components/empty_custom_switch/empty_custom_switch.h @@ -10,6 +10,7 @@ class EmptyCustomSwitch : public switch_::Switch, public Component { public: void setup() override; void write_state(bool state) override; + void dump_config() override; }; } //namespace empty_custom_switch diff --git a/custom_components/empty_text_sensor/empty_text_sensor.cpp b/custom_components/empty_text_sensor/empty_text_sensor.cpp new file mode 100644 index 0000000..d59b4a6 --- /dev/null +++ b/custom_components/empty_text_sensor/empty_text_sensor.cpp @@ -0,0 +1,18 @@ +#include "esphome/core/log.h" +#include "empty_text_sensor.h" + +namespace esphome { +namespace empty_text_sensor { + +static const char *TAG = "empty_text_sensor.text_sensor"; + +void EmptyTextSensor::setup() { + +} + +void EmptyTextSensor::dump_config() { + ESP_LOGCONFIG(TAG, "Empty text sensor"); +} + +} // namespace empty_text_sensor +} // namespace esphome \ No newline at end of file diff --git a/custom_components/empty_text_sensor/empty_text_sensor.h b/custom_components/empty_text_sensor/empty_text_sensor.h new file mode 100644 index 0000000..2c8af50 --- /dev/null +++ b/custom_components/empty_text_sensor/empty_text_sensor.h @@ -0,0 +1,16 @@ +#pragma once + +#include "esphome/core/component.h" +#include "esphome/components/text_sensor/text_sensor.h" + +namespace esphome { +namespace empty_text_sensor { + +class EmptyTextSensor : public text_sensor::TextSensor, public Component { + public: + void setup() override; + void dump_config() override; +}; + +} // namespace empty_text_sensor +} // namespace esphome diff --git a/custom_components/empty_text_sensor/text_sensor.py b/custom_components/empty_text_sensor/text_sensor.py new file mode 100644 index 0000000..29dd770 --- /dev/null +++ b/custom_components/empty_text_sensor/text_sensor.py @@ -0,0 +1,18 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import text_sensor +from esphome.const import CONF_ID + +empty_text_sensor_ns = cg.esphome_ns.namespace('empty_text_sensor') +EmptyTextSensor = empty_text_sensor_ns.class_('EmptyTextSensor', text_sensor.TextSensor, cg.Component) + +CONFIG_SCHEMA = text_sensor.TEXT_SENSOR_SCHEMA.extend({ + cv.GenerateID(): cv.declare_id(EmptyTextSensor) +}).extend(cv.COMPONENT_SCHEMA) + + +def to_code(config): + var = cg.new_Pvariable(config[CONF_ID]) + yield text_sensor.register_text_sensor(var, config) + yield cg.register_component(var, config) + \ No newline at end of file diff --git a/custom_components/example_custom_sensor/example_custom_sensor.cpp b/custom_components/example_custom_sensor/example_custom_sensor.cpp index f209a8b..4cab1ea 100644 --- a/custom_components/example_custom_sensor/example_custom_sensor.cpp +++ b/custom_components/example_custom_sensor/example_custom_sensor.cpp @@ -1,4 +1,4 @@ -#include "esphome.h" +#include "esphome/core/log.h" #include "example_custom_sensor.h" namespace esphome { @@ -17,7 +17,7 @@ void ExampleCustomSensor::update(){ } void ExampleCustomSensor::dump_config(){ - + ESP_LOGCONFIG(TAG, "Empty custom sensor"); } } //namespace example_custom_sensor diff --git a/test_empty.yaml b/test_empty.yaml index 01a33d2..2883e24 100644 --- a/test_empty.yaml +++ b/test_empty.yaml @@ -23,4 +23,17 @@ light: switch: - platform: empty_custom_switch - id: empty_custom_switch_1 \ No newline at end of file + id: empty_custom_switch_1 + +fan: + - platform: empty_custom_fan + id: empty_custom_fan_1 + output: empty_custom_binary_output_1 + +text_sensor: + - platform: empty_text_sensor + id: empty_text_sensor_1 + +cover: + platform: empty_cover + id: empty_cover_1 \ No newline at end of file