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)
def to_code(config): for red in get_variable(config[CONF_RED]): yield for green in get_variable(config[CONF_GREEN]): yield for blue in get_variable(config[CONF_BLUE]): yield rhs = App.make_rgb_light(config[CONF_NAME], red, green, blue) light_struct = variable(config[CONF_MAKE_ID], rhs) light.setup_light(light_struct.Pstate, light_struct.Pmqtt, config) setup_component(light_struct.Pstate, config)
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) setup_component(out, config)
def to_code(config): for cold_white in get_variable(config[CONF_COLD_WHITE]): yield for warm_white in get_variable(config[CONF_WARM_WHITE]): yield rhs = App.make_cwww_light(config[CONF_NAME], config[CONF_COLD_WHITE_COLOR_TEMPERATURE], config[CONF_WARM_WHITE_COLOR_TEMPERATURE], cold_white, warm_white) light_struct = variable(config[CONF_MAKE_ID], rhs) light.setup_light(light_struct.Pstate, light_struct.Pmqtt, config) setup_component(light_struct.Pstate, config)
def to_code(config): for output_ in get_variable(config[CONF_OUTPUT]): yield rhs = App.make_fan(config[CONF_NAME]) fan_struct = variable(config[CONF_MAKE_ID], rhs) add(fan_struct.Poutput.set_binary(output_)) if CONF_OSCILLATION_OUTPUT in config: for oscillation_output in get_variable(config[CONF_OSCILLATION_OUTPUT]): yield add(fan_struct.Poutput.set_oscillation(oscillation_output)) fan.setup_fan(fan_struct.Pstate, fan_struct.Pmqtt, config) setup_component(fan_struct.Poutput, config)
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] sensor.register_sensor(dev.Pmake_temperature_sensor(conf[CONF_NAME]), conf) if CONF_MOISTURE in config: conf = config[CONF_MOISTURE] sensor.register_sensor(dev.Pmake_moisture_sensor(conf[CONF_NAME]), conf) if CONF_ILLUMINANCE in config: conf = config[CONF_ILLUMINANCE] sensor.register_sensor(dev.Pmake_illuminance_sensor(conf[CONF_NAME]), conf) if CONF_CONDUCTIVITY in config: conf = config[CONF_CONDUCTIVITY] sensor.register_sensor(dev.Pmake_conductivity_sensor(conf[CONF_NAME]), conf) if CONF_BATTERY_LEVEL in config: conf = config[CONF_BATTERY_LEVEL] sensor.register_sensor(dev.Pmake_battery_level_sensor(conf[CONF_NAME]), conf)
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, light_struct.Pmqtt, config) setup_component(light_struct.Pstate, config)
def to_code(config): for uart_ in get_variable(config[CONF_UART_ID]): yield rhs = App.make_pmsx003(uart_, PMSX003_TYPES[config[CONF_TYPE]]) pms = Pvariable(config[CONF_ID], rhs) if CONF_PM_1_0 in config: conf = config[CONF_PM_1_0] sensor.register_sensor(pms.make_pm_1_0_sensor(conf[CONF_NAME]), conf) if CONF_PM_2_5 in config: conf = config[CONF_PM_2_5] sensor.register_sensor(pms.make_pm_2_5_sensor(conf[CONF_NAME]), conf) if CONF_PM_10_0 in config: conf = config[CONF_PM_10_0] sensor.register_sensor(pms.make_pm_10_0_sensor(conf[CONF_NAME]), conf) if CONF_TEMPERATURE in config: conf = config[CONF_TEMPERATURE] sensor.register_sensor(pms.make_temperature_sensor(conf[CONF_NAME]), conf) if CONF_HUMIDITY in config: conf = config[CONF_HUMIDITY] sensor.register_sensor(pms.make_humidity_sensor(conf[CONF_NAME]), conf) if CONF_FORMALDEHYDE in config: conf = config[CONF_FORMALDEHYDE] sensor.register_sensor(pms.make_formaldehyde_sensor(conf[CONF_NAME]), conf) setup_component(pms, config)
def to_code(config): hub = None for hub in get_variable(config[CONF_ESP32_BLE_ID]): yield rhs = hub.make_presence_sensor( config[CONF_NAME], make_address_array(config[CONF_MAC_ADDRESS])) binary_sensor.register_binary_sensor(rhs, config)
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 for dc in gpio_output_pin_expression(config[CONF_DC_PIN]): yield rhs = App.make_spi_ssd1306(spi_, cs, dc) ssd = Pvariable(config[CONF_ID], rhs) add(ssd.set_model(MODELS[config[CONF_MODEL]])) if CONF_RESET_PIN in config: for reset in gpio_output_pin_expression(config[CONF_RESET_PIN]): yield add(ssd.set_reset_pin(reset)) if CONF_EXTERNAL_VCC in config: add(ssd.set_external_vcc(config[CONF_EXTERNAL_VCC])) if CONF_LAMBDA in config: for lambda_ in process_lambda(config[CONF_LAMBDA], [(display.DisplayBufferRef, 'it')], return_type=void): yield add(ssd.set_writer(lambda_)) display.setup_display(ssd, config) setup_component(ssd, config)
def to_code(config): for remote in get_variable(config[CONF_REMOTE_RECEIVER_ID]): yield rhs = receiver_base(config) receiver = Pvariable(config[CONF_RECEIVER_ID], rhs) binary_sensor.register_binary_sensor(remote.add_decoder(receiver), config)
def to_code(config): hub = None for hub in get_variable(config[CONF_ESP32_TOUCH_ID]): yield touch_pad = TOUCH_PADS[config[CONF_PIN]] rhs = hub.make_touch_pad(config[CONF_NAME], touch_pad, config[CONF_THRESHOLD]) binary_sensor.register_binary_sensor(rhs, config)
def to_code(config): rhs = App.make_fast_led_light(config[CONF_NAME]) make = variable(config[CONF_MAKE_ID], rhs) fast_led = make.Pfast_led rgb_order = None if CONF_RGB_ORDER in config: rgb_order = RawExpression(config[CONF_RGB_ORDER]) template_args = TemplateArguments(RawExpression(config[CONF_CHIPSET]), config[CONF_DATA_PIN], config[CONF_CLOCK_PIN], rgb_order) add(fast_led.add_leds(template_args, config[CONF_NUM_LEDS])) if CONF_MAX_REFRESH_RATE in config: add(fast_led.set_max_refresh_rate(config[CONF_MAX_REFRESH_RATE])) if CONF_POWER_SUPPLY in config: for power_supply in get_variable(config[CONF_POWER_SUPPLY]): yield add(fast_led.set_power_supply(power_supply)) if CONF_COLOR_CORRECT in config: r, g, b = config[CONF_COLOR_CORRECT] add(fast_led.set_correction(r, g, b)) light.setup_light(make.Pstate, make.Pmqtt, config) setup_component(fast_led, config)
def to_code(config): for output_ in get_variable(config[CONF_OUTPUT]): yield rhs = App.make_output_switch(config[CONF_NAME], output_) make = variable(config[CONF_MAKE_ID], rhs) switch_ = make.Pswitch_ switch.setup_switch(switch_, make.Pmqtt, config) setup_component(switch, config)
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)
def to_code(config): for red in get_variable(config[CONF_RED]): yield for green in get_variable(config[CONF_GREEN]): yield for blue in get_variable(config[CONF_BLUE]): yield for cold_white in get_variable(config[CONF_COLD_WHITE]): yield for warm_white in get_variable(config[CONF_WARM_WHITE]): yield rhs = App.make_rgbww_light(config[CONF_NAME], config[CONF_COLD_WHITE_COLOR_TEMPERATURE], config[CONF_WARM_WHITE_COLOR_TEMPERATURE], red, green, blue, cold_white, warm_white) light_struct = variable(config[CONF_MAKE_ID], rhs) light.setup_light(light_struct.Pstate, light_struct.Pmqtt, config) setup_component(light_struct.Pstate, config)
def stepper_set_target_to_code(config, action_id, arg_type, template_arg): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_set_target_action(template_arg) type = SetTargetAction.template(arg_type) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_TARGET], arg_type, int32): yield None add(action.set_target(template_)) yield action
def stepper_report_position_to_code(config, action_id, arg_type, template_arg): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_report_position_action(template_arg) type = ReportPositionAction.template(arg_type) action = Pvariable(action_id, rhs, type=type) for template_ in templatable(config[CONF_POSITION], arg_type, int32): yield None add(action.set_target(template_)) yield action
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], ArrayInitializer(*data, multiline=False)) restart = variable(config[CONF_MAKE_ID], rhs) switch.setup_switch(restart.Puart, restart.Pmqtt, config)
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)) sensor.register_sensor(rhs, config)
def light_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(template_arg) action = Pvariable(action_id, rhs, type=type) if CONF_TRANSITION_LENGTH in config: for template_ in templatable(config[CONF_TRANSITION_LENGTH], arg_type, uint32): yield None add(action.set_transition_length(template_)) yield action
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_max6675_sensor(config[CONF_NAME], spi_, cs, config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) max6675 = make.Pmax6675 sensor.setup_sensor(max6675, make.Pmqtt, config) setup_component(max6675, config)
def to_code(config): for output_ in get_variable(config[CONF_OUTPUT]): yield rhs = App.make_fan(config[CONF_NAME]) fan_struct = variable(config[CONF_MAKE_ID], rhs) if CONF_SPEED in config: speeds = config[CONF_SPEED] add( fan_struct.Poutput.set_speed(output_, speeds[CONF_LOW], speeds[CONF_MEDIUM], speeds[CONF_HIGH])) else: add(fan_struct.Poutput.set_speed(output_)) if CONF_OSCILLATION_OUTPUT in config: for oscillation_output in get_variable( config[CONF_OSCILLATION_OUTPUT]): yield add(fan_struct.Poutput.set_oscillation(oscillation_output)) fan.setup_fan(fan_struct.Pstate, fan_struct.Pmqtt, config)
def sensor_in_range_to_code(config, condition_id, arg_type, template_arg): for var in get_variable(config[CONF_ID]): yield None rhs = var.make_sensor_in_range_condition(template_arg) type = SensorInRangeCondition.template(arg_type) cond = Pvariable(condition_id, rhs, type=type) if CONF_ABOVE in config: add(cond.set_min(config[CONF_ABOVE])) if CONF_BELOW in config: add(cond.set_max(config[CONF_BELOW])) yield cond
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_pn532_component(spi_, cs, config.get(CONF_UPDATE_INTERVAL)) pn532 = Pvariable(config[CONF_ID], rhs) for conf_ in config.get(CONF_ON_TAG, []): trigger = Pvariable(conf_[CONF_TRIGGER_ID], pn532.make_trigger()) automation.build_automation(trigger, std_string, conf_) setup_component(pn532, config)
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')]): yield add(nextion.set_writer(lambda_)) display.setup_display(nextion, config) setup_component(nextion, config)
def to_code(config): for uart_ in get_variable(config[CONF_UART_ID]): yield rhs = App.make_mhz19_sensor(uart_, config[CONF_CO2][CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) mhz19 = make.Pmhz19 Pvariable(config[CONF_ID], mhz19) sensor.setup_sensor(mhz19.Pget_co2_sensor(), make.Pmqtt, config[CONF_CO2]) if CONF_TEMPERATURE in config: sensor.register_sensor(mhz19.Pmake_temperature_sensor(config[CONF_TEMPERATURE][CONF_NAME]), config[CONF_TEMPERATURE]) setup_component(mhz19, config)
def fan_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) action = Pvariable(action_id, rhs, type=type) if CONF_OSCILLATING in config: for template_ in templatable(config[CONF_OSCILLATING], arg_type, bool_): yield None add(action.set_oscillating(template_)) if CONF_SPEED in config: for template_ in templatable(config[CONF_SPEED], arg_type, FanSpeed): yield None add(action.set_speed(template_)) yield action
def light_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(template_arg) action = Pvariable(action_id, rhs, type=type) if CONF_TRANSITION_LENGTH in config: for template_ in templatable(config[CONF_TRANSITION_LENGTH], arg_type, uint32): yield None add(action.set_transition_length(template_)) if CONF_FLASH_LENGTH in config: for template_ in templatable(config[CONF_FLASH_LENGTH], arg_type, uint32): yield None add(action.set_flash_length(template_)) if CONF_BRIGHTNESS in config: for template_ in templatable(config[CONF_BRIGHTNESS], arg_type, float_): yield None add(action.set_brightness(template_)) if CONF_RED in config: for template_ in templatable(config[CONF_RED], arg_type, float_): yield None add(action.set_red(template_)) if CONF_GREEN in config: for template_ in templatable(config[CONF_GREEN], arg_type, float_): yield None add(action.set_green(template_)) if CONF_BLUE in config: for template_ in templatable(config[CONF_BLUE], arg_type, float_): yield None add(action.set_blue(template_)) if CONF_WHITE in config: for template_ in templatable(config[CONF_WHITE], arg_type, float_): yield None add(action.set_white(template_)) if CONF_COLOR_TEMPERATURE in config: for template_ in templatable(config[CONF_COLOR_TEMPERATURE], arg_type, float_): yield None add(action.set_color_temperature(template_)) if CONF_EFFECT in config: for template_ in templatable(config[CONF_EFFECT], arg_type, std_string): yield None add(action.set_effect(template_)) yield action
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)