5
5
import yaml
6
6
from importlib_resources import files
7
7
from osfv .libs .rtectrl_api import rtectrl
8
- from osfv .libs .sonoff_api import SonoffDevice
9
8
from voluptuous import Any , Optional , Required , Schema
10
9
11
10
@@ -29,12 +28,15 @@ class RTE(rtectrl):
29
28
PROGRAMMER_CH341A = "ch341a_spi"
30
29
FLASHROM_CMD = "flashrom -p {programmer} {args}"
31
30
32
- def __init__ (self , rte_ip , dut_model , snipeit_api = None , sonoff_ip = None ):
31
+ def __init__ (self , rte_ip , dut_model , sonoff ):
33
32
self .rte_ip = rte_ip
34
33
self .dut_model = dut_model
35
34
self .dut_data = self .load_model_data ()
36
- self .snipeit_api = snipeit_api
37
- self .sonoff , self .sonoff_ip = self .init_sonoff (sonoff_ip )
35
+ self .sonoff = sonoff
36
+ if not self .sonoff_sanity_check ():
37
+ raise SonoffNotFound (
38
+ exit (f"Missing value for 'sonoff_ip' or Sonoff not found in SnipeIT" )
39
+ )
38
40
39
41
def load_model_data (self ):
40
42
file_path = os .path .join (files ("osfv" ), "models" , f"{ self .dut_model } .yml" )
@@ -98,26 +100,6 @@ def load_model_data(self):
98
100
# Return the loaded data
99
101
return data
100
102
101
- def init_sonoff (self , init_sonoff_ip ):
102
- sonoff_ip = ""
103
- sonoff = None
104
-
105
- if self .dut_data ["pwr_ctrl" ]["sonoff" ] is True :
106
- if not self .snipeit_api :
107
- if not init_sonoff_ip :
108
- raise TypeError (
109
- f"Expected a value for 'sonoff_ip', but got None"
110
- )
111
- sonoff_ip = init_sonoff_ip
112
- else :
113
- sonoff_ip = self .snipeit_api .get_sonoff_ip_by_rte_ip (self .rte_ip )
114
- if not sonoff_ip :
115
- raise SonoffNotFound (
116
- exit (f"Sonoff IP not found in SnipeIT for RTE: { self .rte_ip } " )
117
- )
118
- sonoff = SonoffDevice (sonoff_ip )
119
- return sonoff , sonoff_ip
120
-
121
103
def power_on (self , sleep = 1 ):
122
104
self .gpio_set (self .GPIO_POWER , "low" , sleep )
123
105
time .sleep (sleep )
@@ -320,6 +302,12 @@ def flash_write(self, write_file):
320
302
if self .dut_data ["reset_cmos" ] == True :
321
303
self .reset_cmos ()
322
304
305
+ def sonoff_sanity_check (self ):
306
+ """
307
+ Verify that if DUT is powered by Sonoff, Sonoff IP is not None
308
+ """
309
+ return not self .dut_data ["pwr_ctrl" ]["sonoff" ] or self .sonoff .sonoff_ip
310
+
323
311
324
312
class IncompleteModelData (Exception ):
325
313
pass
0 commit comments