Shorthand and nicer python syntax for four options clicking a button
If 0 and 1 are the only possible values of af_button.checked, you could condense this to just one if:

if (state == 'click') != af_button.checked:
    squishtest.clickButton(squishtest.waitForObject(af_button))


The parentheses are important because otherwise Python would treat this as a chained comparison. (state == 'click') evaluates to True or False, and True equals 1 and False equals 0.