mirror of
https://github.com/esphome/esphome.git
synced 2025-10-30 14:43: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:
@@ -7,12 +7,12 @@ DEPENDENCIES = ['i2c']
|
||||
AUTO_LOAD = ['binary_sensor']
|
||||
|
||||
CONF_TTP229_ID = 'ttp229_id'
|
||||
ttp229_ns = cg.esphome_ns.namespace('ttp229')
|
||||
ttp229_lsf_ns = cg.esphome_ns.namespace('ttp229_lsf')
|
||||
|
||||
TTP229LSFComponent = ttp229_ns.class_('TTP229LSFComponent', cg.Component)
|
||||
TTP229LSFComponent = ttp229_lsf_ns.class_('TTP229LSFComponent', cg.Component, i2c.I2CDevice)
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(TTP229LSFComponent),
|
||||
cv.GenerateID(): cv.declare_id(TTP229LSFComponent),
|
||||
}).extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(0x57))
|
||||
|
||||
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
from esphome.components import binary_sensor
|
||||
import esphome.config_validation as cv
|
||||
import esphome.codegen as cg
|
||||
from esphome.const import CONF_CHANNEL, CONF_NAME, CONF_ID
|
||||
from . import ttp229_ns, TTP229LSFComponent, CONF_TTP229_ID
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import binary_sensor
|
||||
from esphome.const import CONF_CHANNEL, CONF_ID
|
||||
from . import ttp229_lsf_ns, TTP229LSFComponent, CONF_TTP229_ID
|
||||
|
||||
DEPENDENCIES = ['ttp229_lsf']
|
||||
TTP229Channel = ttp229_ns.class_('TTP229Channel', binary_sensor.BinarySensor)
|
||||
TTP229Channel = ttp229_lsf_ns.class_('TTP229Channel', binary_sensor.BinarySensor)
|
||||
|
||||
CONFIG_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(TTP229Channel),
|
||||
cv.GenerateID(CONF_TTP229_ID): cv.use_variable_id(TTP229LSFComponent),
|
||||
cv.Required(CONF_CHANNEL): cv.All(cv.Coerce(int), cv.Range(min=0, max=15))
|
||||
}))
|
||||
CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_id(TTP229Channel),
|
||||
cv.GenerateID(CONF_TTP229_ID): cv.use_id(TTP229LSFComponent),
|
||||
cv.Required(CONF_CHANNEL): cv.All(cv.int_, cv.Range(min=0, max=15))
|
||||
})
|
||||
|
||||
|
||||
def to_code(config):
|
||||
hub = yield cg.get_variable(config[CONF_TTP229_ID])
|
||||
var = cg.new_Pvariable(config[CONF_ID], config[CONF_NAME], config[CONF_CHANNEL])
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield binary_sensor.register_binary_sensor(var, config)
|
||||
|
||||
cg.add(var.set_channel(config[CONF_CHANNEL]))
|
||||
hub = yield cg.get_variable(config[CONF_TTP229_ID])
|
||||
cg.add(hub.register_channel(var))
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "ttp229.h"
|
||||
#include "ttp229_lsf.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ttp229 {
|
||||
namespace ttp229_lsf {
|
||||
|
||||
static const char *TAG = "ttp229";
|
||||
static const char *TAG = "ttp229_lsf";
|
||||
|
||||
void TTP229LSFComponent::setup() {
|
||||
ESP_LOGCONFIG(TAG, "Setting up ttp229...");
|
||||
@@ -39,5 +39,5 @@ void TTP229LSFComponent::loop() {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ttp229
|
||||
} // namespace ttp229_lsf
|
||||
} // namespace esphome
|
||||
@@ -5,15 +5,15 @@
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace ttp229 {
|
||||
namespace ttp229_lsf {
|
||||
|
||||
class TTP229Channel : public binary_sensor::BinarySensor {
|
||||
public:
|
||||
TTP229Channel(const std::string &name, int channel) : BinarySensor(name), channel_(channel) {}
|
||||
void set_channel(uint8_t channel) { channel_ = channel; }
|
||||
void process(uint16_t data) { this->publish_state(data & (1 << this->channel_)); }
|
||||
|
||||
protected:
|
||||
int channel_;
|
||||
uint8_t channel_;
|
||||
};
|
||||
|
||||
class TTP229LSFComponent : public Component, public i2c::I2CDevice {
|
||||
@@ -32,5 +32,5 @@ class TTP229LSFComponent : public Component, public i2c::I2CDevice {
|
||||
} error_code_{NONE};
|
||||
};
|
||||
|
||||
} // namespace ttp229
|
||||
} // namespace ttp229_lsf
|
||||
} // namespace esphome
|
||||
Reference in New Issue
Block a user