How to sort states of entities by sensor and switch in python

hello Great community,
Im writing a code using python to get all the values of my multisensors, switches and store it in csv file.
the problem is that my code became very long and biger because, i have to repeat the same code by every entity (temparatur, humidity, luminance…) of multisensor. // store value and name of sensor
my question is:
Im looking for crita how can i do if loop to make my code not longer and biger:
so that i sort states by sensors:
if state = Sensor:
store name and value
else
pass // alarm states are not relevant
if state = Switch:
store name, power, energy
else
pass // alarm state, node infos state, bweather state and blabla state are not relevant

api = remote.API('127.0.0.1', 'password')
entities = remote.get_states(api)
for entity in entities:
    #print(entity)  #here i get millions of states which i don't need 
    SensorTemperatur = remote.get_state(api,'sensor.aeotec_zw074_multisensor_gen5_relative_humidity')
    time=  datetime.strftime(SensorTemperatur.last_changed, '%b %d %y %I:%M%p')
    #print(time) 

Every help will be appreciated