@@ -127,8 +127,7 @@ def __repr__(self):
127
127
def __str__ (self ):
128
128
"""return the official string representation of the LUT"""
129
129
value_strs = []
130
- lut_keys = list (self .lut_values .keys ())
131
- lut_keys .sort ()
130
+ lut_keys = list (sorted (self .lut_values .keys ()))
132
131
for temp in lut_keys :
133
132
fan_drive = self .lut_values [temp ]
134
133
value_strs .append ("%d deg C => %.1f%% duty cycle" % (temp , fan_drive ))
@@ -143,31 +142,26 @@ def __len__(self):
143
142
# temperature first
144
143
145
144
def _set_lut (self , lut_dict ):
146
- lut_keys = list (lut_dict .keys ())
147
- lut_size = len (lut_dict )
148
145
# Make sure we're not going to try to set more entries than we have slots
149
- if lut_size > 8 :
146
+ if len ( lut_dict ) > 8 :
150
147
raise AttributeError ("LUT can only contain a maximum of 8 items" )
151
148
152
- # we want to assign the lowest temperature to the lowest LUT slot, so we sort the keys/temps
153
- for k in lut_keys :
154
- # Verify that the value is a correct amount
155
- lut_value = lut_dict [k ]
156
- if lut_value > 100.0 or lut_value < 0 :
149
+ # Verify that the value is a correct amount
150
+ for speed in lut_dict .values ():
151
+ if speed > 100.0 or speed < 0 :
157
152
raise AttributeError ("LUT values must be a fan speed from 0-100%" )
158
153
159
- # add the current temp/speed to our internal representation
160
- self . lut_values [ k ] = lut_value
154
+ # Copy to our internal representation
155
+ self . lut_values = { k : v for k , v in lut_dict . items ()}
161
156
current_mode = self .emc_fan .lut_enabled
162
157
163
158
# Disable the lut to allow it to be updated
164
159
self .emc_fan .lut_enabled = False
165
160
161
+ # we want to assign the lowest temperature to the lowest LUT slot, so we sort the keys/temps
166
162
# get and sort the new lut keys so that we can assign them in order
167
- lut_keys = list (self .lut_values .keys ())
168
- lut_keys .sort ()
169
- for idx in range (lut_size ):
170
- current_temp = lut_keys [idx ]
163
+ flat_list = []
164
+ for idx , current_temp in enumerate (sorted (self .lut_values .keys ())):
171
165
current_speed = _speed_to_lsb (self .lut_values [current_temp ])
172
166
getattr (self , "_fan_lut_t%d" % (idx + 1 )).__set__ (self , current_temp )
173
167
getattr (self , "_fan_lut_s%d" % (idx + 1 )).__set__ (self , current_speed )
@@ -176,7 +170,7 @@ def _set_lut(self, lut_dict):
176
170
# self.emc_fan._lut_speed_setters[idx].__set__(self.emc_fan, current_speed)
177
171
178
172
# Set the remaining LUT entries to the default (Temp/Speed = max value)
179
- for idx in range (8 )[lut_size :]:
173
+ for idx in range (8 )[len ( self . lut_values ) :]:
180
174
getattr (self , "_fan_lut_t%d" % (idx + 1 )).__set__ (self , MAX_LUT_TEMP )
181
175
getattr (self , "_fan_lut_s%d" % (idx + 1 )).__set__ (self , MAX_LUT_SPEED )
182
176
self .emc_fan .lut_enabled = current_mode
0 commit comments