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
+9 -10
View File
@@ -1,7 +1,7 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import i2c, sensor
from esphome.const import CONF_GAIN, CONF_ID, CONF_INTEGRATION_TIME, CONF_UPDATE_INTERVAL, CONF_NAME
from esphome.const import CONF_GAIN, CONF_ID, CONF_INTEGRATION_TIME, UNIT_LUX, ICON_BRIGHTNESS_5
DEPENDENCIES = ['i2c']
@@ -24,26 +24,25 @@ CONF_IS_CS_PACKAGE = 'is_cs_package'
def validate_integration_time(value):
value = cv.positive_time_period_milliseconds(value).total_milliseconds
return cv.one_of(*INTEGRATION_TIMES, int=True)(value)
return cv.enum(INTEGRATION_TIMES, int=True)(value)
TSL2561Sensor = tsl2561_ns.class_('TSL2561Sensor', sensor.PollingSensorComponent, i2c.I2CDevice)
CONFIG_SCHEMA = cv.nameable(sensor.SENSOR_SCHEMA.extend({
cv.GenerateID(): cv.declare_variable_id(TSL2561Sensor),
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_LUX, ICON_BRIGHTNESS_5, 1).extend({
cv.GenerateID(): cv.declare_id(TSL2561Sensor),
cv.Optional(CONF_INTEGRATION_TIME, default=402): validate_integration_time,
cv.Optional(CONF_GAIN, default='1X'): cv.one_of(*GAINS, upper=True),
cv.Optional(CONF_GAIN, default='1X'): cv.enum(GAINS, upper=True),
cv.Optional(CONF_IS_CS_PACKAGE, default=False): cv.boolean,
cv.Optional(CONF_UPDATE_INTERVAL, default='60s'): cv.update_interval,
}).extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(0x39)))
}).extend(cv.polling_component_schema('60s')).extend(i2c.i2c_device_schema(0x39))
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 i2c.register_i2c_device(var, config)
yield sensor.register_sensor(var, config)
cg.add(var.set_integration_time(INTEGRATION_TIMES[config[CONF_INTEGRATION_TIME]]))
cg.add(var.set_gain(GAINS[config[CONF_GAIN]]))
cg.add(var.set_integration_time(config[CONF_INTEGRATION_TIME]))
cg.add(var.set_gain(config[CONF_GAIN]))
cg.add(var.set_is_cs_package(config[CONF_IS_CS_PACKAGE]))
-2
View File
@@ -159,8 +159,6 @@ bool TSL2561Sensor::tsl2561_read_uint(uint8_t a_register, uint16_t *value) {
bool TSL2561Sensor::tsl2561_read_byte(uint8_t a_register, uint8_t *value) {
return this->read_byte(a_register | TSL2561_COMMAND_BIT, value);
}
TSL2561Sensor::TSL2561Sensor(const std::string &name, uint32_t update_interval)
: PollingSensorComponent(name, update_interval) {}
} // namespace tsl2561
} // namespace esphome
+1 -3
View File
@@ -27,10 +27,8 @@ enum TSL2561Gain {
};
/// This class includes support for the TSL2561 i2c ambient light sensor.
class TSL2561Sensor : public sensor::PollingSensorComponent, public i2c::I2CDevice {
class TSL2561Sensor : public sensor::Sensor, public PollingComponent, public i2c::I2CDevice {
public:
TSL2561Sensor(const std::string &name, uint32_t update_interval);
/** Set the time that sensor values should be accumulated for.
*
* Longer means more accurate, but also mean more power consumption.