mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-13 08:03:32 +02: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:
@@ -32,17 +32,17 @@ void HLW8012Component::dump_config() {
|
||||
float HLW8012Component::get_setup_priority() const { return setup_priority::DATA; }
|
||||
void HLW8012Component::update() {
|
||||
// HLW8012 has 50% duty cycle
|
||||
const uint32_t last_rise_cf = this->cf_store_.get_last_rise();
|
||||
const uint32_t last_rise_cf1 = this->cf1_store_.get_last_rise();
|
||||
const uint32_t now = micros();
|
||||
float full_cycle_cf = this->cf_store_.get_pulse_width_s() * 2;
|
||||
float full_cycle_cf1 = this->cf1_store_.get_pulse_width_s() * 2;
|
||||
float cf_hz, cf1_hz;
|
||||
float cf_hz = 0.0f, cf1_hz = 0.0f;
|
||||
auto update_interval_micros = static_cast<uint32_t>(this->update_interval_ * 1e3f);
|
||||
|
||||
if (full_cycle_cf == 0.0f)
|
||||
cf_hz = 0.0f;
|
||||
else
|
||||
if (full_cycle_cf != 0.0f && now - last_rise_cf < update_interval_micros * 3)
|
||||
cf_hz = 1.0f / full_cycle_cf;
|
||||
if (full_cycle_cf1 == 0.0f)
|
||||
cf1_hz = 0.0f;
|
||||
else
|
||||
if (full_cycle_cf1 != 0.0f && now - last_rise_cf1 < update_interval_micros * 3)
|
||||
cf1_hz = 1.0f / full_cycle_cf1;
|
||||
|
||||
if (this->nth_value_++ < 2) {
|
||||
|
||||
@@ -10,8 +10,6 @@ namespace hlw8012 {
|
||||
|
||||
class HLW8012Component : public PollingComponent {
|
||||
public:
|
||||
HLW8012Component(uint32_t update_interval) : PollingComponent(update_interval) {}
|
||||
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
float get_setup_priority() const override;
|
||||
|
||||
@@ -3,8 +3,8 @@ import esphome.config_validation as cv
|
||||
from esphome import pins
|
||||
from esphome.components import sensor
|
||||
from esphome.const import CONF_CHANGE_MODE_EVERY, CONF_CURRENT, \
|
||||
CONF_CURRENT_RESISTOR, CONF_ID, CONF_POWER, CONF_SEL_PIN, CONF_UPDATE_INTERVAL, \
|
||||
CONF_VOLTAGE, CONF_VOLTAGE_DIVIDER, ICON_FLASH, UNIT_VOLT, UNIT_AMPERE, UNIT_WATT
|
||||
CONF_CURRENT_RESISTOR, CONF_ID, CONF_POWER, CONF_SEL_PIN, CONF_VOLTAGE, CONF_VOLTAGE_DIVIDER, \
|
||||
ICON_FLASH, UNIT_VOLT, UNIT_AMPERE, UNIT_WATT
|
||||
|
||||
AUTO_LOAD = ['pulse_width']
|
||||
|
||||
@@ -14,26 +14,25 @@ HLW8012Component = hlw8012_ns.class_('HLW8012Component', cg.PollingComponent)
|
||||
CONF_CF1_PIN = 'cf1_pin'
|
||||
CONF_CF_PIN = 'cf_pin'
|
||||
CONFIG_SCHEMA = cv.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(HLW8012Component),
|
||||
cv.GenerateID(): cv.declare_id(HLW8012Component),
|
||||
cv.Required(CONF_SEL_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Required(CONF_CF_PIN): cv.All(pins.internal_gpio_input_pullup_pin_schema,
|
||||
pins.validate_has_interrupt),
|
||||
cv.Required(CONF_CF1_PIN): cv.All(pins.internal_gpio_input_pullup_pin_schema,
|
||||
pins.validate_has_interrupt),
|
||||
|
||||
cv.Optional(CONF_VOLTAGE): cv.nameable(sensor.sensor_schema(UNIT_VOLT, ICON_FLASH, 1)),
|
||||
cv.Optional(CONF_CURRENT): cv.nameable(sensor.sensor_schema(UNIT_AMPERE, ICON_FLASH, 2)),
|
||||
cv.Optional(CONF_POWER): cv.nameable(sensor.sensor_schema(UNIT_WATT, ICON_FLASH, 1)),
|
||||
cv.Optional(CONF_VOLTAGE): sensor.sensor_schema(UNIT_VOLT, ICON_FLASH, 1),
|
||||
cv.Optional(CONF_CURRENT): sensor.sensor_schema(UNIT_AMPERE, ICON_FLASH, 2),
|
||||
cv.Optional(CONF_POWER): sensor.sensor_schema(UNIT_WATT, ICON_FLASH, 1),
|
||||
|
||||
cv.Optional(CONF_CURRENT_RESISTOR, default=0.001): cv.resistance,
|
||||
cv.Optional(CONF_VOLTAGE_DIVIDER, default=2351): cv.positive_float,
|
||||
cv.Optional(CONF_CHANGE_MODE_EVERY, default=8): cv.All(cv.uint32_t, cv.Range(min=1)),
|
||||
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_UPDATE_INTERVAL])
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
|
||||
sel = yield cg.gpio_pin_expression(config[CONF_SEL_PIN])
|
||||
|
||||
Reference in New Issue
Block a user