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
+20 -20
View File
@@ -1,13 +1,15 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.automation import ACTION_REGISTRY
from esphome import automation
from esphome.components import mqtt
from esphome.const import CONF_AWAY, CONF_ID, CONF_INTERNAL, CONF_MAX_TEMPERATURE, \
CONF_MIN_TEMPERATURE, CONF_MODE, CONF_TARGET_TEMPERATURE, \
CONF_TARGET_TEMPERATURE_HIGH, CONF_TARGET_TEMPERATURE_LOW, CONF_TEMPERATURE_STEP, CONF_VISUAL, \
CONF_MQTT_ID
CONF_MQTT_ID, CONF_NAME
from esphome.core import CORE, coroutine
IS_PLATFORM_COMPONENT = True
climate_ns = cg.esphome_ns.namespace('climate')
ClimateDevice = climate_ns.class_('Climate', cg.Nameable)
@@ -23,14 +25,14 @@ CLIMATE_MODES = {
'HEAT': ClimateMode.CLIMATE_MODE_HEAT,
}
validate_climate_mode = cv.one_of(*CLIMATE_MODES, upper=True)
validate_climate_mode = cv.enum(CLIMATE_MODES, upper=True)
# Actions
ControlAction = climate_ns.class_('ControlAction', cg.Action)
ControlAction = climate_ns.class_('ControlAction', automation.Action)
CLIMATE_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
cv.GenerateID(): cv.declare_variable_id(ClimateDevice),
cv.OnlyWith(CONF_MQTT_ID, 'mqtt'): cv.declare_variable_id(mqtt.MQTTClimateComponent),
cv.GenerateID(): cv.declare_id(ClimateDevice),
cv.OnlyWith(CONF_MQTT_ID, 'mqtt'): cv.declare_id(mqtt.MQTTClimateComponent),
cv.Optional(CONF_VISUAL, default={}): cv.Schema({
cv.Optional(CONF_MIN_TEMPERATURE): cv.temperature,
cv.Optional(CONF_MAX_TEMPERATURE): cv.temperature,
@@ -42,6 +44,7 @@ CLIMATE_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
@coroutine
def setup_climate_core_(var, config):
cg.add(var.set_name(config[CONF_NAME]))
if CONF_INTERNAL in config:
cg.add(var.set_internal(config[CONF_INTERNAL]))
visual = config[CONF_VISUAL]
@@ -66,7 +69,7 @@ def register_climate(var, config):
CLIMATE_CONTROL_ACTION_SCHEMA = cv.Schema({
cv.Required(CONF_ID): cv.use_variable_id(ClimateDevice),
cv.Required(CONF_ID): cv.use_id(ClimateDevice),
cv.Optional(CONF_MODE): cv.templatable(validate_climate_mode),
cv.Optional(CONF_TARGET_TEMPERATURE): cv.templatable(cv.temperature),
cv.Optional(CONF_TARGET_TEMPERATURE_LOW): cv.templatable(cv.temperature),
@@ -75,29 +78,26 @@ CLIMATE_CONTROL_ACTION_SCHEMA = cv.Schema({
})
@ACTION_REGISTRY.register('climate.control', CLIMATE_CONTROL_ACTION_SCHEMA)
@automation.register_action('climate.control', ControlAction, CLIMATE_CONTROL_ACTION_SCHEMA)
def climate_control_to_code(config, action_id, template_arg, args):
var = yield cg.get_variable(config[CONF_ID])
type = ControlAction.template(template_arg)
rhs = type.new(var)
action = cg.Pvariable(action_id, rhs, type=type)
paren = yield cg.get_variable(config[CONF_ID])
var = cg.new_Pvariable(action_id, template_arg, paren)
if CONF_MODE in config:
template_ = yield cg.templatable(config[CONF_MODE], args, ClimateMode,
to_exp=CLIMATE_MODES)
cg.add(action.set_mode(template_))
template_ = yield cg.templatable(config[CONF_MODE], args, ClimateMode)
cg.add(var.set_mode(template_))
if CONF_TARGET_TEMPERATURE in config:
template_ = yield cg.templatable(config[CONF_TARGET_TEMPERATURE], args, float)
cg.add(action.set_target_temperature(template_))
cg.add(var.set_target_temperature(template_))
if CONF_TARGET_TEMPERATURE_LOW in config:
template_ = yield cg.templatable(config[CONF_TARGET_TEMPERATURE_LOW], args, float)
cg.add(action.set_target_temperature_low(template_))
cg.add(var.set_target_temperature_low(template_))
if CONF_TARGET_TEMPERATURE_HIGH in config:
template_ = yield cg.templatable(config[CONF_TARGET_TEMPERATURE_HIGH], args, float)
cg.add(action.set_target_temperature_high(template_))
cg.add(var.set_target_temperature_high(template_))
if CONF_AWAY in config:
template_ = yield cg.templatable(config[CONF_AWAY], args, bool)
cg.add(action.set_away(template_))
yield action
cg.add(var.set_away(template_))
yield var
def to_code(config):