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,16 @@ 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 (
39
+ f"Missing value for 'sonoff_ip' or Sonoff not found in SnipeIT" )
40
+ )
38
41
39
42
def load_model_data (self ):
40
43
file_path = os .path .join (files ("osfv" ), "models" , f"{ self .dut_model } .yml" )
@@ -97,26 +100,6 @@ def load_model_data(self):
97
100
# Return the loaded data
98
101
return data
99
102
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
103
def power_on (self , sleep = 1 ):
121
104
self .gpio_set (self .GPIO_POWER , "low" , sleep )
122
105
time .sleep (sleep )
@@ -322,6 +305,12 @@ def flash_write(self, write_file):
322
305
if self .dut_data ["reset_cmos" ] == True :
323
306
self .reset_cmos ()
324
307
308
+ def sonoff_sanity_check (self ):
309
+ """
310
+ Verify that if DUT is powered by Sonoff, Sonoff IP is not None
311
+ """
312
+ return not self .dut_data ["pwr_ctrl" ]["sonoff" ] or self .sonoff .sonoff_ip
313
+
325
314
326
315
class IncompleteModelData (Exception ):
327
316
pass
@@ -334,6 +323,5 @@ class UnsupportedDUTModel(Exception):
334
323
class SPIWrongVoltage (Exception ):
335
324
pass
336
325
337
-
338
326
class SonoffNotFound (Exception ):
339
327
pass
0 commit comments