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