1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-27 21:23:48 +00:00

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

View File

@@ -19,6 +19,7 @@ class PulseWidthSensorStore {
static void gpio_intr(PulseWidthSensorStore *arg);
uint32_t get_pulse_width_us() const { return this->last_width_; }
float get_pulse_width_s() const { return this->last_width_ / 1e6f; }
uint32_t get_last_rise() const { return last_rise_; }
protected:
ISRInternalGPIOPin *pin_;
@@ -26,9 +27,8 @@ class PulseWidthSensorStore {
volatile uint32_t last_rise_{0};
};
class PulseWidthSensor : public sensor::PollingSensorComponent {
class PulseWidthSensor : public sensor::Sensor, public PollingComponent {
public:
PulseWidthSensor(const std::string &name, uint32_t update_interval) : PollingSensorComponent(name, update_interval) {}
void set_pin(GPIOPin *pin) { pin_ = pin; }
void setup() override { this->store_.setup(this->pin_); }
void dump_config() override;

View File

@@ -2,23 +2,21 @@ 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_ID, CONF_NAME, CONF_PIN, CONF_UPDATE_INTERVAL, UNIT_SECOND, \
ICON_TIMER
from esphome.const import CONF_ID, CONF_PIN, UNIT_SECOND, ICON_TIMER
pulse_width_ns = cg.esphome_ns.namespace('pulse_width')
PulseWidthSensor = pulse_width_ns.class_('PulseWidthSensor', sensor.PollingSensorComponent)
CONFIG_SCHEMA = cv.nameable(sensor.sensor_schema(UNIT_SECOND, ICON_TIMER, 3).extend({
cv.GenerateID(): cv.declare_variable_id(PulseWidthSensor),
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_SECOND, ICON_TIMER, 3).extend({
cv.GenerateID(): cv.declare_id(PulseWidthSensor),
cv.Required(CONF_PIN): cv.All(pins.internal_gpio_input_pullup_pin_schema,
pins.validate_has_interrupt),
cv.Optional(CONF_UPDATE_INTERVAL, default='60s'): cv.update_interval,
}).extend(cv.COMPONENT_SCHEMA))
}).extend(cv.polling_component_schema('60s'))
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID], config[CONF_NAME], config[CONF_UPDATE_INTERVAL])
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
yield sensor.register_sensor(var, config)