from pi4home.components.my9231 import MY9231OutputComponent import pi4home.config_validation as cv from pi4home.const import CONF_CHANNEL, CONF_ID, CONF_MY9231_ID, CONF_POWER_SUPPLY from pi4home.cpp_generator import Pvariable, get_variable from pi4home.cpp_helpers import setup_component DEPENDENCIES = ['my9231'] Channel = MY9231OutputComponent.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=65535)), cv.GenerateID(CONF_MY9231_ID): cv.use_variable_id(MY9231OutputComponent), }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): power_supply = None if CONF_POWER_SUPPLY in config: for power_supply in get_variable(config[CONF_POWER_SUPPLY]): yield my9231 = None for my9231 in get_variable(config[CONF_MY9231_ID]): yield rhs = my9231.create_channel(config[CONF_CHANNEL], power_supply) out = Pvariable(config[CONF_ID], rhs) output.setup_output_platform(out, config, skip_power_supply=True)
from pi4home import config_validation as cv from pi4home.components import sensor from pi4home.const import CONF_ID, CONF_SCAN_INTERVAL, ESP_PLATFORM_ESP32 from pi4home.core import HexInt from pi4home.cpp_generator import Pvariable, add from pi4home.cpp_helpers import setup_component from pi4home.cpp_types import App, Component, pi4home_ns ESP_PLATFORMS = [ESP_PLATFORM_ESP32] CONF_ESP32_BLE_ID = 'esp32_ble_id' ESP32BLETracker = pi4home_ns.class_('ESP32BLETracker', Component) XiaomiSensor = pi4home_ns.class_('XiaomiSensor', sensor.Sensor) XiaomiDevice = pi4home_ns.class_('XiaomiDevice') XIAOMI_SENSOR_SCHEMA = sensor.SENSOR_SCHEMA.extend( {cv.GenerateID(): cv.declare_variable_id(XiaomiSensor)}) CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_variable_id(ESP32BLETracker), vol.Optional(CONF_SCAN_INTERVAL): cv.positive_time_period_seconds, }).extend(cv.COMPONENT_SCHEMA.schema) def make_address_array(address): return [HexInt(i) for i in address.parts] def to_code(config): rhs = App.make_esp32_ble_tracker()
AddressableSegment = light.light_ns.class_('AddressableSegment') PartitionLightOutput = light.light_ns.class_('PartitionLightOutput', AddressableLight) MakePartitionLight = Application.struct('MakePartitionLight') def validate_from_to(value): if value[CONF_FROM] > value[CONF_TO]: raise vol.Invalid(u"From ({}) must not be larger than to ({})" 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):
from pi4home import automation from pi4home.automation import ACTION_REGISTRY from pi4home.components import switch import pi4home.config_validation as cv from pi4home.const import CONF_ASSUMED_STATE, CONF_ID, CONF_LAMBDA, CONF_NAME, CONF_OPTIMISTIC, \ CONF_RESTORE_STATE, CONF_STATE, CONF_TURN_OFF_ACTION, CONF_TURN_ON_ACTION from pi4home.cpp_generator import Pvariable, add, get_variable, process_lambda, templatable from pi4home.cpp_helpers import setup_component from pi4home.cpp_types import Action, App, Component, 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)
def validate_raw(value): if isinstance(value, dict): return cv.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): cv.Schema({ vol.Required(CONF_DATA): cv.hex_uint32_t, }), vol.Optional(CONF_LG): cv.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): cv.Schema({ vol.Required(CONF_ADDRESS): cv.hex_uint16_t, vol.Required(CONF_COMMAND): cv.hex_uint16_t, }), vol.Optional(CONF_SAMSUNG): cv.Schema({ vol.Required(CONF_DATA): cv.hex_uint32_t, }), vol.Optional(CONF_SONY): cv.Schema({
from pi4home.const import CONF_HUMIDITY, CONF_ID, CONF_NAME, CONF_TEMPERATURE, \ CONF_UPDATE_INTERVAL from pi4home.cpp_generator import Pvariable from pi4home.cpp_helpers import setup_component from pi4home.cpp_types import App, PollingComponent DEPENDENCIES = ['i2c'] DHT12Component = sensor.sensor_ns.class_('DHT12Component', PollingComponent, i2c.I2CDevice) DHT12TemperatureSensor = sensor.sensor_ns.class_('DHT12TemperatureSensor', sensor.EmptyPollingParentSensor) DHT12HumiditySensor = sensor.sensor_ns.class_('DHT12HumiditySensor', sensor.EmptyPollingParentSensor) PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(DHT12Component), vol.Required(CONF_TEMPERATURE): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(DHT12TemperatureSensor), })), vol.Required(CONF_HUMIDITY): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(DHT12HumiditySensor), })), vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): rhs = App.make_dht12_sensor(config[CONF_TEMPERATURE][CONF_NAME], config[CONF_HUMIDITY][CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) dht = Pvariable(config[CONF_ID], rhs)
import pi4home.config_validation as cv from pi4home.const import CONF_ECHO_PIN, CONF_ID, CONF_NAME, CONF_TRIGGER_PIN, \ CONF_UPDATE_INTERVAL, CONF_TIMEOUT from pi4home.cpp_generator import Pvariable, add from pi4home.cpp_helpers import gpio_input_pin_expression, gpio_output_pin_expression, \ setup_component from pi4home.cpp_types import App 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):
SERVICE_ARG_TYPES = { 'bool': ServiceArgType.SERVICE_ARG_TYPE_BOOL, 'int': ServiceArgType.SERVICE_ARG_TYPE_INT, 'float': ServiceArgType.SERVICE_ARG_TYPE_FLOAT, 'string': ServiceArgType.SERVICE_ARG_TYPE_STRING, } SERVICE_ARG_NATIVE_TYPES = { 'bool': bool_, 'int': int32, 'float': float_, 'string': std_string, } CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_variable_id(APIServer), vol.Optional(CONF_PORT, default=6053): cv.port, vol.Optional(CONF_PASSWORD, default=''): cv.string_strict, vol.Optional(CONF_REBOOT_TIMEOUT): cv.positive_time_period_milliseconds, vol.Optional(CONF_SERVICES): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(UserService), vol.Required(CONF_SERVICE): cv.valid_name, vol.Optional(CONF_VARIABLES, default={}): cv.Schema({ cv.validate_id_name: cv.one_of(*SERVICE_ARG_TYPES, lower=True), }), }), }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): rhs = App.init_api_server()
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 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)
from pi4home import config_validation as cv from pi4home.const import CONF_ID, CONF_SCAN_INTERVAL, CONF_TYPE, CONF_UUID, ESP_PLATFORM_ESP32 from pi4home.cpp_generator import Pvariable, RawExpression, add from pi4home.cpp_helpers import setup_component from pi4home.cpp_types import App, Component, pi4home_ns ESP_PLATFORMS = [ESP_PLATFORM_ESP32] CONFLICTS_WITH = ['esp32_ble_tracker'] ESP32BLEBeacon = pi4home_ns.class_('ESP32BLEBeacon', Component) CONF_MAJOR = 'major' CONF_MINOR = 'minor' CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_variable_id(ESP32BLEBeacon), vol.Required(CONF_TYPE): cv.one_of('IBEACON', upper=True), vol.Required(CONF_UUID): cv.uuid, vol.Optional(CONF_MAJOR): cv.uint16_t, vol.Optional(CONF_MINOR): cv.uint16_t, vol.Optional(CONF_SCAN_INTERVAL): cv.positive_time_period_milliseconds, }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): uuid = config[CONF_UUID].hex uuid_arr = [RawExpression('0x{}'.format(uuid[i:i + 2])) for i in range(0, len(uuid), 2)] rhs = App.make_esp32_ble_beacon(uuid_arr) ble = Pvariable(config[CONF_ID], rhs) if CONF_MAJOR in config: add(ble.set_major(config[CONF_MAJOR]))
def validator(value): value = validator_(value) if extra_validators is not None: value = cv.Schema([extra_validators])(value) if single: if len(value) != 1: raise vol.Invalid("Cannot have more than 1 automation for templates") return value[0] return value return validator AUTOMATION_SCHEMA = cv.Schema({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(Trigger), cv.GenerateID(CONF_AUTOMATION_ID): cv.declare_variable_id(Automation), vol.Required(CONF_THEN): validate_recursive_action, }) AND_CONDITION_SCHEMA = validate_recursive_condition @CONDITION_REGISTRY.register(CONF_AND, AND_CONDITION_SCHEMA) def and_condition_to_code(config, condition_id, template_arg, args): for conditions in build_conditions(config, template_arg, args): yield rhs = AndCondition.new(template_arg, conditions) type = AndCondition.template(template_arg) yield Pvariable(condition_id, rhs, type=type)
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({}) # pylint: disable=invalid-name text_sensor_ns = pi4home_ns.namespace('text_sensor') TextSensor = text_sensor_ns.class_('TextSensor', Nameable) TextSensorPtr = TextSensor.operator('ptr') MQTTTextSensor = text_sensor_ns.class_('MQTTTextSensor', mqtt.MQTTComponent) TextSensorStateTrigger = text_sensor_ns.class_('TextSensorStateTrigger', Trigger.template(std_string)) TextSensorPublishAction = text_sensor_ns.class_('TextSensorPublishAction', Action) TEXT_SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend({ cv.GenerateID(CONF_MQTT_ID): cv.declare_variable_id(MQTTTextSensor), vol.Optional(CONF_ICON): cv.icon, vol.Optional(CONF_ON_VALUE): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(TextSensorStateTrigger), }), }) TEXT_SENSOR_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(TEXT_SENSOR_SCHEMA.schema) def setup_text_sensor_core_(text_sensor_var, config): if CONF_INTERNAL in config:
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 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'
from pi4home.components import sensor, time import pi4home.config_validation as cv from pi4home.const import CONF_ID, CONF_NAME, CONF_TIME_ID 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)
from pi4home import pins from pi4home.components import sensor, spi from pi4home.components.spi import SPIComponent import pi4home.config_validation as cv from pi4home.const import CONF_CS_PIN, CONF_ID, CONF_NAME, CONF_SPI_ID, CONF_UPDATE_INTERVAL from pi4home.cpp_generator import Pvariable, get_variable from pi4home.cpp_helpers import gpio_output_pin_expression, setup_component from pi4home.cpp_types import App MAX31855Sensor = sensor.sensor_ns.class_('MAX31855Sensor', sensor.PollingSensorComponent, spi.SPIDevice) PLATFORM_SCHEMA = cv.nameable( sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(MAX31855Sensor), cv.GenerateID(CONF_SPI_ID): cv.use_variable_id(SPIComponent), vol.Required(CONF_CS_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).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
CONF_UPDATE_INTERVAL from pi4home.cpp_generator import Pvariable, get_variable from pi4home.cpp_helpers import gpio_output_pin_expression, setup_component from pi4home.cpp_types import App, PollingComponent, Trigger, std_string DEPENDENCIES = ['spi'] MULTI_CONF = True PN532Component = binary_sensor.binary_sensor_ns.class_('PN532Component', PollingComponent, spi.SPIDevice) PN532Trigger = binary_sensor.binary_sensor_ns.class_( 'PN532Trigger', Trigger.template(std_string)) CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_variable_id(PN532Component), cv.GenerateID(CONF_SPI_ID): cv.use_variable_id(SPIComponent), vol.Required(CONF_CS_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, vol.Optional(CONF_ON_TAG): automation.validate_automation({ cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(PN532Trigger), }), }).extend(cv.COMPONENT_SCHEMA.schema)
from pi4home.cpp_generator import Pvariable, get_variable 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))
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)
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'
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]
raise vol.Invalid('invalid gain "{}"'.format(value)) return cv.one_of(*GAIN)(value) def validate_mux(value): value = cv.string(value).upper() 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
import voluptuous as vol from pi4home import pins from pi4home.components import output import pi4home.config_validation as cv from pi4home.const import (CONF_BIT_DEPTH, CONF_CLOCK_PIN, CONF_DATA_PIN, CONF_ID, CONF_NUM_CHANNELS, CONF_NUM_CHIPS, CONF_UPDATE_ON_BOOT) from pi4home.cpp_generator import Pvariable, add from pi4home.cpp_helpers import gpio_output_pin_expression, setup_component from pi4home.cpp_types import App, Component MY9231OutputComponent = output.output_ns.class_('MY9231OutputComponent', Component) MULTI_CONF = True CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_variable_id(MY9231OutputComponent), vol.Required(CONF_DATA_PIN): pins.gpio_output_pin_schema, vol.Required(CONF_CLOCK_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_NUM_CHANNELS): vol.All(vol.Coerce(int), vol.Range(3, 1020)), vol.Optional(CONF_NUM_CHIPS): vol.All(vol.Coerce(int), vol.Range(1, 255)), vol.Optional(CONF_BIT_DEPTH): cv.one_of(8, 12, 14, 16, int=True), vol.Optional(CONF_UPDATE_ON_BOOT): vol.Coerce(bool), }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): for di in gpio_output_pin_expression(config[CONF_DATA_PIN]): yield for dcki in gpio_output_pin_expression(config[CONF_CLOCK_PIN]):
CONF_ADDRESSABLE_FIREWORKS, CONF_ADDRESSABLE_FLICKER ] EFFECTS_SCHEMA = cv.Schema({ vol.Optional(CONF_LAMBDA): cv.Schema({ vol.Required(CONF_NAME): cv.string, vol.Required(CONF_LAMBDA): cv.lambda_, vol.Optional(CONF_UPDATE_INTERVAL, default='0ms'): cv.positive_time_period_milliseconds, }), vol.Optional(CONF_RANDOM): cv.Schema({ cv.GenerateID(CONF_EFFECT_ID): cv.declare_variable_id(RandomLightEffect), vol.Optional(CONF_NAME, default="Random"): cv.string, vol.Optional(CONF_TRANSITION_LENGTH): cv.positive_time_period_milliseconds, vol.Optional(CONF_UPDATE_INTERVAL): cv.positive_time_period_milliseconds, }), vol.Optional(CONF_STROBE): cv.Schema({ cv.GenerateID(CONF_EFFECT_ID): cv.declare_variable_id(StrobeLightEffect), vol.Optional(CONF_NAME, default="Strobe"): cv.string, vol.Optional(CONF_COLORS):
vol.Required(CONF_NAME): cv.valid_name, vol.Required(CONF_PLATFORM): cv.one_of('ESP8266', 'ESPRESSIF8266', 'ESP32', 'ESPRESSIF32', upper=True), vol.Required(CONF_BOARD): validate_board, vol.Optional(CONF_PI4HOME_CORE_VERSION, default='latest'): PI4HOME_CORE_VERSION_SCHEMA, vol.Optional(CONF_ARDUINO_VERSION, default='recommended'): validate_arduino_version, vol.Optional(CONF_USE_CUSTOM_CODE, default=False): cv.boolean, vol.Optional(CONF_BUILD_PATH, default=default_build_path): cv.string, vol.Optional(CONF_PLATFORMIO_OPTIONS): cv.Schema({ cv.string_strict: vol.Any([cv.string], cv.string), }), vol.Optional(CONF_ESP8266_RESTORE_FROM_FLASH): vol.All(cv.only_on_esp8266, cv.boolean), 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"), })
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)
UARTComponent = pi4home_ns.class_('UARTComponent', Component) UARTDevice = pi4home_ns.class_('UARTDevice') MULTI_CONF = True def validate_rx_pin(value): value = pins.input_pin(value) if CORE.is_esp8266 and value >= 16: raise vol.Invalid( "Pins GPIO16 and GPIO17 cannot be used as RX pins on ESP8266.") return value CONFIG_SCHEMA = vol.All( cv.Schema({ cv.GenerateID(): cv.declare_variable_id(UARTComponent), vol.Optional(CONF_TX_PIN): pins.output_pin, vol.Optional(CONF_RX_PIN): validate_rx_pin, vol.Required(CONF_BAUD_RATE): cv.positive_int, }).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_least_one_key(CONF_TX_PIN, CONF_RX_PIN)) def to_code(config): rhs = App.init_uart(config[CONF_BAUD_RATE]) var = Pvariable(config[CONF_ID], rhs) if CONF_TX_PIN in config: add(var.set_tx_pin(config[CONF_TX_PIN])) if CONF_RX_PIN in config: add(var.set_rx_pin(config[CONF_RX_PIN]))
import voluptuous as vol import pi4home.config_validation as cv from pi4home.const import CONF_CSS_URL, CONF_ID, CONF_JS_URL, CONF_PORT from pi4home.core import CORE from pi4home.cpp_generator import Pvariable, add from pi4home.cpp_helpers import setup_component from pi4home.cpp_types import App, Component, StoringController, pi4home_ns WebServer = pi4home_ns.class_('WebServer', Component, StoringController) CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_variable_id(WebServer), vol.Optional(CONF_PORT): cv.port, vol.Optional(CONF_CSS_URL): cv.string, vol.Optional(CONF_JS_URL): cv.string, }).extend(cv.COMPONENT_SCHEMA.schema) def to_code(config): rhs = App.init_web_server(config.get(CONF_PORT)) web_server = Pvariable(config[CONF_ID], rhs) if CONF_CSS_URL in config: add(web_server.set_css_url(config[CONF_CSS_URL])) if CONF_JS_URL in config: add(web_server.set_js_url(config[CONF_JS_URL])) setup_component(web_server, config) REQUIRED_BUILD_FLAGS = '-DUSE_WEB_SERVER'
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)
MakeHX711Sensor = Application.struct('MakeHX711Sensor') HX711Sensor = sensor.sensor_ns.class_('HX711Sensor', sensor.PollingSensorComponent) CONF_DOUT_PIN = 'dout_pin' HX711Gain = sensor.sensor_ns.enum('HX711Gain') GAINS = { 128: HX711Gain.HX711_GAIN_128, 32: HX711Gain.HX711_GAIN_32, 64: HX711Gain.HX711_GAIN_64, } PLATFORM_SCHEMA = cv.nameable( sensor.SENSOR_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(HX711Sensor), vol.Required(CONF_DOUT_PIN): pins.gpio_input_pin_schema, vol.Required(CONF_CLK_PIN): pins.gpio_output_pin_schema, vol.Optional(CONF_GAIN): cv.one_of(*GAINS, int=True), vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval, }).extend(cv.COMPONENT_SCHEMA.schema)) def to_code(config): for dout_pin in gpio_input_pin_expression(config[CONF_DOUT_PIN]): yield
from pi4home.components import sensor import pi4home.config_validation as cv from pi4home.const import CONF_CF1_PIN, CONF_CF_PIN, CONF_CHANGE_MODE_EVERY, CONF_CURRENT, \ CONF_CURRENT_RESISTOR, CONF_ID, CONF_NAME, CONF_POWER, CONF_SEL_PIN, CONF_UPDATE_INTERVAL, \ CONF_VOLTAGE, CONF_VOLTAGE_DIVIDER from pi4home.cpp_generator import Pvariable, add from pi4home.cpp_helpers import gpio_output_pin_expression, setup_component from pi4home.cpp_types import App, PollingComponent HLW8012Component = sensor.sensor_ns.class_('HLW8012Component', PollingComponent) HLW8012VoltageSensor = sensor.sensor_ns.class_('HLW8012VoltageSensor', sensor.EmptySensor) HLW8012CurrentSensor = sensor.sensor_ns.class_('HLW8012CurrentSensor', sensor.EmptySensor) HLW8012PowerSensor = sensor.sensor_ns.class_('HLW8012PowerSensor', sensor.EmptyPollingParentSensor) PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(HLW8012Component), vol.Required(CONF_SEL_PIN): pins.gpio_output_pin_schema, vol.Required(CONF_CF_PIN): pins.input_pin, vol.Required(CONF_CF1_PIN): pins.input_pin, vol.Optional(CONF_VOLTAGE): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(HLW8012VoltageSensor), })), vol.Optional(CONF_CURRENT): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(HLW8012CurrentSensor), })), vol.Optional(CONF_POWER): cv.nameable(sensor.SENSOR_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(HLW8012PowerSensor), })), vol.Optional(CONF_CURRENT_RESISTOR): cv.resistance,