additional components, clean-up

master
HB 5 years ago
parent fce81d14a9
commit 54c7dabb67

@ -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)

@ -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

@ -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

@ -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

@ -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

@ -0,0 +1,3 @@
import esphome.codegen as cg
empty_custom_fan_ns = cg.esphome_ns.namespace('empty_custom_fan')

@ -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))

@ -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

@ -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

@ -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

@ -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

@ -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 {

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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)

@ -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

@ -24,3 +24,16 @@ light:
switch:
- platform: empty_custom_switch
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
Loading…
Cancel
Save