mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-29 22:24:26 +00:00 
			
		
		
		
	New coroutine-based task execution
This commit is contained in:
		| @@ -8,13 +8,6 @@ PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({ | ||||
|  | ||||
| }) | ||||
|  | ||||
| SWITCH_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({ | ||||
|     cv.GenerateID('switch_'): cv.register_variable_id, | ||||
|     cv.GenerateID('mqtt_switch', CONF_MQTT_ID): cv.register_variable_id, | ||||
|     vol.Optional(CONF_ICON): cv.icon, | ||||
|     vol.Optional(CONF_INVERTED): cv.boolean, | ||||
| }) | ||||
|  | ||||
| switch_ns = esphomelib_ns.namespace('switch_') | ||||
| Switch = switch_ns.Switch | ||||
| MQTTSwitchComponent = switch_ns.MQTTSwitchComponent | ||||
| @@ -22,6 +15,13 @@ ToggleAction = switch_ns.ToggleAction | ||||
| TurnOffAction = switch_ns.TurnOffAction | ||||
| TurnOnAction = switch_ns.TurnOnAction | ||||
|  | ||||
| SWITCH_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({ | ||||
|     cv.GenerateID(): cv.declare_variable_id(Switch), | ||||
|     cv.GenerateID(CONF_MQTT_ID): cv.declare_variable_id(MQTTSwitchComponent), | ||||
|     vol.Optional(CONF_ICON): cv.icon, | ||||
|     vol.Optional(CONF_INVERTED): cv.boolean, | ||||
| }) | ||||
|  | ||||
|  | ||||
| def setup_switch_core_(switch_var, mqtt_var, config): | ||||
|     if CONF_ICON in config: | ||||
| @@ -33,17 +33,15 @@ def setup_switch_core_(switch_var, mqtt_var, config): | ||||
|  | ||||
|  | ||||
| def setup_switch(switch_obj, mqtt_obj, config): | ||||
|     switch_var = Pvariable(Switch, config[CONF_ID], switch_obj, has_side_effects=False) | ||||
|     mqtt_var = Pvariable(MQTTSwitchComponent, config[CONF_MQTT_ID], mqtt_obj, | ||||
|                          has_side_effects=False) | ||||
|     switch_var = Pvariable(config[CONF_ID], switch_obj, has_side_effects=False) | ||||
|     mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj, has_side_effects=False) | ||||
|     setup_switch_core_(switch_var, mqtt_var, config) | ||||
|  | ||||
|  | ||||
| def register_switch(var, config): | ||||
|     switch_var = Pvariable(Switch, config[CONF_ID], var, has_side_effects=True) | ||||
|     switch_var = Pvariable(config[CONF_ID], var, has_side_effects=True) | ||||
|     rhs = App.register_switch(switch_var) | ||||
|     mqtt_var = Pvariable(MQTTSwitchComponent, config[CONF_MQTT_ID], rhs, | ||||
|                          has_side_effects=True) | ||||
|     mqtt_var = Pvariable(config[CONF_MQTT_ID], rhs, has_side_effects=True) | ||||
|     setup_switch_core_(switch_var, mqtt_var, config) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -6,17 +6,20 @@ from esphomeyaml.components import switch | ||||
| from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_PIN | ||||
| from esphomeyaml.helpers import App, Application, gpio_output_pin_expression, variable | ||||
|  | ||||
| MakeGPIOSwitch = Application.MakeGPIOSwitch | ||||
|  | ||||
| PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({ | ||||
|     cv.GenerateID('gpio_switch', CONF_MAKE_ID): cv.register_variable_id, | ||||
|     cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeGPIOSwitch), | ||||
|     vol.Required(CONF_PIN): pins.GPIO_OUTPUT_PIN_SCHEMA, | ||||
| }).extend(switch.SWITCH_SCHEMA.schema) | ||||
|  | ||||
| MakeGPIOSwitch = Application.MakeGPIOSwitch | ||||
|  | ||||
|  | ||||
| def to_code(config): | ||||
|     rhs = App.make_gpio_switch(config[CONF_NAME], gpio_output_pin_expression(config[CONF_PIN])) | ||||
|     gpio = variable(MakeGPIOSwitch, config[CONF_MAKE_ID], rhs) | ||||
|     pin = None | ||||
|     for pin in gpio_output_pin_expression(config[CONF_PIN]): | ||||
|         yield | ||||
|     rhs = App.make_gpio_switch(config[CONF_NAME], pin) | ||||
|     gpio = variable(config[CONF_MAKE_ID], rhs) | ||||
|     switch.setup_switch(gpio.Pswitch_, gpio.Pmqtt, config) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -17,7 +17,6 @@ WAIT_TIME_MESSAGE = "The wait_time_us option has been renamed to wait_time in or | ||||
|                     "ambiguity. " | ||||
|  | ||||
| PLATFORM_SCHEMA = vol.All(switch.PLATFORM_SCHEMA.extend({ | ||||
|     cv.GenerateID('ir_transmitter_switch'): cv.register_variable_id, | ||||
|     vol.Exclusive(CONF_NEC, 'code'): vol.Schema({ | ||||
|         vol.Required(CONF_ADDRESS): cv.hex_uint16_t, | ||||
|         vol.Required(CONF_COMMAND): cv.hex_uint16_t, | ||||
| @@ -44,7 +43,7 @@ PLATFORM_SCHEMA = vol.All(switch.PLATFORM_SCHEMA.extend({ | ||||
|  | ||||
|         vol.Optional('wait_time_us'): cv.invalid(WAIT_TIME_MESSAGE), | ||||
|     })), | ||||
|     vol.Optional(CONF_IR_TRANSMITTER_ID): cv.variable_id, | ||||
|     cv.GenerateID(CONF_IR_TRANSMITTER_ID): cv.use_variable_id(IRTransmitterComponent), | ||||
|     vol.Optional(CONF_INVERTED): cv.invalid("IR Transmitters do not support inverted mode!"), | ||||
| }).extend(switch.SWITCH_SCHEMA.schema), cv.has_at_least_one_key(*IR_KEYS)) | ||||
|  | ||||
| @@ -94,7 +93,9 @@ def exp_send_data(config): | ||||
|  | ||||
|  | ||||
| def to_code(config): | ||||
|     ir = get_variable(config.get(CONF_IR_TRANSMITTER_ID), IRTransmitterComponent) | ||||
|     ir = None | ||||
|     for ir in get_variable(config[CONF_IR_TRANSMITTER_ID]): | ||||
|         yield | ||||
|     send_data = exp_send_data(config) | ||||
|     rhs = App.register_component(ir.create_transmitter(config[CONF_NAME], send_data)) | ||||
|     switch.register_switch(rhs, config) | ||||
|   | ||||
| @@ -5,18 +5,20 @@ from esphomeyaml.components import switch | ||||
| from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_OUTPUT | ||||
| from esphomeyaml.helpers import App, Application, get_variable, variable | ||||
|  | ||||
| PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({ | ||||
|     cv.GenerateID('output_switch', CONF_MAKE_ID): cv.register_variable_id, | ||||
|     vol.Required(CONF_OUTPUT): cv.variable_id, | ||||
| }).extend(switch.SWITCH_SCHEMA.schema) | ||||
|  | ||||
| MakeSimpleSwitch = Application.MakeSimpleSwitch | ||||
|  | ||||
| PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({ | ||||
|     cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeSimpleSwitch), | ||||
|     vol.Required(CONF_OUTPUT): cv.use_variable_id(None), | ||||
| }).extend(switch.SWITCH_SCHEMA.schema) | ||||
|  | ||||
|  | ||||
| def to_code(config): | ||||
|     output = get_variable(config[CONF_OUTPUT]) | ||||
|     output = None | ||||
|     for output in get_variable(config[CONF_OUTPUT]): | ||||
|         yield | ||||
|     rhs = App.make_simple_switch(config[CONF_NAME], output) | ||||
|     gpio = variable(MakeSimpleSwitch, config[CONF_MAKE_ID], rhs) | ||||
|     gpio = variable(config[CONF_MAKE_ID], rhs) | ||||
|     switch.setup_switch(gpio.Pswitch_, gpio.Pmqtt, config) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -5,17 +5,17 @@ from esphomeyaml.components import switch | ||||
| from esphomeyaml.const import CONF_INVERTED, CONF_MAKE_ID, CONF_NAME | ||||
| from esphomeyaml.helpers import App, Application, variable | ||||
|  | ||||
| MakeRestartSwitch = Application.MakeRestartSwitch | ||||
|  | ||||
| PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({ | ||||
|     cv.GenerateID('restart_switch', CONF_MAKE_ID): cv.register_variable_id, | ||||
|     cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeRestartSwitch), | ||||
|     vol.Optional(CONF_INVERTED): cv.invalid("Restart switches do not support inverted mode!"), | ||||
| }).extend(switch.SWITCH_SCHEMA.schema) | ||||
|  | ||||
| MakeRestartSwitch = Application.MakeRestartSwitch | ||||
|  | ||||
|  | ||||
| def to_code(config): | ||||
|     rhs = App.make_restart_switch(config[CONF_NAME]) | ||||
|     restart = variable(MakeRestartSwitch, config[CONF_MAKE_ID], rhs) | ||||
|     restart = variable(config[CONF_MAKE_ID], rhs) | ||||
|     switch.setup_switch(restart.Prestart, restart.Pmqtt, config) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -5,17 +5,17 @@ from esphomeyaml.components import switch | ||||
| from esphomeyaml.const import CONF_INVERTED, CONF_MAKE_ID, CONF_NAME | ||||
| from esphomeyaml.helpers import App, Application, variable | ||||
|  | ||||
| MakeShutdownSwitch = Application.MakeShutdownSwitch | ||||
|  | ||||
| PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({ | ||||
|     cv.GenerateID('shutdown_switch', CONF_MAKE_ID): cv.register_variable_id, | ||||
|     cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeShutdownSwitch), | ||||
|     vol.Optional(CONF_INVERTED): cv.invalid("Shutdown switches do not support inverted mode!"), | ||||
| }).extend(switch.SWITCH_SCHEMA.schema) | ||||
|  | ||||
| MakeShutdownSwitch = Application.MakeShutdownSwitch | ||||
|  | ||||
|  | ||||
| def to_code(config): | ||||
|     rhs = App.make_shutdown_switch(config[CONF_NAME]) | ||||
|     shutdown = variable(MakeShutdownSwitch, config[CONF_MAKE_ID], rhs) | ||||
|     shutdown = variable(config[CONF_MAKE_ID], rhs) | ||||
|     switch.setup_switch(shutdown.Pshutdown, shutdown.Pmqtt, config) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -7,29 +7,35 @@ from esphomeyaml.const import CONF_LAMBDA, CONF_MAKE_ID, CONF_NAME, CONF_TURN_OF | ||||
|     CONF_TURN_ON_ACTION, CONF_OPTIMISTIC | ||||
| from esphomeyaml.helpers import App, Application, process_lambda, variable, NoArg, add | ||||
|  | ||||
| MakeTemplateSwitch = Application.MakeTemplateSwitch | ||||
|  | ||||
| PLATFORM_SCHEMA = vol.All(switch.PLATFORM_SCHEMA.extend({ | ||||
|     cv.GenerateID('template_switch', CONF_MAKE_ID): cv.register_variable_id, | ||||
|     cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeTemplateSwitch), | ||||
|     vol.Optional(CONF_LAMBDA): cv.lambda_, | ||||
|     vol.Optional(CONF_OPTIMISTIC): cv.boolean, | ||||
|     vol.Optional(CONF_TURN_OFF_ACTION): automation.ACTIONS_SCHEMA, | ||||
|     vol.Optional(CONF_TURN_ON_ACTION): automation.ACTIONS_SCHEMA, | ||||
| }).extend(switch.SWITCH_SCHEMA.schema), cv.has_at_least_one_key(CONF_LAMBDA, CONF_OPTIMISTIC)) | ||||
|  | ||||
| MakeTemplateSwitch = Application.MakeTemplateSwitch | ||||
|  | ||||
|  | ||||
| def to_code(config): | ||||
|     rhs = App.make_template_switch(config[CONF_NAME]) | ||||
|     make = variable(MakeTemplateSwitch, config[CONF_MAKE_ID], rhs) | ||||
|     make = variable(config[CONF_MAKE_ID], rhs) | ||||
|  | ||||
|     if CONF_LAMBDA in config: | ||||
|         template_ = process_lambda(config[CONF_LAMBDA], []) | ||||
|         template_ = None | ||||
|         for template_ in process_lambda(config[CONF_LAMBDA], []): | ||||
|             yield | ||||
|         add(make.Ptemplate_.set_state_lambda(template_)) | ||||
|     if CONF_TURN_OFF_ACTION in config: | ||||
|         actions = automation.build_actions(config[CONF_TURN_OFF_ACTION], NoArg) | ||||
|         actions = None | ||||
|         for actions in automation.build_actions(config[CONF_TURN_OFF_ACTION], NoArg): | ||||
|             yield | ||||
|         add(make.Ptemplate_.add_turn_off_actions(actions)) | ||||
|     if CONF_TURN_ON_ACTION in config: | ||||
|         actions = automation.build_actions(config[CONF_TURN_ON_ACTION], NoArg) | ||||
|         actions = None | ||||
|         for actions in automation.build_actions(config[CONF_TURN_ON_ACTION], NoArg): | ||||
|             yield | ||||
|         add(make.Ptemplate_.add_turn_on_actions(actions)) | ||||
|     if CONF_OPTIMISTIC in config: | ||||
|         add(make.Ptemplate_.set_optimistic(config[CONF_OPTIMISTIC])) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user