mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-31 02:08:26 +02:00
Rename esphomeyaml to esphome (#426)
* Rename * Update * Add migration * Fix * Fix dashboard * Change test * Fixes * Code cleanup * Fix import order * Update * Automate docker builds * Shellcheck
This commit is contained in:
@@ -1,163 +0,0 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import automation
|
||||
from esphomeyaml.automation import maybe_simple_id, ACTION_REGISTRY, CONDITION_REGISTRY, Condition
|
||||
from esphomeyaml.components import mqtt
|
||||
from esphomeyaml.components.mqtt import setup_mqtt_component
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ICON, CONF_ID, CONF_INVERTED, CONF_MQTT_ID, CONF_INTERNAL, \
|
||||
CONF_OPTIMISTIC, CONF_ON_TURN_ON, CONF_ON_TURN_OFF, CONF_TRIGGER_ID
|
||||
from esphomeyaml.core import CORE
|
||||
from esphomeyaml.cpp_generator import add, Pvariable, get_variable
|
||||
from esphomeyaml.cpp_types import esphomelib_ns, Nameable, Action, App, Trigger, NoArg
|
||||
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||
|
||||
})
|
||||
|
||||
switch_ns = esphomelib_ns.namespace('switch_')
|
||||
Switch = switch_ns.class_('Switch', Nameable)
|
||||
SwitchPtr = Switch.operator('ptr')
|
||||
MQTTSwitchComponent = switch_ns.class_('MQTTSwitchComponent', mqtt.MQTTComponent)
|
||||
|
||||
ToggleAction = switch_ns.class_('ToggleAction', Action)
|
||||
TurnOffAction = switch_ns.class_('TurnOffAction', Action)
|
||||
TurnOnAction = switch_ns.class_('TurnOnAction', Action)
|
||||
|
||||
SwitchCondition = switch_ns.class_('SwitchCondition', Condition)
|
||||
SwitchTurnOnTrigger = switch_ns.class_('SwitchTurnOnTrigger', Trigger.template(NoArg))
|
||||
SwitchTurnOffTrigger = switch_ns.class_('SwitchTurnOffTrigger', Trigger.template(NoArg))
|
||||
|
||||
SWITCH_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
|
||||
cv.GenerateID(CONF_MQTT_ID): cv.declare_variable_id(MQTTSwitchComponent),
|
||||
vol.Optional(CONF_ICON): cv.icon,
|
||||
vol.Optional(CONF_INVERTED): cv.boolean,
|
||||
vol.Optional(CONF_ON_TURN_ON): automation.validate_automation({
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(SwitchTurnOnTrigger),
|
||||
}),
|
||||
vol.Optional(CONF_ON_TURN_OFF): automation.validate_automation({
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(SwitchTurnOffTrigger),
|
||||
}),
|
||||
})
|
||||
|
||||
SWITCH_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(SWITCH_SCHEMA.schema)
|
||||
|
||||
|
||||
def setup_switch_core_(switch_var, config):
|
||||
if CONF_INTERNAL in config:
|
||||
add(switch_var.set_internal(config[CONF_INTERNAL]))
|
||||
if CONF_ICON in config:
|
||||
add(switch_var.set_icon(config[CONF_ICON]))
|
||||
if CONF_INVERTED in config:
|
||||
add(switch_var.set_inverted(config[CONF_INVERTED]))
|
||||
for conf in config.get(CONF_ON_TURN_ON, []):
|
||||
rhs = switch_var.make_switch_turn_on_trigger()
|
||||
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
||||
automation.build_automation(trigger, NoArg, conf)
|
||||
for conf in config.get(CONF_ON_TURN_OFF, []):
|
||||
rhs = switch_var.make_switch_turn_off_trigger()
|
||||
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
|
||||
automation.build_automation(trigger, NoArg, conf)
|
||||
|
||||
setup_mqtt_component(switch_var.Pget_mqtt(), config)
|
||||
|
||||
|
||||
def setup_switch(switch_obj, config):
|
||||
if not CORE.has_id(config[CONF_ID]):
|
||||
switch_obj = Pvariable(config[CONF_ID], switch_obj, has_side_effects=True)
|
||||
CORE.add_job(setup_switch_core_, switch_obj, config)
|
||||
|
||||
|
||||
def register_switch(var, config):
|
||||
switch_var = Pvariable(config[CONF_ID], var, has_side_effects=True)
|
||||
add(App.register_switch(switch_var))
|
||||
CORE.add_job(setup_switch_core_, switch_var, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_SWITCH'
|
||||
|
||||
|
||||
CONF_SWITCH_TOGGLE = 'switch.toggle'
|
||||
SWITCH_TOGGLE_ACTION_SCHEMA = maybe_simple_id({
|
||||
vol.Required(CONF_ID): cv.use_variable_id(Switch),
|
||||
})
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_SWITCH_TOGGLE, SWITCH_TOGGLE_ACTION_SCHEMA)
|
||||
def switch_toggle_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_toggle_action(template_arg)
|
||||
type = ToggleAction.template(arg_type)
|
||||
yield Pvariable(action_id, rhs, type=type)
|
||||
|
||||
|
||||
CONF_SWITCH_TURN_OFF = 'switch.turn_off'
|
||||
SWITCH_TURN_OFF_ACTION_SCHEMA = maybe_simple_id({
|
||||
vol.Required(CONF_ID): cv.use_variable_id(Switch),
|
||||
})
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_SWITCH_TURN_OFF, SWITCH_TURN_OFF_ACTION_SCHEMA)
|
||||
def switch_turn_off_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_turn_off_action(template_arg)
|
||||
type = TurnOffAction.template(arg_type)
|
||||
yield Pvariable(action_id, rhs, type=type)
|
||||
|
||||
|
||||
CONF_SWITCH_TURN_ON = 'switch.turn_on'
|
||||
SWITCH_TURN_ON_ACTION_SCHEMA = maybe_simple_id({
|
||||
vol.Required(CONF_ID): cv.use_variable_id(Switch),
|
||||
})
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_SWITCH_TURN_ON, SWITCH_TURN_ON_ACTION_SCHEMA)
|
||||
def switch_turn_on_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_turn_on_action(template_arg)
|
||||
type = TurnOnAction.template(arg_type)
|
||||
yield Pvariable(action_id, rhs, type=type)
|
||||
|
||||
|
||||
CONF_SWITCH_IS_ON = 'switch.is_on'
|
||||
SWITCH_IS_ON_CONDITION_SCHEMA = maybe_simple_id({
|
||||
vol.Required(CONF_ID): cv.use_variable_id(Switch),
|
||||
})
|
||||
|
||||
|
||||
@CONDITION_REGISTRY.register(CONF_SWITCH_IS_ON, SWITCH_IS_ON_CONDITION_SCHEMA)
|
||||
def switch_is_on_to_code(config, condition_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_switch_is_on_condition(template_arg)
|
||||
type = SwitchCondition.template(arg_type)
|
||||
yield Pvariable(condition_id, rhs, type=type)
|
||||
|
||||
|
||||
CONF_SWITCH_IS_OFF = 'switch.is_off'
|
||||
SWITCH_IS_OFF_CONDITION_SCHEMA = maybe_simple_id({
|
||||
vol.Required(CONF_ID): cv.use_variable_id(Switch),
|
||||
})
|
||||
|
||||
|
||||
@CONDITION_REGISTRY.register(CONF_SWITCH_IS_OFF, SWITCH_IS_OFF_CONDITION_SCHEMA)
|
||||
def switch_is_off_to_code(config, condition_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_switch_is_off_condition(template_arg)
|
||||
type = SwitchCondition.template(arg_type)
|
||||
yield Pvariable(condition_id, rhs, type=type)
|
||||
|
||||
|
||||
def core_to_hass_config(data, config):
|
||||
ret = mqtt.build_hass_config(data, 'switch', config, include_state=True, include_command=True)
|
||||
if ret is None:
|
||||
return None
|
||||
if CONF_ICON in config:
|
||||
ret['icon'] = config[CONF_ICON]
|
||||
if CONF_OPTIMISTIC in config:
|
||||
ret['optimistic'] = config[CONF_OPTIMISTIC]
|
||||
return ret
|
||||
@@ -1,38 +0,0 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import switch
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_SWITCHES, CONF_NAME
|
||||
from esphomeyaml.cpp_generator import process_lambda, variable, Pvariable, add
|
||||
from esphomeyaml.cpp_types import std_vector
|
||||
|
||||
CustomSwitchConstructor = switch.switch_ns.class_('CustomSwitchConstructor')
|
||||
|
||||
PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(CustomSwitchConstructor),
|
||||
vol.Required(CONF_LAMBDA): cv.lambda_,
|
||||
vol.Required(CONF_SWITCHES):
|
||||
cv.ensure_list(switch.SWITCH_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(switch.Switch),
|
||||
})),
|
||||
})
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for template_ in process_lambda(config[CONF_LAMBDA], [],
|
||||
return_type=std_vector.template(switch.SwitchPtr)):
|
||||
yield
|
||||
|
||||
rhs = CustomSwitchConstructor(template_)
|
||||
custom = variable(config[CONF_ID], rhs)
|
||||
for i, conf in enumerate(config[CONF_SWITCHES]):
|
||||
var = Pvariable(conf[CONF_ID], custom.get_switch(i))
|
||||
add(var.set_name(conf[CONF_NAME]))
|
||||
switch.setup_switch(var, conf)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_CUSTOM_SWITCH'
|
||||
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return [switch.core_to_hass_config(data, swi) for swi in config[CONF_SWITCHES]]
|
||||
@@ -1,54 +0,0 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import switch
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_NAME, CONF_PIN, CONF_RESTORE_MODE, CONF_INTERLOCK
|
||||
from esphomeyaml.cpp_generator import Pvariable, add, get_variable
|
||||
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
||||
from esphomeyaml.cpp_types import App, Component
|
||||
|
||||
GPIOSwitch = switch.switch_ns.class_('GPIOSwitch', switch.Switch, Component)
|
||||
GPIOSwitchRestoreMode = switch.switch_ns.enum('GPIOSwitchRestoreMode')
|
||||
|
||||
RESTORE_MODES = {
|
||||
'RESTORE_DEFAULT_OFF': GPIOSwitchRestoreMode.GPIO_SWITCH_RESTORE_DEFAULT_OFF,
|
||||
'RESTORE_DEFAULT_ON': GPIOSwitchRestoreMode.GPIO_SWITCH_RESTORE_DEFAULT_ON,
|
||||
'ALWAYS_OFF': GPIOSwitchRestoreMode.GPIO_SWITCH_ALWAYS_OFF,
|
||||
'ALWAYS_ON': GPIOSwitchRestoreMode.GPIO_SWITCH_ALWAYS_ON,
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(GPIOSwitch),
|
||||
vol.Required(CONF_PIN): pins.gpio_output_pin_schema,
|
||||
vol.Optional(CONF_RESTORE_MODE): cv.one_of(*RESTORE_MODES, upper=True, space='_'),
|
||||
vol.Optional(CONF_INTERLOCK): cv.ensure_list(cv.use_variable_id(switch.Switch)),
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for pin in gpio_output_pin_expression(config[CONF_PIN]):
|
||||
yield
|
||||
rhs = App.make_gpio_switch(config[CONF_NAME], pin)
|
||||
gpio = Pvariable(config[CONF_ID], rhs)
|
||||
|
||||
if CONF_RESTORE_MODE in config:
|
||||
add(gpio.set_restore_mode(RESTORE_MODES[config[CONF_RESTORE_MODE]]))
|
||||
|
||||
if CONF_INTERLOCK in config:
|
||||
interlock = []
|
||||
for it in config[CONF_INTERLOCK]:
|
||||
for lock in get_variable(it):
|
||||
yield
|
||||
interlock.append(lock)
|
||||
add(gpio.set_interlock(interlock))
|
||||
|
||||
switch.setup_switch(gpio, config)
|
||||
setup_component(gpio, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_GPIO_SWITCH'
|
||||
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return switch.core_to_hass_config(data, config)
|
||||
@@ -1,32 +0,0 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import output, switch
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_NAME, CONF_OUTPUT
|
||||
from esphomeyaml.cpp_generator import Pvariable, get_variable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import App, Component
|
||||
|
||||
OutputSwitch = switch.switch_ns.class_('OutputSwitch', switch.Switch, Component)
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(OutputSwitch),
|
||||
vol.Required(CONF_OUTPUT): cv.use_variable_id(output.BinaryOutput),
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for output_ in get_variable(config[CONF_OUTPUT]):
|
||||
yield
|
||||
rhs = App.make_output_switch(config[CONF_NAME], output_)
|
||||
switch_ = Pvariable(config[CONF_ID], rhs)
|
||||
|
||||
switch.setup_switch(switch_, config)
|
||||
setup_component(switch, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_OUTPUT_SWITCH'
|
||||
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return switch.core_to_hass_config(data, config)
|
||||
@@ -1,162 +0,0 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import switch
|
||||
from esphomeyaml.components.remote_transmitter import RC_SWITCH_RAW_SCHEMA, \
|
||||
RC_SWITCH_TYPE_A_SCHEMA, RC_SWITCH_TYPE_B_SCHEMA, RC_SWITCH_TYPE_C_SCHEMA, \
|
||||
RC_SWITCH_TYPE_D_SCHEMA, RemoteTransmitterComponent, binary_code, build_rc_switch_protocol, \
|
||||
remote_ns
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_CARRIER_FREQUENCY, CONF_CHANNEL, CONF_CODE, \
|
||||
CONF_COMMAND, CONF_DATA, CONF_DEVICE, CONF_FAMILY, CONF_GROUP, CONF_INVERTED, CONF_JVC, \
|
||||
CONF_LG, CONF_NAME, CONF_NBITS, CONF_NEC, CONF_PANASONIC, CONF_PROTOCOL, CONF_RAW, \
|
||||
CONF_RC_SWITCH_RAW, CONF_RC_SWITCH_TYPE_A, CONF_RC_SWITCH_TYPE_B, CONF_RC_SWITCH_TYPE_C, \
|
||||
CONF_RC_SWITCH_TYPE_D, CONF_REPEAT, CONF_SAMSUNG, CONF_SONY, CONF_STATE, CONF_TIMES, \
|
||||
CONF_WAIT_TIME, CONF_ID
|
||||
from esphomeyaml.cpp_generator import Pvariable, add, get_variable, progmem_array
|
||||
from esphomeyaml.cpp_types import int32
|
||||
|
||||
DEPENDENCIES = ['remote_transmitter']
|
||||
|
||||
REMOTE_KEYS = [CONF_JVC, CONF_NEC, CONF_LG, CONF_SAMSUNG, CONF_SONY, CONF_PANASONIC, CONF_RAW,
|
||||
CONF_RC_SWITCH_RAW, CONF_RC_SWITCH_TYPE_A, CONF_RC_SWITCH_TYPE_B,
|
||||
CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_TYPE_D]
|
||||
|
||||
CONF_REMOTE_TRANSMITTER_ID = 'remote_transmitter_id'
|
||||
CONF_TRANSMITTER_ID = 'transmitter_id'
|
||||
|
||||
RemoteTransmitter = remote_ns.class_('RemoteTransmitter', switch.Switch)
|
||||
JVCTransmitter = remote_ns.class_('JVCTransmitter', RemoteTransmitter)
|
||||
LGTransmitter = remote_ns.class_('LGTransmitter', RemoteTransmitter)
|
||||
NECTransmitter = remote_ns.class_('NECTransmitter', RemoteTransmitter)
|
||||
PanasonicTransmitter = remote_ns.class_('PanasonicTransmitter', RemoteTransmitter)
|
||||
RawTransmitter = remote_ns.class_('RawTransmitter', RemoteTransmitter)
|
||||
SamsungTransmitter = remote_ns.class_('SamsungTransmitter', RemoteTransmitter)
|
||||
SonyTransmitter = remote_ns.class_('SonyTransmitter', RemoteTransmitter)
|
||||
RCSwitchRawTransmitter = remote_ns.class_('RCSwitchRawTransmitter', RemoteTransmitter)
|
||||
RCSwitchTypeATransmitter = remote_ns.class_('RCSwitchTypeATransmitter', RCSwitchRawTransmitter)
|
||||
RCSwitchTypeBTransmitter = remote_ns.class_('RCSwitchTypeBTransmitter', RCSwitchRawTransmitter)
|
||||
RCSwitchTypeCTransmitter = remote_ns.class_('RCSwitchTypeCTransmitter', RCSwitchRawTransmitter)
|
||||
RCSwitchTypeDTransmitter = remote_ns.class_('RCSwitchTypeDTransmitter', RCSwitchRawTransmitter)
|
||||
|
||||
|
||||
def validate_raw(value):
|
||||
if isinstance(value, dict):
|
||||
return vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(int32),
|
||||
vol.Required(CONF_DATA): [vol.Any(vol.Coerce(int), cv.time_period_microseconds)],
|
||||
vol.Optional(CONF_CARRIER_FREQUENCY): vol.All(cv.frequency, vol.Coerce(int)),
|
||||
})(value)
|
||||
return validate_raw({
|
||||
CONF_DATA: value
|
||||
})
|
||||
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(RemoteTransmitter),
|
||||
vol.Optional(CONF_JVC): vol.Schema({
|
||||
vol.Required(CONF_DATA): cv.hex_uint32_t,
|
||||
}),
|
||||
vol.Optional(CONF_LG): vol.Schema({
|
||||
vol.Required(CONF_DATA): cv.hex_uint32_t,
|
||||
vol.Optional(CONF_NBITS, default=28): cv.one_of(28, 32, int=True),
|
||||
}),
|
||||
vol.Optional(CONF_NEC): vol.Schema({
|
||||
vol.Required(CONF_ADDRESS): cv.hex_uint16_t,
|
||||
vol.Required(CONF_COMMAND): cv.hex_uint16_t,
|
||||
}),
|
||||
vol.Optional(CONF_SAMSUNG): vol.Schema({
|
||||
vol.Required(CONF_DATA): cv.hex_uint32_t,
|
||||
}),
|
||||
vol.Optional(CONF_SONY): vol.Schema({
|
||||
vol.Required(CONF_DATA): cv.hex_uint32_t,
|
||||
vol.Optional(CONF_NBITS, default=12): cv.one_of(12, 15, 20, int=True),
|
||||
}),
|
||||
vol.Optional(CONF_PANASONIC): vol.Schema({
|
||||
vol.Required(CONF_ADDRESS): cv.hex_uint16_t,
|
||||
vol.Required(CONF_COMMAND): cv.hex_uint32_t,
|
||||
}),
|
||||
vol.Optional(CONF_RAW): validate_raw,
|
||||
vol.Optional(CONF_RC_SWITCH_RAW): RC_SWITCH_RAW_SCHEMA,
|
||||
vol.Optional(CONF_RC_SWITCH_TYPE_A): RC_SWITCH_TYPE_A_SCHEMA,
|
||||
vol.Optional(CONF_RC_SWITCH_TYPE_B): RC_SWITCH_TYPE_B_SCHEMA,
|
||||
vol.Optional(CONF_RC_SWITCH_TYPE_C): RC_SWITCH_TYPE_C_SCHEMA,
|
||||
vol.Optional(CONF_RC_SWITCH_TYPE_D): RC_SWITCH_TYPE_D_SCHEMA,
|
||||
|
||||
vol.Optional(CONF_REPEAT): vol.Any(cv.positive_not_null_int, vol.Schema({
|
||||
vol.Required(CONF_TIMES): cv.positive_not_null_int,
|
||||
vol.Required(CONF_WAIT_TIME): cv.positive_time_period_microseconds,
|
||||
})),
|
||||
cv.GenerateID(CONF_REMOTE_TRANSMITTER_ID): cv.use_variable_id(RemoteTransmitterComponent),
|
||||
cv.GenerateID(CONF_TRANSMITTER_ID): cv.declare_variable_id(RemoteTransmitter),
|
||||
vol.Optional(CONF_INVERTED): cv.invalid("Remote Transmitters do not support inverted mode!"),
|
||||
}), cv.has_exactly_one_key(*REMOTE_KEYS))
|
||||
|
||||
|
||||
def transmitter_base(full_config):
|
||||
name = full_config[CONF_NAME]
|
||||
key, config = next((k, v) for k, v in full_config.items() if k in REMOTE_KEYS)
|
||||
|
||||
if key == CONF_JVC:
|
||||
return JVCTransmitter.new(name, config[CONF_DATA])
|
||||
if key == CONF_LG:
|
||||
return LGTransmitter.new(name, config[CONF_DATA], config[CONF_NBITS])
|
||||
if key == CONF_NEC:
|
||||
return NECTransmitter.new(name, config[CONF_ADDRESS], config[CONF_COMMAND])
|
||||
if key == CONF_PANASONIC:
|
||||
return PanasonicTransmitter.new(name, config[CONF_ADDRESS], config[CONF_COMMAND])
|
||||
if key == CONF_SAMSUNG:
|
||||
return SamsungTransmitter.new(name, config[CONF_DATA])
|
||||
if key == CONF_SONY:
|
||||
return SonyTransmitter.new(name, config[CONF_DATA], config[CONF_NBITS])
|
||||
if key == CONF_RAW:
|
||||
arr = progmem_array(config[CONF_ID], config[CONF_DATA])
|
||||
return RawTransmitter.new(name, arr, len(config[CONF_DATA]),
|
||||
config.get(CONF_CARRIER_FREQUENCY))
|
||||
if key == CONF_RC_SWITCH_RAW:
|
||||
return RCSwitchRawTransmitter.new(name, build_rc_switch_protocol(config[CONF_PROTOCOL]),
|
||||
binary_code(config[CONF_CODE]), len(config[CONF_CODE]))
|
||||
if key == CONF_RC_SWITCH_TYPE_A:
|
||||
return RCSwitchTypeATransmitter.new(name, build_rc_switch_protocol(config[CONF_PROTOCOL]),
|
||||
binary_code(config[CONF_GROUP]),
|
||||
binary_code(config[CONF_DEVICE]),
|
||||
config[CONF_STATE])
|
||||
if key == CONF_RC_SWITCH_TYPE_B:
|
||||
return RCSwitchTypeBTransmitter.new(name, build_rc_switch_protocol(config[CONF_PROTOCOL]),
|
||||
config[CONF_ADDRESS], config[CONF_CHANNEL],
|
||||
config[CONF_STATE])
|
||||
if key == CONF_RC_SWITCH_TYPE_C:
|
||||
return RCSwitchTypeCTransmitter.new(name, build_rc_switch_protocol(config[CONF_PROTOCOL]),
|
||||
ord(config[CONF_FAMILY][0]) - ord('a'),
|
||||
config[CONF_GROUP], config[CONF_DEVICE],
|
||||
config[CONF_STATE])
|
||||
if key == CONF_RC_SWITCH_TYPE_D:
|
||||
return RCSwitchTypeDTransmitter.new(name, build_rc_switch_protocol(config[CONF_PROTOCOL]),
|
||||
ord(config[CONF_GROUP][0]) - ord('a'),
|
||||
config[CONF_DEVICE], config[CONF_STATE])
|
||||
|
||||
raise NotImplementedError("Unknown transmitter type {}".format(config))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for remote in get_variable(config[CONF_REMOTE_TRANSMITTER_ID]):
|
||||
yield
|
||||
rhs = transmitter_base(config)
|
||||
transmitter = Pvariable(config[CONF_TRANSMITTER_ID], rhs)
|
||||
|
||||
if CONF_REPEAT in config:
|
||||
if isinstance(config[CONF_REPEAT], int):
|
||||
times = config[CONF_REPEAT]
|
||||
wait_us = 1000
|
||||
else:
|
||||
times = config[CONF_REPEAT][CONF_TIMES]
|
||||
wait_us = config[CONF_REPEAT][CONF_WAIT_TIME]
|
||||
add(transmitter.set_repeat(times, wait_us))
|
||||
|
||||
switch.register_switch(remote.add_transmitter(transmitter), config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_REMOTE_TRANSMITTER'
|
||||
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return switch.core_to_hass_config(data, config)
|
||||
@@ -1,27 +0,0 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import switch
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_INVERTED, CONF_NAME
|
||||
from esphomeyaml.cpp_generator import Pvariable
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
RestartSwitch = switch.switch_ns.class_('RestartSwitch', switch.Switch)
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(RestartSwitch),
|
||||
vol.Optional(CONF_INVERTED): cv.invalid("Restart switches do not support inverted mode!"),
|
||||
}))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
rhs = App.make_restart_switch(config[CONF_NAME])
|
||||
restart = Pvariable(config[CONF_ID], rhs)
|
||||
switch.setup_switch(restart, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_RESTART_SWITCH'
|
||||
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return switch.core_to_hass_config(data, config)
|
||||
@@ -1,27 +0,0 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import switch
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_INVERTED, CONF_NAME
|
||||
from esphomeyaml.cpp_generator import Pvariable
|
||||
from esphomeyaml.cpp_types import App
|
||||
|
||||
ShutdownSwitch = switch.switch_ns.class_('ShutdownSwitch', switch.Switch)
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(ShutdownSwitch),
|
||||
vol.Optional(CONF_INVERTED): cv.invalid("Shutdown switches do not support inverted mode!"),
|
||||
}))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
rhs = App.make_shutdown_switch(config[CONF_NAME])
|
||||
shutdown = Pvariable(config[CONF_ID], rhs)
|
||||
switch.setup_switch(shutdown, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_SHUTDOWN_SWITCH'
|
||||
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return switch.core_to_hass_config(data, config)
|
||||
@@ -1,79 +0,0 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml import automation
|
||||
from esphomeyaml.automation import ACTION_REGISTRY
|
||||
from esphomeyaml.components import switch
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_NAME, CONF_OPTIMISTIC, \
|
||||
CONF_RESTORE_STATE, \
|
||||
CONF_STATE, CONF_TURN_OFF_ACTION, CONF_TURN_ON_ACTION, CONF_ASSUMED_STATE
|
||||
from esphomeyaml.cpp_generator import Pvariable, add, get_variable, process_lambda, templatable
|
||||
from esphomeyaml.cpp_helpers import setup_component
|
||||
from esphomeyaml.cpp_types import Action, App, Component, NoArg, bool_, optional
|
||||
|
||||
TemplateSwitch = switch.switch_ns.class_('TemplateSwitch', switch.Switch, Component)
|
||||
SwitchPublishAction = switch.switch_ns.class_('SwitchPublishAction', Action)
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(TemplateSwitch),
|
||||
vol.Optional(CONF_LAMBDA): cv.lambda_,
|
||||
vol.Optional(CONF_OPTIMISTIC): cv.boolean,
|
||||
vol.Optional(CONF_ASSUMED_STATE): cv.boolean,
|
||||
vol.Optional(CONF_TURN_OFF_ACTION): automation.validate_automation(single=True),
|
||||
vol.Optional(CONF_TURN_ON_ACTION): automation.validate_automation(single=True),
|
||||
vol.Optional(CONF_RESTORE_STATE): cv.boolean,
|
||||
}).extend(cv.COMPONENT_SCHEMA.schema))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
rhs = App.make_template_switch(config[CONF_NAME])
|
||||
template = Pvariable(config[CONF_ID], rhs)
|
||||
|
||||
switch.setup_switch(template, config)
|
||||
|
||||
if CONF_LAMBDA in config:
|
||||
for template_ in process_lambda(config[CONF_LAMBDA], [],
|
||||
return_type=optional.template(bool_)):
|
||||
yield
|
||||
add(template.set_state_lambda(template_))
|
||||
if CONF_TURN_OFF_ACTION in config:
|
||||
automation.build_automation(template.get_turn_off_trigger(), NoArg,
|
||||
config[CONF_TURN_OFF_ACTION])
|
||||
if CONF_TURN_ON_ACTION in config:
|
||||
automation.build_automation(template.get_turn_on_trigger(), NoArg,
|
||||
config[CONF_TURN_ON_ACTION])
|
||||
if CONF_OPTIMISTIC in config:
|
||||
add(template.set_optimistic(config[CONF_OPTIMISTIC]))
|
||||
if CONF_ASSUMED_STATE in config:
|
||||
add(template.set_assumed_state(config[CONF_ASSUMED_STATE]))
|
||||
|
||||
if CONF_RESTORE_STATE in config:
|
||||
add(template.set_restore_state(config[CONF_RESTORE_STATE]))
|
||||
|
||||
setup_component(template, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_TEMPLATE_SWITCH'
|
||||
|
||||
CONF_SWITCH_TEMPLATE_PUBLISH = 'switch.template.publish'
|
||||
SWITCH_TEMPLATE_PUBLISH_ACTION_SCHEMA = vol.Schema({
|
||||
vol.Required(CONF_ID): cv.use_variable_id(switch.Switch),
|
||||
vol.Required(CONF_STATE): cv.templatable(cv.boolean),
|
||||
})
|
||||
|
||||
|
||||
@ACTION_REGISTRY.register(CONF_SWITCH_TEMPLATE_PUBLISH, SWITCH_TEMPLATE_PUBLISH_ACTION_SCHEMA)
|
||||
def switch_template_publish_to_code(config, action_id, arg_type, template_arg):
|
||||
for var in get_variable(config[CONF_ID]):
|
||||
yield None
|
||||
rhs = var.make_switch_publish_action(template_arg)
|
||||
type = SwitchPublishAction.template(arg_type)
|
||||
action = Pvariable(action_id, rhs, type=type)
|
||||
for template_ in templatable(config[CONF_STATE], arg_type, bool_):
|
||||
yield None
|
||||
add(action.set_state(template_))
|
||||
yield action
|
||||
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return switch.core_to_hass_config(data, config)
|
||||
@@ -1,50 +0,0 @@
|
||||
import voluptuous as vol
|
||||
|
||||
from esphomeyaml.components import switch, uart
|
||||
from esphomeyaml.components.uart import UARTComponent
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_DATA, CONF_ID, CONF_INVERTED, CONF_NAME, CONF_UART_ID
|
||||
from esphomeyaml.core import HexInt
|
||||
from esphomeyaml.cpp_generator import Pvariable, get_variable
|
||||
from esphomeyaml.cpp_types import App
|
||||
from esphomeyaml.py_compat import text_type
|
||||
|
||||
DEPENDENCIES = ['uart']
|
||||
|
||||
UARTSwitch = switch.switch_ns.class_('UARTSwitch', switch.Switch, uart.UARTDevice)
|
||||
|
||||
|
||||
def validate_data(value):
|
||||
if isinstance(value, text_type):
|
||||
return value.encode('utf-8')
|
||||
if isinstance(value, str):
|
||||
return value
|
||||
if isinstance(value, list):
|
||||
return vol.Schema([cv.hex_uint8_t])(value)
|
||||
raise vol.Invalid("data must either be a string wrapped in quotes or a list of bytes")
|
||||
|
||||
|
||||
PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(UARTSwitch),
|
||||
cv.GenerateID(CONF_UART_ID): cv.use_variable_id(UARTComponent),
|
||||
vol.Required(CONF_DATA): validate_data,
|
||||
vol.Optional(CONF_INVERTED): cv.invalid("UART switches do not support inverted mode!"),
|
||||
}))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for uart_ in get_variable(config[CONF_UART_ID]):
|
||||
yield
|
||||
data = config[CONF_DATA]
|
||||
if isinstance(data, str):
|
||||
data = [HexInt(ord(x)) for x in data]
|
||||
rhs = App.make_uart_switch(uart_, config[CONF_NAME], data)
|
||||
var = Pvariable(config[CONF_ID], rhs)
|
||||
switch.setup_switch(var, config)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_UART_SWITCH'
|
||||
|
||||
|
||||
def to_hass_config(data, config):
|
||||
return switch.core_to_hass_config(data, config)
|
||||
Reference in New Issue
Block a user