1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 06:33:51 +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

@@ -48,16 +48,12 @@ struct PulseCounterStorage {
pulse_counter_t last_value{0};
};
class PulseCounterSensor : public sensor::PollingSensorComponent {
class PulseCounterSensor : public sensor::Sensor, public PollingComponent {
public:
explicit PulseCounterSensor(const std::string &name, GPIOPin *pin, uint32_t update_interval,
PulseCounterCountMode rising_edge_mode, PulseCounterCountMode falling_edge_mode,
uint32_t filter_us)
: sensor::PollingSensorComponent(name, update_interval), pin_(pin) {
this->storage_.rising_edge_mode = rising_edge_mode;
this->storage_.falling_edge_mode = falling_edge_mode;
this->storage_.filter_us = filter_us;
}
void set_pin(GPIOPin *pin) { pin_ = pin; }
void set_rising_edge_mode(PulseCounterCountMode mode) { storage_.rising_edge_mode = mode; }
void set_falling_edge_mode(PulseCounterCountMode mode) { storage_.falling_edge_mode = mode; }
void set_filter_us(uint32_t filter) { storage_.filter_us = filter; }
/// Unit of measurement is "pulses/min".
void setup() override;

View File

@@ -1,10 +1,10 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.components import sensor
import esphome.config_validation as cv
import esphome.codegen as cg
from esphome.const import CONF_COUNT_MODE, CONF_FALLING_EDGE, CONF_ID, CONF_INTERNAL_FILTER, \
CONF_NAME, CONF_PIN, CONF_RISING_EDGE, CONF_UPDATE_INTERVAL, CONF_NUMBER, \
CONF_ACCURACY_DECIMALS, CONF_ICON, CONF_UNIT_OF_MEASUREMENT, ICON_PULSE, UNIT_PULSES_PER_MINUTE
CONF_PIN, CONF_RISING_EDGE, CONF_UPDATE_INTERVAL, CONF_NUMBER, \
ICON_PULSE, UNIT_PULSES_PER_MINUTE
from esphome.core import CORE
pulse_counter_ns = cg.esphome_ns.namespace('pulse_counter')
@@ -15,7 +15,7 @@ COUNT_MODES = {
'DECREMENT': PulseCounterCountMode.PULSE_COUNTER_DECREMENT,
}
COUNT_MODE_SCHEMA = cv.one_of(*COUNT_MODES, upper=True)
COUNT_MODE_SCHEMA = cv.enum(COUNT_MODES, upper=True)
PulseCounterSensor = pulse_counter_ns.class_('PulseCounterSensor',
sensor.PollingSensorComponent)
@@ -38,8 +38,8 @@ def validate_pulse_counter_pin(value):
return value
CONFIG_SCHEMA = cv.nameable(sensor.SENSOR_SCHEMA.extend({
cv.GenerateID(): cv.declare_variable_id(PulseCounterSensor),
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_PULSES_PER_MINUTE, ICON_PULSE, 2).extend({
cv.GenerateID(): cv.declare_id(PulseCounterSensor),
cv.Required(CONF_PIN): validate_pulse_counter_pin,
cv.Optional(CONF_COUNT_MODE, default={
CONF_RISING_EDGE: 'INCREMENT',
@@ -50,20 +50,17 @@ CONFIG_SCHEMA = cv.nameable(sensor.SENSOR_SCHEMA.extend({
}),
cv.Optional(CONF_INTERNAL_FILTER, default='13us'): validate_internal_filter,
cv.Optional(CONF_UPDATE_INTERVAL, default='60s'): cv.update_interval,
cv.Optional(CONF_ACCURACY_DECIMALS, default=2): sensor.accuracy_decimals,
cv.Optional(CONF_ICON, default=ICON_PULSE): sensor.icon,
cv.Optional(CONF_UNIT_OF_MEASUREMENT, default=UNIT_PULSES_PER_MINUTE):
sensor.unit_of_measurement,
}).extend(cv.COMPONENT_SCHEMA))
}).extend(cv.polling_component_schema('60s'))
def to_code(config):
pin = yield cg.gpio_pin_expression(config[CONF_PIN])
count = config[CONF_COUNT_MODE]
var = cg.new_Pvariable(config[CONF_ID], config[CONF_NAME], pin, config[CONF_UPDATE_INTERVAL],
COUNT_MODES[count[CONF_RISING_EDGE]],
COUNT_MODES[count[CONF_FALLING_EDGE]],
config[CONF_INTERNAL_FILTER])
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
yield sensor.register_sensor(var, config)
pin = yield cg.gpio_pin_expression(config[CONF_PIN])
cg.add(var.set_pin(pin))
count = config[CONF_COUNT_MODE]
cg.add(var.set_rising_edge_mode(count[CONF_RISING_EDGE]))
cg.add(var.set_falling_edge_mode(count[CONF_FALLING_EDGE]))
cg.add(var.set_filter_us(config[CONF_INTERNAL_FILTER]))