vol.Required(CONF_MDIO_PIN): pins.input_output_pin, vol.Optional(CONF_CLK_MODE, default='GPIO0_IN'): cv.one_of(*CLK_MODES, upper=True, space='_'), vol.Optional(CONF_PHY_ADDR, default=0): vol.All(cv.int_, vol.Range(min=0, max=31)), vol.Optional(CONF_POWER_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_MANUAL_IP): wifi.STA_MANUAL_IP_SCHEMA, vol.Optional(CONF_DOMAIN, default='.local'): cv.domain_name, vol.Optional(CONF_USE_ADDRESS): cv.string_strict, vol.Optional('hostname'): cv.invalid("The hostname option has been removed in 1.11.0"), }), validate) def to_code(config): rhs = App.init_ethernet() eth = Pvariable(config[CONF_ID], rhs) add(eth.set_phy_addr(config[CONF_PHY_ADDR])) add(eth.set_mdc_pin(config[CONF_MDC_PIN])) add(eth.set_mdio_pin(config[CONF_MDIO_PIN])) add(eth.set_type(ETHERNET_TYPES[config[CONF_TYPE]])) add(eth.set_clk_mode(CLK_MODES[config[CONF_CLK_MODE]])) add(eth.set_use_address(config[CONF_USE_ADDRESS])) if CONF_POWER_PIN in config:
vol.Optional(CONF_WAKEUP_PIN_MODE): vol.All(cv.only_on_esp32, cv.one_of(*WAKEUP_PIN_MODES), upper=True), vol.Optional(CONF_ESP32_EXT1_WAKEUP): vol.All( cv.only_on_esp32, cv.Schema({ vol.Required(CONF_PINS): cv.ensure_list(pins.shorthand_input_pin, validate_pin_number), vol.Required(CONF_MODE): cv.one_of(*EXT1_WAKEUP_MODES, upper=True), })), vol.Optional(CONF_RUN_DURATION): cv.positive_time_period_milliseconds, vol.Optional(CONF_RUN_CYCLES): cv.invalid("The run_cycles option has been removed in 1.11.0 as " "it was essentially the same as a run_duration of 0s." "Please use run_duration now.") }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): rhs = App.make_deep_sleep_component() deep_sleep = Pvariable(config[CONF_ID], rhs) if CONF_SLEEP_DURATION in config: add(deep_sleep.set_sleep_duration(config[CONF_SLEEP_DURATION])) if CONF_WAKEUP_PIN in config: for pin in gpio_input_pin_expression(config[CONF_WAKEUP_PIN]): yield add(deep_sleep.set_wakeup_pin(pin)) if CONF_WAKEUP_PIN_MODE in config: add(
vol.Required(CONF_COMMAND): vol.All(cv.hex_int, vol.Range(min=0, max=0x3F)), }), 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, cv.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])
vol.Optional(CONF_BOARD_FLASH_MODE, default='dout'): cv.one_of(*BUILD_FLASH_MODES, lower=True), vol.Optional(CONF_ON_BOOT): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(StartupTrigger), vol.Optional(CONF_PRIORITY): cv.float_, }), vol.Optional(CONF_ON_SHUTDOWN): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(ShutdownTrigger), }), vol.Optional(CONF_ON_LOOP): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(LoopTrigger), }), vol.Optional(CONF_INCLUDES): cv.ensure_list(cv.file_), vol.Optional(CONF_LIBRARIES): cv.ensure_list(cv.string_strict), vol.Optional('pi4homelib_version'): cv.invalid("The pi4homelib_version has been renamed to " "pi4home_core_version in 1.11.0"), }) def preload_core_config(config): if 'pi4homeyaml' in config: _LOGGER.warning("The pi4homeyaml section has been renamed to pi4home in 1.11.0. " "Please replace 'pi4homeyaml:' in your configuration with 'pi4home:'.") config[CONF_PI4HOME] = config.pop('pi4homeyaml') if CONF_PI4HOME not in config: raise pi4homeError(u"No pi4home section in config") core_conf = config[CONF_PI4HOME] if CONF_PLATFORM not in core_conf: raise pi4homeError("pi4home.platform not specified.") if CONF_BOARD not in core_conf: raise pi4homeError("pi4home.board not specified.")
CONF_PULSE_TIME = 'pulse_time' UltrasonicSensorComponent = sensor.sensor_ns.class_('UltrasonicSensorComponent', sensor.PollingSensorComponent) PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(UltrasonicSensorComponent), vol.Required(CONF_TRIGGER_PIN): pins.gpio_output_pin_schema, vol.Required(CONF_ECHO_PIN): pins.internal_gpio_input_pin_schema, vol.Optional(CONF_TIMEOUT): cv.distance, vol.Optional(CONF_PULSE_TIME): cv.positive_time_period_microseconds, vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, vol.Optional('timeout_meter'): cv.invalid("The timeout_meter option has been renamed " "to 'timeout'."), vol.Optional('timeout_time'): cv.invalid("The timeout_time option has been removed. Please " "use 'timeout'."), })) def to_code(config): for trigger in gpio_output_pin_expression(config[CONF_TRIGGER_PIN]): yield for echo in gpio_input_pin_expression(config[CONF_ECHO_PIN]): yield rhs = App.make_ultrasonic_sensor(config[CONF_NAME], trigger, echo, config.get(CONF_UPDATE_INTERVAL)) ultrasonic = Pvariable(config[CONF_ID], rhs) if CONF_TIMEOUT in config:
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 cv.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'
import voluptuous as vol from pi4home.components import switch import pi4home.config_validation as cv from pi4home.const import CONF_ID, CONF_INVERTED, CONF_NAME from pi4home.cpp_generator import Pvariable from pi4home.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'
FILTER_KEYS = [ CONF_INVERT, CONF_DELAYED_ON, CONF_DELAYED_OFF, CONF_LAMBDA, CONF_HEARTBEAT ] FILTERS_SCHEMA = cv.ensure_list( { vol.Optional(CONF_INVERT): None, vol.Optional(CONF_DELAYED_ON): cv.positive_time_period_milliseconds, vol.Optional(CONF_DELAYED_OFF): cv.positive_time_period_milliseconds, vol.Optional(CONF_LAMBDA): cv.lambda_, vol.Optional(CONF_HEARTBEAT): cv.invalid("The heartbeat filter has been removed in 1.11.0"), }, cv.has_exactly_one_key(*FILTER_KEYS)) MULTI_CLICK_TIMING_SCHEMA = cv.Schema({ vol.Optional(CONF_STATE): cv.boolean, vol.Optional(CONF_MIN_LENGTH): cv.positive_time_period_milliseconds, vol.Optional(CONF_MAX_LENGTH): cv.positive_time_period_milliseconds, }) def parse_multi_click_timing_str(value): if not isinstance(value, string_types): return value
raise vol.Invalid("Datapoint mapping must contain '->'") a, b = value.split('->', 1) a, b = a.strip(), b.strip() return validate_datapoint({CONF_FROM: cv.float_(a), CONF_TO: cv.float_(b)}) FILTERS_SCHEMA = cv.ensure_list( { vol.Optional(CONF_OFFSET): cv.float_, vol.Optional(CONF_MULTIPLY): cv.float_, vol.Optional(CONF_FILTER_OUT): cv.float_, vol.Optional('filter_nan'): cv.invalid("The filter_nan filter has been removed. Please use " "'filter_out: nan' instead"), vol.Optional(CONF_SLIDING_WINDOW_MOVING_AVERAGE): vol.All( cv.Schema({ vol.Optional(CONF_WINDOW_SIZE, default=15): cv.positive_not_null_int, vol.Optional(CONF_SEND_EVERY, default=15): cv.positive_not_null_int, vol.Optional(CONF_SEND_FIRST_AT): cv.positive_not_null_int, }), validate_send_first_at), vol.Optional(CONF_EXPONENTIAL_MOVING_AVERAGE): cv.Schema({ vol.Optional(CONF_ALPHA, default=0.1): cv.positive_float, vol.Optional(CONF_SEND_EVERY, default=15):
I2CDevice = pins.I2CDevice CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_variable_id(I2CComponent), vol.Optional(CONF_SDA, default='SDA'): pins.input_pin, vol.Optional(CONF_SCL, default='SCL'): pins.input_pin, vol.Optional(CONF_FREQUENCY): vol.All(cv.frequency, vol.Range(min=0, min_included=False)), vol.Optional(CONF_SCAN, default=True): cv.boolean, vol.Optional(CONF_RECEIVE_TIMEOUT): cv.invalid("The receive_timeout option has been removed " "because timeouts are already handled by the " "low-level i2c interface.") }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): rhs = App.init_i2c(config[CONF_SDA], config[CONF_SCL], config.get(CONF_SCAN)) i2c = Pvariable(config[CONF_ID], rhs) if CONF_FREQUENCY in config: add(i2c.set_frequency(config[CONF_FREQUENCY])) setup_component(i2c, config) BUILD_FLAGS = '-DUSE_I2C'