esphome/esphomeyaml/components/light/__init__.py

40 lines
1.4 KiB
Python
Raw Normal View History

2018-04-07 01:23:03 +02:00
import esphomeyaml.config_validation as cv
2018-05-20 12:41:52 +02:00
from esphomeyaml.const import CONF_DEFAULT_TRANSITION_LENGTH, CONF_GAMMA_CORRECT, CONF_ID, \
CONF_MQTT_ID
from esphomeyaml.helpers import Application, Pvariable, add, esphomelib_ns, setup_mqtt_component
2018-04-07 01:23:03 +02:00
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
2018-05-20 12:41:52 +02:00
})
2018-04-07 01:23:03 +02:00
2018-05-20 12:41:52 +02:00
light_ns = esphomelib_ns.namespace('light')
LightState = light_ns.LightState
MQTTJSONLightComponent = light_ns.MQTTJSONLightComponent
ToggleAction = light_ns.ToggleAction
TurnOffAction = light_ns.TurnOffAction
TurnOnAction = light_ns.TurnOnAction
MakeLight = Application.MakeLight
2018-06-02 22:22:20 +02:00
LIGHT_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
cv.GenerateID(): cv.declare_variable_id(LightState),
cv.GenerateID(CONF_MQTT_ID): cv.declare_variable_id(MQTTJSONLightComponent),
})
2018-05-20 12:41:52 +02:00
def setup_light_core_(light_var, mqtt_var, config):
2018-04-07 01:23:03 +02:00
if CONF_DEFAULT_TRANSITION_LENGTH in config:
2018-05-20 12:41:52 +02:00
add(light_var.set_default_transition_length(config[CONF_DEFAULT_TRANSITION_LENGTH]))
2018-05-14 11:50:56 +02:00
if CONF_GAMMA_CORRECT in config:
2018-05-20 12:41:52 +02:00
add(light_var.set_gamma_correct(config[CONF_GAMMA_CORRECT]))
setup_mqtt_component(mqtt_var, config)
def setup_light(light_obj, mqtt_obj, config):
2018-06-02 22:22:20 +02:00
light_var = Pvariable(config[CONF_ID], light_obj, has_side_effects=False)
mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj, has_side_effects=False)
2018-05-20 12:41:52 +02:00
setup_light_core_(light_var, mqtt_var, config)
2018-05-06 15:56:12 +02:00
BUILD_FLAGS = '-DUSE_LIGHT'