def setup_mqtt_sensor_component(obj, config): if CONF_EXPIRE_AFTER in config: if config[CONF_EXPIRE_AFTER] is None: add(obj.disable_expire_after()) else: add(obj.set_expire_after(config[CONF_EXPIRE_AFTER])) setup_mqtt_component(obj, config)
def setup_sensor_core_(sensor_var, mqtt_var, config): if CONF_UNIT_OF_MEASUREMENT in config: add( sensor_var.set_unit_of_measurement( config[CONF_UNIT_OF_MEASUREMENT])) if CONF_ICON in config: add(sensor_var.set_icon(config[CONF_ICON])) if CONF_ACCURACY_DECIMALS in config: add(sensor_var.set_accuracy_decimals(config[CONF_ACCURACY_DECIMALS])) if CONF_FILTERS in config: add(sensor_var.set_filters(setup_filters(config[CONF_FILTERS]))) for conf in config.get(CONF_ON_VALUE, []): rhs = sensor_var.make_value_trigger() trigger = Pvariable(SensorValueTrigger, conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, float_, conf) for conf in config.get(CONF_ON_RAW_VALUE, []): rhs = sensor_var.make_raw_value_trigger() trigger = Pvariable(RawSensorValueTrigger, conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, float_, conf) for conf in config.get(CONF_ON_VALUE_RANGE, []): rhs = sensor_var.make_value_range_trigger() trigger = Pvariable(ValueRangeTrigger, conf[CONF_TRIGGER_ID], rhs) if CONF_ABOVE in conf: trigger.set_min(templatable(conf[CONF_ABOVE], float_, float_)) if CONF_BELOW in conf: trigger.set_max(templatable(conf[CONF_BELOW], float_, float_)) automation.build_automation(trigger, float_, conf) if CONF_EXPIRE_AFTER in config: if config[CONF_EXPIRE_AFTER] is None: add(mqtt_var.disable_expire_after()) else: add(mqtt_var.set_expire_after(config[CONF_EXPIRE_AFTER])) setup_mqtt_component(mqtt_var, config)
def setup_switch_core_(switch_var, mqtt_var, config): if CONF_ICON in config: add(switch_var.set_icon(config[CONF_ICON])) if CONF_INVERTED in config: add(switch_var.set_inverted(config[CONF_INVERTED])) setup_mqtt_component(mqtt_var, config)
def setup_binary_sensor_core_(binary_sensor_var, mqtt_var, config): if CONF_DEVICE_CLASS in config: add(binary_sensor_var.set_device_class(config[CONF_DEVICE_CLASS])) if CONF_INVERTED in config: add(binary_sensor_var.set_inverted(config[CONF_INVERTED])) for conf in config.get(CONF_ON_PRESS, []): rhs = binary_sensor_var.make_press_trigger() trigger = Pvariable(PressTrigger, conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_RELEASE, []): rhs = binary_sensor_var.make_release_trigger() trigger = Pvariable(ReleaseTrigger, conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_CLICK, []): rhs = binary_sensor_var.make_click_trigger(conf[CONF_MIN_LENGTH], conf[CONF_MAX_LENGTH]) trigger = Pvariable(ClickTrigger, conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_DOUBLE_CLICK, []): rhs = binary_sensor_var.make_double_click_trigger( conf[CONF_MIN_LENGTH], conf[CONF_MAX_LENGTH]) trigger = Pvariable(DoubleClickTrigger, conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) setup_mqtt_component(mqtt_var, config)
def setup_binary_sensor_core_(binary_sensor_var, mqtt_var, config): if CONF_INTERNAL in config: add(binary_sensor_var.set_internal(CONF_INTERNAL)) if CONF_DEVICE_CLASS in config: add(binary_sensor_var.set_device_class(config[CONF_DEVICE_CLASS])) if CONF_INVERTED in config: add(binary_sensor_var.set_inverted(config[CONF_INVERTED])) if CONF_FILTERS in config: filters = None for filters in setup_filters(config[CONF_FILTERS]): yield add(binary_sensor_var.add_filters(filters)) for conf in config.get(CONF_ON_PRESS, []): rhs = binary_sensor_var.make_press_trigger() trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_RELEASE, []): rhs = binary_sensor_var.make_release_trigger() trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_CLICK, []): rhs = binary_sensor_var.make_click_trigger(conf[CONF_MIN_LENGTH], conf[CONF_MAX_LENGTH]) trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_DOUBLE_CLICK, []): rhs = binary_sensor_var.make_double_click_trigger(conf[CONF_MIN_LENGTH], conf[CONF_MAX_LENGTH]) trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) setup_mqtt_component(mqtt_var, config)
def setup_light_core_(light_var, mqtt_var, config): if CONF_DEFAULT_TRANSITION_LENGTH in config: add(light_var.set_default_transition_length(config[CONF_DEFAULT_TRANSITION_LENGTH])) if CONF_GAMMA_CORRECT in config: add(light_var.set_gamma_correct(config[CONF_GAMMA_CORRECT])) setup_mqtt_component(mqtt_var, config)
def to_code(config): red = get_variable(config[CONF_RED]) green = get_variable(config[CONF_GREEN]) blue = get_variable(config[CONF_BLUE]) rhs = App.make_rgb_light(config[CONF_NAME], red, green, blue) light_struct = variable('Application::MakeLight', config[CONF_ID], rhs) if CONF_GAMMA_CORRECT in config: add(light_struct.Poutput.set_gamma_correct(config[CONF_GAMMA_CORRECT])) setup_mqtt_component(light_struct.Pmqtt, config) light.setup_light_component(light_struct.Pstate, config)
def setup_binary_sensor_core_(binary_sensor_var, mqtt_var, config): if CONF_INTERNAL in config: add(binary_sensor_var.set_internal(CONF_INTERNAL)) if CONF_DEVICE_CLASS in config: add(binary_sensor_var.set_device_class(config[CONF_DEVICE_CLASS])) if CONF_INVERTED in config: add(binary_sensor_var.set_inverted(config[CONF_INVERTED])) if CONF_FILTERS in config: filters = None for filters in setup_filters(config[CONF_FILTERS]): yield add(binary_sensor_var.add_filters(filters)) for conf in config.get(CONF_ON_PRESS, []): rhs = binary_sensor_var.make_press_trigger() trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_RELEASE, []): rhs = binary_sensor_var.make_release_trigger() trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_CLICK, []): rhs = binary_sensor_var.make_click_trigger(conf[CONF_MIN_LENGTH], conf[CONF_MAX_LENGTH]) trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_DOUBLE_CLICK, []): rhs = binary_sensor_var.make_double_click_trigger( conf[CONF_MIN_LENGTH], conf[CONF_MAX_LENGTH]) trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, NoArg, conf) for conf in config.get(CONF_ON_MULTI_CLICK, []): timings = [] for tim in conf[CONF_TIMING]: timings.append( StructInitializer( MultiClickTriggerEvent, ('state', tim[CONF_STATE]), ('min_length', tim[CONF_MIN_LENGTH]), ('max_length', tim.get(CONF_MAX_LENGTH, 4294967294)), )) timings = ArrayInitializer(*timings, multiline=False) rhs = App.register_component( binary_sensor_var.make_multi_click_trigger(timings)) trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) if CONF_INVALID_COOLDOWN in conf: add(trigger.set_invalid_cooldown(conf[CONF_INVALID_COOLDOWN])) automation.build_automation(trigger, NoArg, conf) setup_mqtt_component(mqtt_var, config)
def setup_text_sensor_core_(text_sensor_var, mqtt_var, config): if CONF_INTERNAL in config: add(text_sensor_var.set_internal(config[CONF_INTERNAL])) if CONF_ICON in config: add(text_sensor_var.set_icon(config[CONF_ICON])) for conf in config.get(CONF_ON_VALUE, []): rhs = text_sensor_var.make_state_trigger() trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs) automation.build_automation(trigger, std_string, conf) setup_mqtt_component(mqtt_var, config)
def setup_light_core_(light_var, mqtt_var, config): if CONF_INTERNAL in config: add(light_var.set_internal(config[CONF_INTERNAL])) if CONF_DEFAULT_TRANSITION_LENGTH in config: add(light_var.set_default_transition_length(config[CONF_DEFAULT_TRANSITION_LENGTH])) if CONF_GAMMA_CORRECT in config: add(light_var.set_gamma_correct(config[CONF_GAMMA_CORRECT])) effects = [] for conf in config.get(CONF_EFFECTS, []): for effect in build_effect(conf): yield effects.append(effect) if effects: add(light_var.add_effects(ArrayInitializer(*effects))) setup_mqtt_component(mqtt_var, config)
def setup_mqtt_fan(obj, config): if CONF_OSCILLATION_STATE_TOPIC in config: add( obj.set_custom_oscillation_state_topic( config[CONF_OSCILLATION_STATE_TOPIC])) if CONF_OSCILLATION_COMMAND_TOPIC in config: add( obj.set_custom_oscillation_command_topic( config[CONF_OSCILLATION_COMMAND_TOPIC])) if CONF_SPEED_STATE_TOPIC in config: add(obj.set_custom_speed_state_topic(config[CONF_SPEED_STATE_TOPIC])) if CONF_SPEED_COMMAND_TOPIC in config: add( obj.set_custom_speed_command_topic( config[CONF_SPEED_COMMAND_TOPIC])) setup_mqtt_component(obj, config)
def setup_fan_core_(fan_var, mqtt_var, config): if CONF_INTERNAL in config: add(fan_var.set_internal(config[CONF_INTERNAL])) if CONF_OSCILLATION_STATE_TOPIC in config: add( mqtt_var.set_custom_oscillation_state_topic( config[CONF_OSCILLATION_STATE_TOPIC])) if CONF_OSCILLATION_COMMAND_TOPIC in config: add( mqtt_var.set_custom_oscillation_command_topic( config[CONF_OSCILLATION_COMMAND_TOPIC])) if CONF_SPEED_STATE_TOPIC in config: add( mqtt_var.set_custom_speed_state_topic( config[CONF_SPEED_STATE_TOPIC])) if CONF_SPEED_COMMAND_TOPIC in config: add( mqtt_var.set_custom_speed_command_topic( config[CONF_SPEED_COMMAND_TOPIC])) setup_mqtt_component(mqtt_var, config)
def setup_mqtt_switch(obj, config): setup_mqtt_component(obj, config)
def to_code(config): output = get_variable(config[CONF_OUTPUT]) rhs = App.make_binary_light(config[CONF_NAME], output) light_struct = variable('Application::MakeLight', config[CONF_ID], rhs) setup_mqtt_component(light_struct.Pmqtt, config) light.setup_light_component(light_struct.Pstate, config)
def setup_mqtt_binary_sensor(obj, config): setup_mqtt_component(obj, config)
def setup_cover_core_(cover_var, mqtt_var, config): setup_mqtt_component(mqtt_var, config)
def setup_cover_core_(cover_var, mqtt_var, config): if CONF_INTERNAL in config: add(cover_var.set_internal(config[CONF_INTERNAL])) setup_mqtt_component(mqtt_var, config)