def to_code(config): for uart_ in get_variable(config[CONF_UART_ID]): yield rhs = App.make_cse7766(uart_, config.get(CONF_UPDATE_INTERVAL)) cse = Pvariable(config[CONF_ID], rhs) if CONF_VOLTAGE in config: conf = config[CONF_VOLTAGE] sensor.register_sensor(cse.make_voltage_sensor(conf[CONF_NAME]), conf) if CONF_CURRENT in config: conf = config[CONF_CURRENT] sensor.register_sensor(cse.make_current_sensor(conf[CONF_NAME]), conf) if CONF_POWER in config: conf = config[CONF_POWER] sensor.register_sensor(cse.make_power_sensor(conf[CONF_NAME]), conf) setup_component(cse, config)
def to_code(config): for sel in gpio_output_pin_expression(config[CONF_SEL_PIN]): yield rhs = App.make_hlw8012(sel, config[CONF_CF_PIN], config[CONF_CF1_PIN], config.get(CONF_UPDATE_INTERVAL)) hlw = Pvariable(config[CONF_ID], rhs) if CONF_VOLTAGE in config: conf = config[CONF_VOLTAGE] sensor.register_sensor(hlw.make_voltage_sensor(conf[CONF_NAME]), conf) if CONF_CURRENT in config: conf = config[CONF_CURRENT] sensor.register_sensor(hlw.make_current_sensor(conf[CONF_NAME]), conf) if CONF_POWER in config: conf = config[CONF_POWER] sensor.register_sensor(hlw.make_power_sensor(conf[CONF_NAME]), conf) if CONF_CURRENT_RESISTOR in config: add(hlw.set_current_resistor(config[CONF_CURRENT_RESISTOR])) if CONF_VOLTAGE_DIVIDER in config: add(hlw.set_voltage_divider(config[CONF_VOLTAGE_DIVIDER])) if CONF_CHANGE_MODE_EVERY in config: add(hlw.set_change_mode_every(config[CONF_CHANGE_MODE_EVERY])) setup_component(hlw, config)