Excellent work @LighFusion and @bravosierra99. Since I ended up here after looking for the Python solution, I'll paste it for anybody else.
widget = ida_kernwin.find_widget('Pseudocode-Y')
vu = ida_hexrays.get_widget_vdui(widget)
vu.rename_lvar(vu.cfunc.lvars[2], "pModelInfo", 1)
@Igor Skochinsky -- I just think it would just be common decency to make source or documentation available regarding how the existing basic [context] menu functionality works, so people have something to build on. I can't count the number of times I've been unable to fully replicate some basic inbuilt menu option, watching scripts constantly fail when I can manually perform the operation and it works perfectly.
Here's a more complete example:
def rename_lvar(src, dst, ea):
# if you want to use an existing view:
# widget = ida_kernwin.find_widget('Pseudocode-Y')
# vu = ida_hexrays.get_widget_vdui(widget)
func = idaapi.get_func(ea)
if func:
ea = func.start_ea
vu = idaapi.open_pseudocode(ea, 0)
lvars = [n for n in vu.cfunc.lvars if n.name == src]
if len(lvars) == 1:
print("renaming {} to {}".format(lvars[0].name, dst))
vu.rename_lvar(lvars[0], dst, 1)
# how to close the view without a widget object?
# idautils.close_pseudocode (nope)
# ida_kerwin.close_widget (nope)
else:
print("couldn't find var {}".format(src))