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" )
@@ -97,26 +99,6 @@ def load_model_data(self):
97
99
# Return the loaded data
98
100
return data
99
101
100
- def init_sonoff (self , init_sonoff_ip ):
101
- sonoff_ip = ""
102
- sonoff = None
103
-
104
- if self .dut_data ["pwr_ctrl" ]["sonoff" ] is True :
105
- if not self .snipeit_api :
106
- if not init_sonoff_ip :
107
- raise TypeError (
108
- f"Expected a value for 'sonoff_ip', but got None"
109
- )
110
- sonoff_ip = init_sonoff_ip
111
- else :
112
- sonoff_ip = self .snipeit_api .get_sonoff_ip_by_rte_ip (self .rte_ip )
113
- if not sonoff_ip :
114
- raise SonoffNotFound (
115
- exit (f"Sonoff IP not found in SnipeIT for RTE: { self .rte_ip } " )
116
- )
117
- sonoff = SonoffDevice (sonoff_ip )
118
- return sonoff , sonoff_ip
119
-
120
102
def power_on (self , sleep = 1 ):
121
103
self .gpio_set (self .GPIO_POWER , "low" , sleep )
122
104
time .sleep (sleep )
@@ -322,6 +304,12 @@ def flash_write(self, write_file):
322
304
if self .dut_data ["reset_cmos" ] == True :
323
305
self .reset_cmos ()
324
306
307
+ def sonoff_sanity_check (self ):
308
+ """
309
+ Verify that if DUT is powered by Sonoff, Sonoff IP is not None
310
+ """
311
+ return not self .dut_data ["pwr_ctrl" ]["sonoff" ] or self .sonoff .sonoff_ip
312
+
325
313
326
314
class IncompleteModelData (Exception ):
327
315
pass
0 commit comments