How to know if the toolshelf/properties/header is ON/OFF with python?
there's no official way to know, you can just know, i just found a trick with the interface region width 

import bpy

bpy.context.area.ui_type = 'VIEW_3D'
area = bpy.context.area

for region in area.regions:
    if region.type == 'TOOLS':
        if region.width == 1: 
            print("toolshelf closed")
        else:
            print("toolshelf open")
    elif region.type =='UI':
        if region.width == 1: 
            print("properties closed")
        else:
            print("properties open")
    elif region.type =='HEADER':
        if region.width == 1: 
            print("header closed")
        else:
            print("header open")