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_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, config) setup_component(fast_led, config)
def exp_mqtt_message(config): if config is None: return optional(TemplateArguments(MQTTMessage)) exp = StructInitializer(MQTTMessage, ('topic', config[CONF_TOPIC]), ('payload', config.get(CONF_PAYLOAD, "")), ('qos', config[CONF_QOS]), ('retain', config[CONF_RETAIN])) return exp
def build_condition(full_config, arg_type): action_id = full_config[CONF_CONDITION_ID] key, config = next((k, v) for k, v in full_config.items() if k in CONDITION_REGISTRY) builder = CONDITION_REGISTRY[key][1] template_arg = TemplateArguments(arg_type) for result in builder(config, action_id, arg_type, template_arg): yield None yield result
def build_automation_(trigger, args, config): arg_types = [arg[0] for arg in args] templ = TemplateArguments(*arg_types) rhs = App.make_automation(templ, trigger) type = Automation.template(templ) obj = Pvariable(config[CONF_AUTOMATION_ID], rhs, type=type) for actions in build_actions(config[CONF_THEN], templ, args): yield None add(obj.add_actions(actions)) yield obj
def build_automation_(trigger, arg_type, config): rhs = App.make_automation(TemplateArguments(arg_type), trigger) type = Automation.template(arg_type) obj = Pvariable(config[CONF_AUTOMATION_ID], rhs, type=type) if CONF_IF in config: conditions = None for conditions in build_conditions(config[CONF_IF], arg_type): yield None add(obj.add_conditions(conditions)) actions = None for actions in build_actions(config[CONF_THEN], arg_type): yield None add(obj.add_actions(actions)) yield obj
def to_code(config): type_ = RawExpression(config[CONF_TYPE]) template_args = TemplateArguments(type_) res_type = GlobalVariableComponent.template(template_args) initial_value = None if CONF_INITIAL_VALUE in config: initial_value = RawExpression(config[CONF_INITIAL_VALUE]) rhs = App.Pmake_global_variable(template_args, initial_value) glob = Pvariable(config[CONF_ID], rhs, type=res_type) if config.get(CONF_RESTORE_VALUE, False): hash_ = hash(config[CONF_ID].id) % 2**32 add(glob.set_restore_value(hash_)) setup_component(glob, config)
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 template = TemplateArguments(getattr(global_ns, format_method(config)), color_feat) rhs = func(template, config[CONF_NAME]) make = variable(config[CONF_MAKE_ID], rhs, type=MakeNeoPixelBusLight.template(template)) output = make.Poutput if CONF_PIN in config: add(output.add_leds(config[CONF_NUM_LEDS], config[CONF_PIN])) else: add( output.add_leds(config[CONF_NUM_LEDS], config[CONF_CLOCK_PIN], config[CONF_DATA_PIN])) add(output.set_pixel_order(getattr(ESPNeoPixelOrder, type_))) if CONF_POWER_SUPPLY in config: for power_supply in get_variable(config[CONF_POWER_SUPPLY]): yield add(output.set_power_supply(power_supply)) if CONF_COLOR_CORRECT in config: add(output.set_correction(*config[CONF_COLOR_CORRECT])) light.setup_light(make.Pstate, config) setup_component(output, config)