LAMBDA_CONDITION_SCHEMA = cv.lambda_ @CONDITION_REGISTRY.register(CONF_LAMBDA, LAMBDA_CONDITION_SCHEMA) def lambda_condition_to_code(config, condition_id, template_arg, args): for lambda_ in process_lambda(config, args, return_type=bool_): yield rhs = LambdaCondition.new(template_arg, lambda_) type = LambdaCondition.template(template_arg) yield Pvariable(condition_id, rhs, type=type) CONF_COMPONENT_UPDATE = 'component.update' COMPONENT_UPDATE_ACTION_SCHEMA = maybe_simple_id({ vol.Required(CONF_ID): cv.use_variable_id(PollingComponent), }) @ACTION_REGISTRY.register(CONF_COMPONENT_UPDATE, COMPONENT_UPDATE_ACTION_SCHEMA) def component_update_action_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = UpdateComponentAction.new(template_arg, var) type = UpdateComponentAction.template(template_arg) yield Pvariable(action_id, rhs, type=type) def build_action(full_config, template_arg, args): action_id = full_config[CONF_ACTION_ID] key, config = next((k, v) for k, v in full_config.items() if k in ACTION_REGISTRY)
CONF_RESOLUTION from pi4home.cpp_generator import HexIntLiteral, get_variable DallasTemperatureSensor = sensor.sensor_ns.class_( 'DallasTemperatureSensor', sensor.EmptyPollingParentSensor) PLATFORM_SCHEMA = cv.nameable( sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(DallasTemperatureSensor), vol.Exclusive(CONF_ADDRESS, 'dallas'): cv.hex_int, vol.Exclusive(CONF_INDEX, 'dallas'): cv.positive_int, cv.GenerateID(CONF_DALLAS_ID): cv.use_variable_id(DallasComponent), vol.Optional(CONF_RESOLUTION): vol.All(vol.Coerce(int), vol.Range(min=9, max=12)), }), cv.has_at_least_one_key(CONF_ADDRESS, CONF_INDEX)) def to_code(config): for hub in get_variable(config[CONF_DALLAS_ID]): yield if CONF_ADDRESS in config: address = HexIntLiteral(config[CONF_ADDRESS]) rhs = hub.Pget_sensor_by_address(config[CONF_NAME], address, config.get(CONF_RESOLUTION)) else: rhs = hub.Pget_sensor_by_index(config[CONF_NAME], config[CONF_INDEX], config.get(CONF_RESOLUTION))
from pi4home.const import CONF_ID, CONF_LAMBDA, CONF_UART_ID from pi4home.cpp_generator import Pvariable, add, get_variable, process_lambda from pi4home.cpp_helpers import setup_component from pi4home.cpp_types import App, PollingComponent, void DEPENDENCIES = ['uart'] Nextion = display.display_ns.class_('Nextion', PollingComponent, uart.UARTDevice) NextionRef = Nextion.operator('ref') PLATFORM_SCHEMA = display.BASIC_DISPLAY_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(Nextion), cv.GenerateID(CONF_UART_ID): cv.use_variable_id(UARTComponent), }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): for uart_ in get_variable(config[CONF_UART_ID]): yield rhs = App.make_nextion(uart_) nextion = Pvariable(config[CONF_ID], rhs) if CONF_LAMBDA in config: for lambda_ in process_lambda(config[CONF_LAMBDA], [(NextionRef, 'it')], return_type=void): yield add(nextion.set_writer(lambda_))
from pi4home.components import sensor from pi4home.components.esp32_ble_tracker import CONF_ESP32_BLE_ID, ESP32BLETracker, \ make_address_array import pi4home.config_validation as cv from pi4home.const import CONF_MAC_ADDRESS, CONF_NAME from pi4home.cpp_generator import get_variable from pi4home.cpp_types import pi4home_ns DEPENDENCIES = ['esp32_ble_tracker'] ESP32BLERSSISensor = pi4home_ns.class_('ESP32BLERSSISensor', sensor.Sensor) PLATFORM_SCHEMA = cv.nameable( sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(ESP32BLERSSISensor), vol.Required(CONF_MAC_ADDRESS): cv.mac_address, cv.GenerateID(CONF_ESP32_BLE_ID): cv.use_variable_id(ESP32BLETracker) })) def to_code(config): for hub in get_variable(config[CONF_ESP32_BLE_ID]): yield rhs = hub.make_rssi_sensor(config[CONF_NAME], make_address_array(config[CONF_MAC_ADDRESS])) sensor.register_sensor(rhs, config)
u"".format(value[CONF_FROM], value[CONF_TO])) return value PLATFORM_SCHEMA = cv.nameable( light.LIGHT_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(light.AddressableLightState), cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakePartitionLight), vol.Required(CONF_SEGMENTS): vol.All( cv.ensure_list( { vol.Required(CONF_ID): cv.use_variable_id(light.AddressableLightState), vol.Required(CONF_FROM): cv.positive_int, vol.Required(CONF_TO): cv.positive_int, }, validate_from_to), vol.Length(min=1)), vol.Optional(CONF_DEFAULT_TRANSITION_LENGTH): cv.positive_time_period_milliseconds, vol.Optional(CONF_EFFECTS): light.validate_effects(light.ADDRESSABLE_EFFECTS), })) def to_code(config): segments = [] for conf in config[CONF_SEGMENTS]:
add(light_var.add_effects(effects)) setup_mqtt_component(light_var.Pget_mqtt(), config) def setup_light(light_obj, config): light_var = Pvariable(config[CONF_ID], light_obj, has_side_effects=False) CORE.add_job(setup_light_core_, light_var, config) BUILD_FLAGS = '-DUSE_LIGHT' CONF_LIGHT_TOGGLE = 'light.toggle' LIGHT_TOGGLE_ACTION_SCHEMA = maybe_simple_id({ vol.Required(CONF_ID): cv.use_variable_id(LightState), vol.Optional(CONF_TRANSITION_LENGTH): cv.templatable(cv.positive_time_period_milliseconds), }) @ACTION_REGISTRY.register(CONF_LIGHT_TOGGLE, LIGHT_TOGGLE_ACTION_SCHEMA) def light_toggle_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_toggle_action(template_arg) type = ToggleAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) if CONF_TRANSITION_LENGTH in config: for template_ in templatable(config[CONF_TRANSITION_LENGTH], args, uint32):
for pin in conf[CONF_PINS]: mask |= 1 << pin[CONF_NUMBER] struct = StructInitializer( Ext1Wakeup, ('mask', mask), ('wakeup_mode', EXT1_WAKEUP_MODES[conf[CONF_MODE]])) add(deep_sleep.set_ext1_wakeup(struct)) setup_component(deep_sleep, config) BUILD_FLAGS = '-DUSE_DEEP_SLEEP' CONF_DEEP_SLEEP_ENTER = 'deep_sleep.enter' DEEP_SLEEP_ENTER_ACTION_SCHEMA = maybe_simple_id({ vol.Required(CONF_ID): cv.use_variable_id(DeepSleepComponent), }) @ACTION_REGISTRY.register(CONF_DEEP_SLEEP_ENTER, DEEP_SLEEP_ENTER_ACTION_SCHEMA) def deep_sleep_enter_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_enter_deep_sleep_action(template_arg) type = EnterDeepSleepAction.template(template_arg) yield Pvariable(action_id, rhs, type=type) CONF_DEEP_SLEEP_PREVENT = 'deep_sleep.prevent' DEEP_SLEEP_PREVENT_ACTION_SCHEMA = maybe_simple_id({
import voluptuous as vol from pi4home.components import esp32_ble_tracker, sensor from pi4home.components.esp32_ble_tracker import CONF_ESP32_BLE_ID, ESP32BLETracker, \ make_address_array import pi4home.config_validation as cv from pi4home.const import CONF_BATTERY_LEVEL, CONF_CONDUCTIVITY, CONF_ID, CONF_ILLUMINANCE, \ CONF_MAC_ADDRESS, CONF_MOISTURE, CONF_NAME, CONF_TEMPERATURE from pi4home.cpp_generator import Pvariable, get_variable DEPENDENCIES = ['esp32_ble_tracker'] PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(esp32_ble_tracker.XiaomiDevice), cv.GenerateID(CONF_ESP32_BLE_ID): cv.use_variable_id(ESP32BLETracker), vol.Required(CONF_MAC_ADDRESS): cv.mac_address, vol.Optional(CONF_TEMPERATURE): cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA), vol.Optional(CONF_MOISTURE): cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA), vol.Optional(CONF_ILLUMINANCE): cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA), vol.Optional(CONF_CONDUCTIVITY): cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA), vol.Optional(CONF_BATTERY_LEVEL): cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA), }) def to_code(config): for hub in get_variable(config[CONF_ESP32_BLE_ID]): yield rhs = hub.make_xiaomi_device(make_address_array(config[CONF_MAC_ADDRESS])) dev = Pvariable(config[CONF_ID], rhs) if CONF_TEMPERATURE in config: conf = config[CONF_TEMPERATURE]
vol.Optional(CONF_PIN): pins.output_pin, vol.Optional(CONF_CLOCK_PIN): pins.output_pin, vol.Optional(CONF_DATA_PIN): pins.output_pin, vol.Required(CONF_NUM_LEDS): cv.positive_not_null_int, vol.Optional(CONF_GAMMA_CORRECT): cv.positive_float, vol.Optional(CONF_COLOR_CORRECT): vol.All([cv.percentage], vol.Length(min=3, max=4)), vol.Optional(CONF_DEFAULT_TRANSITION_LENGTH): cv.positive_time_period_milliseconds, vol.Optional(CONF_POWER_SUPPLY): cv.use_variable_id(PowerSupplyComponent), vol.Optional(CONF_EFFECTS): light.validate_effects(light.ADDRESSABLE_EFFECTS), }).extend(cv.COMPONENT_SCHEMA.schema), validate, validate_method_pin) def to_code(config): type_ = config[CONF_TYPE] has_white = 'W' in type_ if has_white: func = App.make_neo_pixel_bus_rgbw_light color_feat = global_ns.NeoRgbwFeature else: func = App.make_neo_pixel_bus_rgb_light color_feat = global_ns.NeoRgbFeature
add(stepper_var.set_acceleration(config[CONF_ACCELERATION])) if CONF_DECELERATION in config: add(stepper_var.set_deceleration(config[CONF_DECELERATION])) if CONF_MAX_SPEED in config: add(stepper_var.set_max_speed(config[CONF_MAX_SPEED])) def setup_stepper(stepper_var, config): CORE.add_job(setup_stepper_core_, stepper_var, config) BUILD_FLAGS = '-DUSE_STEPPER' CONF_STEPPER_SET_TARGET = 'stepper.set_target' STEPPER_SET_TARGET_ACTION_SCHEMA = cv.Schema({ vol.Required(CONF_ID): cv.use_variable_id(Stepper), vol.Required(CONF_TARGET): cv.templatable(cv.int_), }) @ACTION_REGISTRY.register(CONF_STEPPER_SET_TARGET, STEPPER_SET_TARGET_ACTION_SCHEMA) def stepper_set_target_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_set_target_action(template_arg) type = SetTargetAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_TARGET], args, int32): yield None add(action.set_target(template_)) yield action
from pi4home.components import output from pi4home.components.pca9685 import PCA9685OutputComponent import pi4home.config_validation as cv from pi4home.const import CONF_CHANNEL, CONF_ID, CONF_PCA9685_ID, CONF_POWER_SUPPLY from pi4home.cpp_generator import Pvariable, get_variable DEPENDENCIES = ['pca9685'] Channel = PCA9685OutputComponent.class_('Channel', output.FloatOutput) PLATFORM_SCHEMA = output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({ vol.Required(CONF_ID): cv.declare_variable_id(Channel), vol.Required(CONF_CHANNEL): vol.All(vol.Coerce(int), vol.Range(min=0, max=15)), cv.GenerateID(CONF_PCA9685_ID): cv.use_variable_id(PCA9685OutputComponent), }) def to_code(config): power_supply = None if CONF_POWER_SUPPLY in config: for power_supply in get_variable(config[CONF_POWER_SUPPLY]): yield for pca9685 in get_variable(config[CONF_PCA9685_ID]): yield rhs = pca9685.create_channel(config[CONF_CHANNEL], power_supply) out = Pvariable(config[CONF_ID], rhs) output.setup_output_platform(out, config, skip_power_supply=True)
mqtt_.set_custom_speed_command_topic( config[CONF_SPEED_COMMAND_TOPIC])) setup_mqtt_component(mqtt_, config) def setup_fan(fan_obj, config): fan_var = Pvariable(config[CONF_ID], fan_obj, has_side_effects=False) CORE.add_job(setup_fan_core_, fan_var, config) BUILD_FLAGS = '-DUSE_FAN' CONF_FAN_TOGGLE = 'fan.toggle' FAN_TOGGLE_ACTION_SCHEMA = maybe_simple_id({ vol.Required(CONF_ID): cv.use_variable_id(FanState), }) @ACTION_REGISTRY.register(CONF_FAN_TOGGLE, FAN_TOGGLE_ACTION_SCHEMA) def fan_toggle_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_toggle_action(template_arg) type = ToggleAction.template(template_arg) yield Pvariable(action_id, rhs, type=type) CONF_FAN_TURN_OFF = 'fan.turn_off' FAN_TURN_OFF_ACTION_SCHEMA = maybe_simple_id({ vol.Required(CONF_ID):
import voluptuous as vol from pi4home.components import output import pi4home.config_validation as cv from pi4home.const import CONF_ID, CONF_OUTPUTS, CONF_TYPE from pi4home.cpp_generator import Pvariable, get_variable from pi4home.cpp_helpers import setup_component BinaryCopyOutput = output.output_ns.class_('BinaryCopyOutput', output.BinaryOutput) FloatCopyOutput = output.output_ns.class_('FloatCopyOutput', output.FloatOutput) BINARY_SCHEMA = output.PLATFORM_SCHEMA.extend({ vol.Required(CONF_ID): cv.declare_variable_id(BinaryCopyOutput), vol.Required(CONF_TYPE): 'binary', vol.Required(CONF_OUTPUTS): cv.ensure_list(cv.use_variable_id(output.BinaryOutput)), }) FLOAT_SCHEMA = output.PLATFORM_SCHEMA.extend({ vol.Required(CONF_ID): cv.declare_variable_id(FloatCopyOutput), vol.Required(CONF_TYPE): 'float', vol.Required(CONF_OUTPUTS): cv.ensure_list(cv.use_variable_id(output.FloatOutput)), }) def validate_copy_output(value): if not isinstance(value, dict): raise vol.Invalid("Value must be dict") type = cv.string_strict(value.get(CONF_TYPE, 'float')).lower() value[CONF_TYPE] = type if type == 'binary': return BINARY_SCHEMA(value)
BUILD_FLAGS = '-DUSE_API' def lib_deps(config): if CORE.is_esp32: return '[email protected]' if CORE.is_esp8266: return '[email protected]' raise NotImplementedError CONF_HOMEASSISTANT_SERVICE = 'homeassistant.service' HOMEASSISTANT_SERVIC_ACTION_SCHEMA = cv.Schema({ cv.GenerateID(): cv.use_variable_id(APIServer), vol.Required(CONF_SERVICE): cv.string, vol.Optional(CONF_DATA): cv.Schema({ cv.string: cv.string, }), vol.Optional(CONF_DATA_TEMPLATE): cv.Schema({ cv.string: cv.string, }), vol.Optional(CONF_VARIABLES): cv.Schema({ cv.string: cv.lambda_, }), }) @ACTION_REGISTRY.register(CONF_HOMEASSISTANT_SERVICE, HOMEASSISTANT_SERVIC_ACTION_SCHEMA) def homeassistant_service_to_code(config, action_id, template_arg, args):
value = value.replace(' ', '_') return cv.one_of(*MUX)(value) ADS1115Sensor = sensor.sensor_ns.class_('ADS1115Sensor', sensor.EmptySensor) PLATFORM_SCHEMA = cv.nameable( sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(ADS1115Sensor), vol.Required(CONF_MULTIPLEXER): validate_mux, vol.Required(CONF_GAIN): validate_gain, cv.GenerateID(CONF_ADS1115_ID): cv.use_variable_id(ADS1115Component), vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, })) def to_code(config): for hub in get_variable(config[CONF_ADS1115_ID]): yield mux = MUX[config[CONF_MULTIPLEXER]] gain = GAIN[config[CONF_GAIN]] rhs = hub.get_sensor(config[CONF_NAME], mux, gain, config.get(CONF_UPDATE_INTERVAL)) sensor.register_sensor(rhs, config)
import voluptuous as vol from pi4home.automation import ACTION_REGISTRY, maybe_simple_id from pi4home.components.power_supply import PowerSupplyComponent import pi4home.config_validation as cv from pi4home.const import CONF_ID, CONF_INVERTED, CONF_LEVEL, CONF_MAX_POWER, \ CONF_MIN_POWER, CONF_POWER_SUPPLY from pi4home.core import CORE from pi4home.cpp_generator import Pvariable, add, get_variable, templatable from pi4home.cpp_types import Action, pi4home_ns, float_ PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({}) BINARY_OUTPUT_SCHEMA = cv.Schema({ vol.Optional(CONF_POWER_SUPPLY): cv.use_variable_id(PowerSupplyComponent), vol.Optional(CONF_INVERTED): cv.boolean, }) BINARY_OUTPUT_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( BINARY_OUTPUT_SCHEMA.schema) FLOAT_OUTPUT_SCHEMA = BINARY_OUTPUT_SCHEMA.extend({ vol.Optional(CONF_MAX_POWER): cv.percentage, vol.Optional(CONF_MIN_POWER): cv.percentage, }) FLOAT_OUTPUT_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
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 = cv.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, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_switch_publish_action(template_arg) type = SwitchPublishAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_STATE], args, bool_): yield None add(action.set_state(template_)) yield action
from pi4home.const import CONF_NAME, CONF_TYPE from pi4home.cpp_generator import get_variable DEPENDENCIES = ['apds9960'] TYPES = { 'CLEAR': 'make_clear_channel', 'RED': 'make_red_channel', 'GREEN': 'make_green_channel', 'BLUE': 'make_blue_channel', 'PROXIMITY': 'make_proximity', } PLATFORM_SCHEMA = cv.nameable( sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(sensor.Sensor), vol.Required(CONF_TYPE): cv.one_of(*TYPES, upper=True), cv.GenerateID(CONF_APDS9960_ID): cv.use_variable_id(APDS9960) })) def to_code(config): for hub in get_variable(config[CONF_APDS9960_ID]): yield func = getattr(hub, TYPES[config[CONF_TYPE]]) rhs = func(config[CONF_NAME]) sensor.register_sensor(rhs, config)
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]:
import voluptuous as vol from pi4home.components import light, output import pi4home.config_validation as cv from pi4home.const import CONF_DEFAULT_TRANSITION_LENGTH, CONF_EFFECTS, CONF_GAMMA_CORRECT, \ CONF_MAKE_ID, CONF_NAME, CONF_OUTPUT from pi4home.cpp_generator import get_variable, variable from pi4home.cpp_helpers import setup_component from pi4home.cpp_types import App PLATFORM_SCHEMA = cv.nameable( light.LIGHT_PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight), vol.Required(CONF_OUTPUT): cv.use_variable_id(output.FloatOutput), vol.Optional(CONF_GAMMA_CORRECT): cv.positive_float, vol.Optional(CONF_DEFAULT_TRANSITION_LENGTH): cv.positive_time_period_milliseconds, vol.Optional(CONF_EFFECTS): light.validate_effects(light.MONOCHROMATIC_EFFECTS), }).extend(cv.COMPONENT_SCHEMA.schema)) def to_code(config): for output_ in get_variable(config[CONF_OUTPUT]): yield rhs = App.make_monochromatic_light(config[CONF_NAME], output_) light_struct = variable(config[CONF_MAKE_ID], rhs) light.setup_light(light_struct.Pstate, config)
vol.Optional(CONF_RC5): cv.Schema({ vol.Required(CONF_ADDRESS): vol.All(cv.hex_int, vol.Range(min=0, max=0x1F)), 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])
from pi4home.cpp_helpers import setup_component from pi4home.cpp_types import App, PollingComponent DEPENDENCIES = ['uart'] CSE7766Component = sensor.sensor_ns.class_('CSE7766Component', PollingComponent, uart.UARTDevice) CSE7766VoltageSensor = sensor.sensor_ns.class_('CSE7766VoltageSensor', sensor.EmptySensor) CSE7766CurrentSensor = sensor.sensor_ns.class_('CSE7766CurrentSensor', sensor.EmptySensor) CSE7766PowerSensor = sensor.sensor_ns.class_('CSE7766PowerSensor', sensor.EmptySensor) PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(CSE7766Component), cv.GenerateID(CONF_UART_ID): cv.use_variable_id(UARTComponent), vol.Optional(CONF_VOLTAGE): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(CSE7766VoltageSensor), })), vol.Optional(CONF_CURRENT): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(CSE7766CurrentSensor), })), vol.Optional(CONF_POWER): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(CSE7766PowerSensor), })), vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_least_one_key(CONF_VOLTAGE, CONF_CURRENT, CONF_POWER))
import voluptuous as vol from pi4home.components import light, output import pi4home.config_validation as cv from pi4home.const import CONF_EFFECTS, CONF_MAKE_ID, CONF_NAME, CONF_OUTPUT from pi4home.cpp_generator import get_variable, variable from pi4home.cpp_helpers import setup_component from pi4home.cpp_types import App PLATFORM_SCHEMA = cv.nameable( light.LIGHT_PLATFORM_SCHEMA.extend({ cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(light.MakeLight), vol.Required(CONF_OUTPUT): cv.use_variable_id(output.BinaryOutput), vol.Optional(CONF_EFFECTS): light.validate_effects(light.BINARY_EFFECTS), }).extend(cv.COMPONENT_SCHEMA.schema)) def to_code(config): for output_ in get_variable(config[CONF_OUTPUT]): yield rhs = App.make_binary_light(config[CONF_NAME], output_) light_struct = variable(config[CONF_MAKE_ID], rhs) light.setup_light(light_struct.Pstate, config) setup_component(light_struct.Pstate, config)
config[CONF_CLOSE_ACTION]) if CONF_STOP_ACTION in config: automation.build_automations(var.get_stop_trigger(), [], config[CONF_STOP_ACTION]) if CONF_OPTIMISTIC in config: add(var.set_optimistic(config[CONF_OPTIMISTIC])) if CONF_ASSUMED_STATE in config: add(var.set_assumed_state(config[CONF_ASSUMED_STATE])) BUILD_FLAGS = '-DUSE_TEMPLATE_COVER' CONF_COVER_TEMPLATE_PUBLISH = 'cover.template.publish' COVER_TEMPLATE_PUBLISH_ACTION_SCHEMA = cv.Schema({ vol.Required(CONF_ID): cv.use_variable_id(cover.Cover), vol.Required(CONF_STATE): cv.templatable(cover.validate_cover_state), }) @ACTION_REGISTRY.register(CONF_COVER_TEMPLATE_PUBLISH, COVER_TEMPLATE_PUBLISH_ACTION_SCHEMA) def cover_template_publish_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_cover_publish_action(template_arg) type = CoverPublishAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) state = config[CONF_STATE] if isinstance(state, string_types):
CONF_SPI_ID from pi4home.cpp_generator import Pvariable, add, get_variable, process_lambda from pi4home.cpp_helpers import gpio_output_pin_expression, setup_component from pi4home.cpp_types import App, PollingComponent, void DEPENDENCIES = ['spi'] MAX7219Component = display.display_ns.class_('MAX7219Component', PollingComponent, spi.SPIDevice) MAX7219ComponentRef = MAX7219Component.operator('ref') PLATFORM_SCHEMA = display.BASIC_DISPLAY_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(MAX7219Component), cv.GenerateID(CONF_SPI_ID): cv.use_variable_id(SPIComponent), vol.Required(CONF_CS_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_NUM_CHIPS): vol.All(cv.uint8_t, vol.Range(min=1)), vol.Optional(CONF_INTENSITY): vol.All(cv.uint8_t, vol.Range(min=0, max=15)), }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): for spi_ in get_variable(config[CONF_SPI_ID]): yield for cs in gpio_output_pin_expression(config[CONF_CS_PIN]): yield rhs = App.make_max7219(spi_, cs)
setup_component(template, config) if CONF_LAMBDA in config: for template_ in process_lambda( config[CONF_LAMBDA], [], return_type=optional.template(std_string)): yield add(template.set_template(template_)) BUILD_FLAGS = '-DUSE_TEMPLATE_TEXT_SENSOR' CONF_TEXT_SENSOR_TEMPLATE_PUBLISH = 'text_sensor.template.publish' TEXT_SENSOR_TEMPLATE_PUBLISH_ACTION_SCHEMA = cv.Schema({ vol.Required(CONF_ID): cv.use_variable_id(text_sensor.TextSensor), vol.Required(CONF_STATE): cv.templatable(cv.string_strict), }) @ACTION_REGISTRY.register(CONF_TEXT_SENSOR_TEMPLATE_PUBLISH, TEXT_SENSOR_TEMPLATE_PUBLISH_ACTION_SCHEMA) def text_sensor_template_publish_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_text_sensor_publish_action(template_arg) type = TextSensorPublishAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_STATE], args, std_string):
from pi4home.const import CONF_ID, CONF_IDLE_LEVEL, CONF_MAX_LEVEL, CONF_MIN_LEVEL, CONF_OUTPUT, \ CONF_LEVEL from pi4home.cpp_generator import Pvariable, add, get_variable, templatable from pi4home.cpp_helpers import setup_component from pi4home.cpp_types import App, Component, pi4home_ns, Action, float_ Servo = pi4home_ns.class_('Servo', Component) ServoWriteAction = pi4home_ns.class_('ServoWriteAction', Action) MULTI_CONF = True CONFIG_SCHEMA = cv.Schema({ vol.Required(CONF_ID): cv.declare_variable_id(Servo), vol.Required(CONF_OUTPUT): cv.use_variable_id(FloatOutput), vol.Optional(CONF_MIN_LEVEL, default='3%'): cv.percentage, vol.Optional(CONF_IDLE_LEVEL, default='7.5%'): cv.percentage, vol.Optional(CONF_MAX_LEVEL, default='12%'): cv.percentage, }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): for out in get_variable(config[CONF_OUTPUT]): yield rhs = App.register_component(Servo.new(out)) servo = Pvariable(config[CONF_ID], rhs)
from pi4home.components import binary_sensor, uart import pi4home.config_validation as cv from pi4home.const import CONF_ID, CONF_UART_ID from pi4home.cpp_generator import Pvariable, get_variable from pi4home.cpp_helpers import setup_component from pi4home.cpp_types import App, Component DEPENDENCIES = ['uart'] RDM6300Component = binary_sensor.binary_sensor_ns.class_( 'RDM6300Component', Component, uart.UARTDevice) CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_variable_id(RDM6300Component), cv.GenerateID(CONF_UART_ID): cv.use_variable_id(uart.UARTComponent), }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): for uart_ in get_variable(config[CONF_UART_ID]): yield rhs = App.make_rdm6300_component(uart_) var = Pvariable(config[CONF_ID], rhs) setup_component(var, config) BUILD_FLAGS = '-DUSE_RDM6300'
sensor.setup_sensor(template, config) setup_component(template, config) if CONF_LAMBDA in config: for template_ in process_lambda(config[CONF_LAMBDA], [], return_type=optional.template(float_)): yield add(template.set_template(template_)) BUILD_FLAGS = '-DUSE_TEMPLATE_SENSOR' CONF_SENSOR_TEMPLATE_PUBLISH = 'sensor.template.publish' SENSOR_TEMPLATE_PUBLISH_ACTION_SCHEMA = cv.Schema({ vol.Required(CONF_ID): cv.use_variable_id(sensor.Sensor), vol.Required(CONF_STATE): cv.templatable(cv.float_), }) @ACTION_REGISTRY.register(CONF_SENSOR_TEMPLATE_PUBLISH, SENSOR_TEMPLATE_PUBLISH_ACTION_SCHEMA) def sensor_template_publish_to_code(config, action_id, template_arg, args): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_sensor_publish_action(template_arg) type = SensorPublishAction.template(template_arg) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_STATE], args, float_): yield None
from pi4home.cpp_generator import Pvariable, get_variable from pi4home.cpp_helpers import setup_component from pi4home.cpp_types import App, Component DEPENDENCIES = ['time'] CONF_POWER_ID = 'power_id' TotalDailyEnergy = sensor.sensor_ns.class_('TotalDailyEnergy', sensor.Sensor, Component) PLATFORM_SCHEMA = cv.nameable( sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(TotalDailyEnergy), cv.GenerateID(CONF_TIME_ID): cv.use_variable_id(time.RealTimeClockComponent), vol.Required(CONF_POWER_ID): cv.use_variable_id(sensor.Sensor), }).extend(cv.COMPONENT_SCHEMA.schema)) def to_code(config): for time_ in get_variable(config[CONF_TIME_ID]): yield for sens in get_variable(config[CONF_POWER_ID]): yield rhs = App.make_total_daily_energy_sensor(config[CONF_NAME], time_, sens) total_energy = Pvariable(config[CONF_ID], rhs) sensor.setup_sensor(total_energy, config) setup_component(total_energy, config)