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_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): rhs = App.make_template_switch(config[CONF_NAME]) make = variable(config[CONF_MAKE_ID], rhs) template = make.Ptemplate_ switch.setup_switch(template, make.Pmqtt, 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_RESTORE_STATE in config: add(template.set_restore_state(config[CONF_RESTORE_STATE])) setup_component(template, config)
def to_code(config): rhs = App.make_bme280_sensor(config[CONF_TEMPERATURE][CONF_NAME], config[CONF_PRESSURE][CONF_NAME], config[CONF_HUMIDITY][CONF_NAME], config[CONF_ADDRESS], config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) bme280 = make.Pbme280 if CONF_OVERSAMPLING in config[CONF_TEMPERATURE]: constant = OVERSAMPLING_OPTIONS[config[CONF_TEMPERATURE] [CONF_OVERSAMPLING]] add(bme280.set_temperature_oversampling(constant)) if CONF_OVERSAMPLING in config[CONF_PRESSURE]: constant = OVERSAMPLING_OPTIONS[config[CONF_PRESSURE] [CONF_OVERSAMPLING]] add(bme280.set_pressure_oversampling(constant)) if CONF_OVERSAMPLING in config[CONF_HUMIDITY]: constant = OVERSAMPLING_OPTIONS[config[CONF_HUMIDITY] [CONF_OVERSAMPLING]] add(bme280.set_humidity_oversampling(constant)) if CONF_IIR_FILTER in config: constant = IIR_FILTER_OPTIONS[config[CONF_IIR_FILTER]] add(bme280.set_iir_filter(constant)) sensor.setup_sensor(bme280.Pget_temperature_sensor(), make.Pmqtt_temperature, config[CONF_TEMPERATURE]) sensor.setup_sensor(bme280.Pget_pressure_sensor(), make.Pmqtt_pressure, config[CONF_PRESSURE]) sensor.setup_sensor(bme280.Pget_humidity_sensor(), make.Pmqtt_humidity, config[CONF_HUMIDITY]) setup_component(bme280, config)
def to_code(config): pin = None for pin in gpio_input_pin_expression(config[CONF_PIN]): yield rhs = App.make_gpio_binary_sensor(config[CONF_NAME], pin) gpio = variable(config[CONF_MAKE_ID], rhs) binary_sensor.setup_binary_sensor(gpio.Pgpio, gpio.Pmqtt, config) setup_component(gpio.Pgpio, config)
def to_code(config): rhs = App.make_uptime_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) uptime = make.Puptime sensor.setup_sensor(uptime, make.Pmqtt, config) setup_component(uptime, 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 template_ in process_lambda(config[CONF_LAMBDA], [], return_type=std_vector.template(sensor.SensorPtr)): yield rhs = CustomSensorConstructor(template_) custom = variable(config[CONF_ID], rhs) for i, sens in enumerate(config[CONF_SENSORS]): sensor.register_sensor(custom.get_sensor(i), sens)
def to_code(config): rhs = App.make_bh1750_sensor(config[CONF_NAME], config[CONF_ADDRESS], config.get(CONF_UPDATE_INTERVAL)) make_bh1750 = variable(config[CONF_MAKE_ID], rhs) bh1750 = make_bh1750.Pbh1750 if CONF_RESOLUTION in config: add(bh1750.set_resolution(BH1750_RESOLUTIONS[config[CONF_RESOLUTION]])) sensor.setup_sensor(bh1750, make_bh1750.Pmqtt, config) setup_component(bh1750, config)
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 template_ in process_lambda( config[CONF_LAMBDA], [], return_type=std_vector.template(ComponentPtr)): yield rhs = CustomComponentConstructor(template_) custom = variable(config[CONF_ID], rhs) for i, comp in enumerate(config.get(CONF_COMPONENTS, [])): setup_component(custom.get_component(i), comp)
def to_code(config): rhs = App.make_mqtt_subscribe_sensor(config[CONF_NAME], config[CONF_TOPIC]) make = variable(config[CONF_MAKE_ID], rhs) subs = make.Psensor if CONF_QOS in config: add(subs.set_qos(config[CONF_QOS])) sensor.setup_sensor(subs, make.Pmqtt, config) setup_component(subs, config)
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, sens in enumerate(config[CONF_SWITCHES]): switch.register_switch(custom.get_switch(i), sens)
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 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): rhs = App.make_template_binary_sensor(config[CONF_NAME]) make = variable(config[CONF_MAKE_ID], rhs) binary_sensor.setup_binary_sensor(make.Ptemplate_, make.Pmqtt, config) setup_component(make.Ptemplate_, config) template_ = None for template_ in process_lambda(config[CONF_LAMBDA], [], return_type=optional.template(bool_)): yield add(make.Ptemplate_.set_template(template_))
def to_code(config): pin = config[CONF_PIN] if pin == 'VCC': pin = 0 rhs = App.make_adc_sensor(config[CONF_NAME], pin, config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) adc = make.Padc if CONF_ATTENUATION in config: add(adc.set_attenuation(ATTENUATION_MODES[config[CONF_ATTENUATION]])) sensor.setup_sensor(adc, make.Pmqtt, config) setup_component(adc, config)
def to_code(config): for pin in gpio_output_pin_expression(config[CONF_PIN]): yield rhs = App.make_gpio_switch(config[CONF_NAME], pin) make = variable(config[CONF_MAKE_ID], rhs) gpio = make.Pswitch_ if CONF_RESTORE_MODE in config: add(gpio.set_restore_mode(RESTORE_MODES[config[CONF_RESTORE_MODE]])) switch.setup_switch(gpio, make.Pmqtt, config) setup_component(gpio, 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): rhs = App.make_template_text_sensor(config[CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) template = make.Ptemplate_ text_sensor.setup_text_sensor(template, make.Pmqtt, config) setup_component(template, config) for template_ in process_lambda(config[CONF_LAMBDA], [], return_type=optional.template(std_string)): yield add(template.set_template(template_))
def to_code(config): rhs = App.make_dht12_sensor(config[CONF_TEMPERATURE][CONF_NAME], config[CONF_HUMIDITY][CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) dht = make.Pdht12 Pvariable(config[CONF_ID], dht) sensor.setup_sensor(dht.Pget_temperature_sensor(), make.Pmqtt_temperature, config[CONF_TEMPERATURE]) sensor.setup_sensor(dht.Pget_humidity_sensor(), make.Pmqtt_humidity, config[CONF_HUMIDITY]) setup_component(dht, config)
def to_code(config): rhs = App.make_hdc1080_sensor(config[CONF_TEMPERATURE][CONF_NAME], config[CONF_HUMIDITY][CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) hdc1080 = make.Phdc1080 Pvariable(config[CONF_ID], hdc1080) sensor.setup_sensor(hdc1080.Pget_temperature_sensor(), make.Pmqtt_temperature, config[CONF_TEMPERATURE]) sensor.setup_sensor(hdc1080.Pget_humidity_sensor(), make.Pmqtt_humidity, config[CONF_HUMIDITY]) setup_component(hdc1080, config)
def to_code(config): rhs = App.make_bmp085_sensor(config[CONF_TEMPERATURE][CONF_NAME], config[CONF_PRESSURE][CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) bmp = variable(config[CONF_MAKE_ID], rhs) if CONF_ADDRESS in config: add(bmp.Pbmp.set_address(HexIntLiteral(config[CONF_ADDRESS]))) sensor.setup_sensor(bmp.Pbmp.Pget_temperature_sensor(), bmp.Pmqtt_temperature, config[CONF_TEMPERATURE]) sensor.setup_sensor(bmp.Pbmp.Pget_pressure_sensor(), bmp.Pmqtt_pressure, config[CONF_PRESSURE]) setup_component(bmp.Pbmp, 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): rhs = App.make_sht3xd_sensor(config[CONF_TEMPERATURE][CONF_NAME], config[CONF_HUMIDITY][CONF_NAME], config[CONF_ADDRESS], config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) sht3xd = make.Psht3xd Pvariable(config[CONF_ID], sht3xd) sensor.setup_sensor(sht3xd.Pget_temperature_sensor(), make.Pmqtt_temperature, config[CONF_TEMPERATURE]) sensor.setup_sensor(sht3xd.Pget_humidity_sensor(), make.Pmqtt_humidity, config[CONF_HUMIDITY]) setup_component(sht3xd, config)
def wifi_network(config, static_ip): ap = variable(config[CONF_ID], WiFiAP()) if CONF_SSID in config: add(ap.set_ssid(config[CONF_SSID])) if CONF_PASSWORD in config: add(ap.set_password(config[CONF_PASSWORD])) if CONF_BSSID in config: bssid = [HexInt(i) for i in config[CONF_BSSID].parts] add(ap.set_bssid(ArrayInitializer(*bssid, multiline=False))) if CONF_CHANNEL in config: add(ap.set_channel(config[CONF_CHANNEL])) if static_ip is not None: add(ap.set_manual_ip(manual_ip(static_ip))) return ap
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 to_code(config): rhs = App.make_ms5611_sensor(config[CONF_TEMPERATURE][CONF_NAME], config[CONF_PRESSURE][CONF_NAME], config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) ms5611 = make.Pms5611 Pvariable(config[CONF_ID], ms5611) if CONF_ADDRESS in config: add(ms5611.set_address(config[CONF_ADDRESS])) sensor.setup_sensor(ms5611.Pget_temperature_sensor(), make.Pmqtt_temperature, config[CONF_TEMPERATURE]) sensor.setup_sensor(ms5611.Pget_pressure_sensor(), make.Pmqtt_pressure, config[CONF_PRESSURE]) setup_component(ms5611, config)
def to_code(config): type = config[CONF_TYPE] if type == 'binary': ret_type = output.BinaryOutputPtr klass = CustomBinaryOutputConstructor else: ret_type = output.FloatOutputPtr klass = CustomFloatOutputConstructor for template_ in process_lambda(config[CONF_LAMBDA], [], return_type=std_vector.template(ret_type)): yield rhs = klass(template_) custom = variable(config[CONF_ID], rhs) for i, sens in enumerate(config[CONF_OUTPUTS]): output.register_output(custom.get_output(i), sens)
def to_code(config): for dout_pin in gpio_input_pin_expression(config[CONF_DOUT_PIN]): yield for sck_pin in gpio_input_pin_expression(config[CONF_CLK_PIN]): yield rhs = App.make_hx711_sensor(config[CONF_NAME], dout_pin, sck_pin, config.get(CONF_UPDATE_INTERVAL)) make = variable(config[CONF_MAKE_ID], rhs) hx711 = make.Phx711 if CONF_GAIN in config: add(hx711.set_gain(GAINS[config[CONF_GAIN]])) sensor.setup_sensor(hx711, make.Pmqtt, config) setup_component(hx711, config)