summaryrefslogtreecommitdiff
path: root/validation/validlib/link.py
blob: 6c22e9dc725229417d72752688b9b257468be156 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- 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 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