@@ -81,27 +81,6 @@ class FanSpeedLUT:
8181 _fan_lut_t8 = UnaryStruct (0x5E , "<B" )
8282 _fan_lut_s8 = UnaryStruct (0x5F , "<B" )
8383
84- _lut_speed_setters = [
85- _fan_lut_s1 ,
86- _fan_lut_s2 ,
87- _fan_lut_s3 ,
88- _fan_lut_s4 ,
89- _fan_lut_s5 ,
90- _fan_lut_s6 ,
91- _fan_lut_s7 ,
92- _fan_lut_s8 ,
93- ]
94- _lut_temp_setters = [
95- _fan_lut_t1 ,
96- _fan_lut_t2 ,
97- _fan_lut_t3 ,
98- _fan_lut_t4 ,
99- _fan_lut_t5 ,
100- _fan_lut_t6 ,
101- _fan_lut_t7 ,
102- _fan_lut_t8 ,
103- ]
104-
10584 def __init__ (self , fan_obj ):
10685 self .emc_fan = fan_obj
10786 self .lut_values = {}
@@ -117,8 +96,10 @@ def __getitem__(self, index):
11796 def __setitem__ (self , index , value ):
11897 if not isinstance (index , int ):
11998 raise IndexError
99+ if value > 100.0 or value < 0 :
100+ raise AttributeError ("LUT values must be a fan speed from 0-100%" )
120101 self .lut_values [index ] = value
121- self ._set_lut (self . lut_values )
102+ self ._set_lut ()
122103
123104 def __repr__ (self ):
124105 """return the official string representation of the LUT"""
@@ -141,38 +122,33 @@ def __len__(self):
141122 # their correct spot within the lut table as pairs of set registers, sorted with the lowest
142123 # temperature first
143124
144- def _set_lut (self , lut_dict ):
125+ def _set_lut (self ):
145126 # Make sure we're not going to try to set more entries than we have slots
146- if len (lut_dict ) > 8 :
127+ if len (self . lut_values ) > 8 :
147128 raise AttributeError ("LUT can only contain a maximum of 8 items" )
148129
149130 # Verify that the value is a correct amount
150- for speed in lut_dict .values ():
131+ for speed in self . lut_values .values ():
151132 if speed > 100.0 or speed < 0 :
152133 raise AttributeError ("LUT values must be a fan speed from 0-100%" )
153134
154- # Copy to our internal representation
155- self .lut_values = {k : v for k , v in lut_dict .items ()}
135+ # Backup state
156136 current_mode = self .emc_fan .lut_enabled
157137
158138 # Disable the lut to allow it to be updated
159139 self .emc_fan .lut_enabled = False
160140
161141 # we want to assign the lowest temperature to the lowest LUT slot, so we sort the keys/temps
162142 # get and sort the new lut keys so that we can assign them in order
163- flat_list = []
164143 for idx , current_temp in enumerate (sorted (self .lut_values .keys ())):
165144 current_speed = _speed_to_lsb (self .lut_values [current_temp ])
166- getattr (self , "_fan_lut_t%d" % (idx + 1 )).__set__ (self , current_temp )
167- getattr (self , "_fan_lut_s%d" % (idx + 1 )).__set__ (self , current_speed )
168-
169- # self.emc_fan._lut_temp_setters[idx].__set__(self.emc_fan, current_temp)
170- # self.emc_fan._lut_speed_setters[idx].__set__(self.emc_fan, current_speed)
145+ setattr (self , "_fan_lut_t%d" % (idx + 1 ), current_temp )
146+ setattr (self , "_fan_lut_s%d" % (idx + 1 ), current_speed )
171147
172148 # Set the remaining LUT entries to the default (Temp/Speed = max value)
173149 for idx in range (8 )[len (self .lut_values ):]:
174- getattr (self , "_fan_lut_t%d" % (idx + 1 )). __set__ ( self , MAX_LUT_TEMP )
175- getattr (self , "_fan_lut_s%d" % (idx + 1 )). __set__ ( self , MAX_LUT_SPEED )
150+ setattr (self , "_fan_lut_t%d" % (idx + 1 ), MAX_LUT_TEMP )
151+ setattr (self , "_fan_lut_s%d" % (idx + 1 ), MAX_LUT_SPEED )
176152 self .emc_fan .lut_enabled = current_mode
177153
178154
0 commit comments