# -*- coding: utf-8 -*- """Module allowing to command and control a switch, which consists in an electrical switch located between two power plugs""" import power_strip import io_group import time config = { #key: (key on the first power strip, # key on the second power strip, # key on the io group # ) 1: ((1, 4), (2, 4), (1, 1)) } def update_config(new_config): """Update the configuration""" global config config = new_config def attach(key): """Attach the link identified by key""" print "Attaching the power strips...{" execute(key, "on", 3) print "}" def detach(key): """Detach the link identified by key""" print "Detaching the power strips...{" execute(key, "off", 0) print "}" def execute(key, command, duration): """Attach or detach a link""" (power_strip_key_1, power_strip_key_2, io_group_key) = config[key] power_strip.switch(command, power_strip_key_1), power_strip.switch(command, power_strip_key_2), io_group.switch(command, io_group_key) time.sleep(duration)#To let the time to the AVLN to be reorganized