1
1
import robot .api .logger
2
2
from robot .api .deco import keyword
3
- from osfv .libs .rte import RTE
3
+ from osfv .libs .rte import RTE , UnsupportedDUTModel
4
4
from osfv .libs .snipeit_api import SnipeIT
5
5
6
6
7
+ model_dict = {
8
+ "minnowboard_turbot" : "MinnowBoard Turbot B41" ,
9
+ "msi-pro-z690-a-ddr4" : "MSI PRO Z690-A DDR4" ,
10
+ "msi-pro-z690-a-ddr5" : "MSI PRO Z690-A DDR5" ,
11
+ "pcengines-apu2" : "APU2" ,
12
+ "pcengines-apu3" : "APU3" ,
13
+ "pcengines-apu4" : "APU4" ,
14
+ "pcengines-apu6" : "APU6" ,
15
+ "protectli-v1210" : "V1210" ,
16
+ "protectli-v1410" : "V1410" ,
17
+ "protectli-v1610" : "V1610" ,
18
+ "protectli-vp2410" : "VP2410" ,
19
+ "protectli-vp2420" : "VP2420" ,
20
+ "protectli-vp4630" : "VP4630" ,
21
+ "protectli-vp4650" : "VP4650" ,
22
+ "protectli-vp4670" : "VP4670" ,
23
+ "protectli-vp6650" : "VP6650" ,
24
+ "protectli-vp6670" : "VP6670"
25
+ }
26
+
27
+
7
28
class RobotRTE :
8
- def __init__ (self , rte_ip ):
9
- snipeit_api = SnipeIT ()
10
- asset_id = snipeit_api .get_asset_id_by_rte_ip (rte_ip )
11
- status , dut_model_name = snipeit_api .get_asset_model_name (asset_id )
12
- if status :
13
- robot .api .logger .info (f"DUT model retrieved from snipeit: { dut_model_name } " )
29
+ def __init__ (self , rte_ip , snipeit : bool , sonoff_ip = None , config = None ):
30
+ if snipeit :
31
+ snipeit_api = SnipeIT ()
32
+ asset_id = snipeit_api .get_asset_id_by_rte_ip (rte_ip )
33
+ status , dut_model_name = snipeit_api .get_asset_model_name (asset_id )
34
+ if status :
35
+ robot .api .logger .info (
36
+ f"DUT model retrieved from snipeit: { dut_model_name } " )
37
+ else :
38
+ raise AssertionError (
39
+ f"Failed to retrieve model name from Snipe-IT. Check again arguments, or try providing model manually."
40
+ )
41
+ self .rte = RTE (rte_ip , dut_model_name , snipeit_api )
14
42
else :
15
- raise AssertionError (
16
- f"Failed to retrieve model name from Snipe-IT. Check again arguments, or try providing model manually."
17
- )
18
- self .rte = RTE (rte_ip , dut_model_name , snipeit_api )
43
+ self .rte = RTE (rte_ip , self .cli_model_from_osfv (config ), sonoff_ip = sonoff_ip )
44
+
45
+ def cli_model_from_osfv (self , osfv_model ):
46
+ """
47
+ Get osfv_cli model name from OSFV repo config name
48
+ """
49
+ if not osfv_model :
50
+ raise TypeError (f"Expected a value for 'config', but got { osfv_model } " )
51
+ cli_model = model_dict .get (osfv_model )
52
+ if not cli_model :
53
+ raise UnsupportedDUTModel (f"The { osfv_model } model has no counterpart in osfv_cli" )
54
+ return cli_model
19
55
20
56
@keyword (types = None )
21
57
def rte_flash_read (self , fw_file ):
@@ -37,7 +73,7 @@ def rte_flash_write(self, fw_file):
37
73
def rte_flash_probe (self ):
38
74
robot .api .logger .info (f"Probing flash..." )
39
75
self .rte .flash_probe ()
40
-
76
+
41
77
@keyword (types = None )
42
78
def rte_flash_erase (self ):
43
79
robot .api .logger .info (f"Erasing DUT flash..." )
@@ -54,14 +90,14 @@ def rte_relay_toggle(self):
54
90
self .rte .relay_set (new_state_str )
55
91
state = self .rte .relay_get ()
56
92
robot .api .logger .info (f"Relay state toggled. New state: { state } " )
57
-
93
+
58
94
@keyword (types = None )
59
95
def rte_relay_set (self , state ):
60
96
self .rte .relay_set (state )
61
97
state = self .rte .relay_get ()
62
98
robot .api .logger .info (f"Relay state set to { state } " )
63
99
return state
64
-
100
+
65
101
@keyword (types = None )
66
102
def rte_relay_get (self ):
67
103
state = self .rte .relay_get ()
@@ -72,23 +108,23 @@ def rte_relay_get(self):
72
108
def rte_power_on (self , time = 1 ):
73
109
robot .api .logger .info (f"Powering on..." )
74
110
self .rte .power_on (time )
75
-
111
+
76
112
@keyword (types = None )
77
113
def rte_power_off (self , time = 6 ):
78
114
robot .api .logger .info (f"Powering off..." )
79
115
self .rte .power_off (time )
80
-
116
+
81
117
@keyword (types = None )
82
118
def rte_reset (self , time = 1 ):
83
119
robot .api .logger .info (f"Pressing reset button..." )
84
120
self .rte .reset (time )
85
-
121
+
86
122
@keyword (types = None )
87
123
def rte_gpio_get (self , gpio_no ):
88
124
state = self .rte .gpio_get (int (gpio_no ))
89
125
robot .api .logger .info (f"GPIO { gpio_no } state: { state } " )
90
126
return state
91
-
127
+
92
128
@keyword (types = None )
93
129
def rte_gpio_set (self , gpio_no , state ):
94
130
self .rte .gpio_set (int (gpio_no ), state )
0 commit comments