Cleanup dashboard JS (#491)

* Cleanup dashboard JS

* Add vscode

* Save start_mark/end_mark

* Updates

* Updates

* Remove need for cv.nameable

It's a bit hacky but removes so much bloat from integrations

* Add enum helper

* Document APIs, and Improvements

* Fixes

* Fixes

* Update PULL_REQUEST_TEMPLATE.md

* Updates

* Updates

* Updates
This commit is contained in:
Otto Winter
2019-04-22 21:56:30 +02:00
committed by GitHub
parent 6682c43dfa
commit 8e75980ebd
359 changed files with 4395 additions and 4223 deletions
+19 -19
View File
@@ -2,8 +2,8 @@ import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.components import sensor
from esphome.const import CONF_ECHO_PIN, CONF_ID, CONF_NAME, CONF_TRIGGER_PIN, \
CONF_UPDATE_INTERVAL, CONF_TIMEOUT, UNIT_METER, ICON_ARROW_EXPAND_VERTICAL
from esphome.const import CONF_ECHO_PIN, CONF_ID, CONF_TRIGGER_PIN, \
CONF_TIMEOUT, UNIT_METER, ICON_ARROW_EXPAND_VERTICAL
CONF_PULSE_TIME = 'pulse_time'
@@ -11,30 +11,30 @@ ultrasonic_ns = cg.esphome_ns.namespace('ultrasonic')
UltrasonicSensorComponent = ultrasonic_ns.class_('UltrasonicSensorComponent',
sensor.PollingSensorComponent)
CONFIG_SCHEMA = cv.nameable(
sensor.sensor_schema(UNIT_METER, ICON_ARROW_EXPAND_VERTICAL, 2).extend({
cv.GenerateID(): cv.declare_variable_id(UltrasonicSensorComponent),
cv.Required(CONF_TRIGGER_PIN): pins.gpio_output_pin_schema,
cv.Required(CONF_ECHO_PIN): pins.internal_gpio_input_pin_schema,
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_METER, ICON_ARROW_EXPAND_VERTICAL, 2).extend({
cv.GenerateID(): cv.declare_id(UltrasonicSensorComponent),
cv.Required(CONF_TRIGGER_PIN): pins.gpio_output_pin_schema,
cv.Required(CONF_ECHO_PIN): pins.internal_gpio_input_pin_schema,
cv.Optional(CONF_TIMEOUT, default='2m'): cv.distance,
cv.Optional(CONF_PULSE_TIME, default='10us'): cv.positive_time_period_microseconds,
cv.Optional(CONF_UPDATE_INTERVAL, default='60s'): cv.update_interval,
cv.Optional(CONF_TIMEOUT, default='2m'): cv.distance,
cv.Optional(CONF_PULSE_TIME, default='10us'): cv.positive_time_period_microseconds,
cv.Optional('timeout_meter'): cv.invalid("The timeout_meter option has been renamed "
"to 'timeout' in 1.12."),
cv.Optional('timeout_time'): cv.invalid("The timeout_time option has been removed. Please "
"use 'timeout' in 1.12."),
}))
cv.Optional('timeout_meter'): cv.invalid("The timeout_meter option has been renamed "
"to 'timeout' in 1.12."),
cv.Optional('timeout_time'): cv.invalid("The timeout_time option has been removed. Please "
"use 'timeout' in 1.12."),
}).extend(cv.polling_component_schema('60s'))
def to_code(config):
trigger = yield cg.gpio_pin_expression(config[CONF_TRIGGER_PIN])
echo = yield cg.gpio_pin_expression(config[CONF_ECHO_PIN])
var = cg.new_Pvariable(config[CONF_ID], config[CONF_NAME], trigger, echo,
config[CONF_UPDATE_INTERVAL])
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
yield sensor.register_sensor(var, config)
trigger = yield cg.gpio_pin_expression(config[CONF_TRIGGER_PIN])
cg.add(var.set_trigger_pin(trigger))
echo = yield cg.gpio_pin_expression(config[CONF_ECHO_PIN])
cg.add(var.set_echo_pin(echo))
cg.add(var.set_timeout_us(config[CONF_TIMEOUT] / (0.000343 / 2)))
cg.add(var.set_pulse_time_us(config[CONF_PULSE_TIME]))
@@ -6,9 +6,6 @@ namespace ultrasonic {
static const char *TAG = "ultrasonic.sensor";
UltrasonicSensorComponent::UltrasonicSensorComponent(const std::string &name, GPIOPin *trigger_pin, GPIOPin *echo_pin,
uint32_t update_interval)
: PollingSensorComponent(name, update_interval), trigger_pin_(trigger_pin), echo_pin_(echo_pin) {}
void UltrasonicSensorComponent::setup() {
ESP_LOGCONFIG(TAG, "Setting up Ultrasonic Sensor...");
this->trigger_pin_->setup();
@@ -7,15 +7,10 @@
namespace esphome {
namespace ultrasonic {
class UltrasonicSensorComponent : public sensor::PollingSensorComponent {
class UltrasonicSensorComponent : public sensor::Sensor, public PollingComponent {
public:
/** Construct the ultrasonic sensor with the specified trigger pin and echo pin.
*
* @param trigger_pin The trigger pin where pulses are sent to.
* @param echo_pin The echo pin where the echo is listened for.
* @param update_interval The interval in ms the sensor should check for new values.
*/
UltrasonicSensorComponent(const std::string &name, GPIOPin *trigger_pin, GPIOPin *echo_pin, uint32_t update_interval);
void set_trigger_pin(GPIOPin *trigger_pin) { trigger_pin_ = trigger_pin; }
void set_echo_pin(GPIOPin *echo_pin) { echo_pin_ = echo_pin; }
/// Set the timeout for waiting for the echo in µs.
void set_timeout_us(uint32_t timeout_us);