summaryrefslogtreecommitdiff
path: root/validation/validlib/non_spc300.py
blob: eb36a9b67d42818f38bb048c3426767d62c2995b (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-

"""Module allowing to command and control a plug which is not an SPC300"""

import time

import power_strip

config = {
    "plugs":
        {
        #(Power strip index,
        # Power plug index,
        # Identifier (this parameter is optional and is needed only if there
        # are several plugs connected to the same power plug via another
        # power strip):
        #(MAC address,
        # device model,
        # device version)
        (1, 6): ("00:1c:23:1e:a0:7a", "AT6400", "1.0.2"),
        (1, 7, "plug_1"): ("00:1c:23:1e:a0:7b", "AT6400", "1.0.2"),
        (1, 8, "plug_2"): ("00:1c:23:1e:a0:7c", "AT6400", "1.0.2")
        }
    }

def update_config(new_config):
    """Update the configuration"""
    global config
    config = new_config

def get_mac_address(key):
    """Gives the MAC address corresponding to a power strip key"""
    return config["plugs"][key][0]

def get_model(key):
    """Gives the model corresponding to a power strip key"""
    return config["plugs"][key][1]

def get_version(key):
    """Gives the version corresponding to a power strip key"""
    print config["plugs"][key]
    return config["plugs"][key][2]

def switch_on(key):
    print "Starting the plug", key, "...{"
    power_plug_key = (key[0], key[1])
    power_strip.switch("off", power_plug_key)
    power_strip.switch("on", power_plug_key)
    duration = 10
    print "Waiting", duration, "seconds..."
    time.sleep(duration)
    print "}"