@@ -81,27 +81,6 @@ class FanSpeedLUT:
81
81
_fan_lut_t8 = UnaryStruct (0x5E , "<B" )
82
82
_fan_lut_s8 = UnaryStruct (0x5F , "<B" )
83
83
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
-
105
84
def __init__ (self , fan_obj ):
106
85
self .emc_fan = fan_obj
107
86
self .lut_values = {}
@@ -117,8 +96,10 @@ def __getitem__(self, index):
117
96
def __setitem__ (self , index , value ):
118
97
if not isinstance (index , int ):
119
98
raise IndexError
99
+ if value > 100.0 or value < 0 :
100
+ raise AttributeError ("LUT values must be a fan speed from 0-100%" )
120
101
self .lut_values [index ] = value
121
- self ._set_lut (self . lut_values )
102
+ self ._set_lut ()
122
103
123
104
def __repr__ (self ):
124
105
"""return the official string representation of the LUT"""
@@ -141,38 +122,33 @@ def __len__(self):
141
122
# their correct spot within the lut table as pairs of set registers, sorted with the lowest
142
123
# temperature first
143
124
144
- def _set_lut (self , lut_dict ):
125
+ def _set_lut (self ):
145
126
# 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 :
147
128
raise AttributeError ("LUT can only contain a maximum of 8 items" )
148
129
149
130
# Verify that the value is a correct amount
150
- for speed in lut_dict .values ():
131
+ for speed in self . lut_values .values ():
151
132
if speed > 100.0 or speed < 0 :
152
133
raise AttributeError ("LUT values must be a fan speed from 0-100%" )
153
134
154
- # Copy to our internal representation
155
- self .lut_values = {k : v for k , v in lut_dict .items ()}
135
+ # Backup state
156
136
current_mode = self .emc_fan .lut_enabled
157
137
158
138
# Disable the lut to allow it to be updated
159
139
self .emc_fan .lut_enabled = False
160
140
161
141
# we want to assign the lowest temperature to the lowest LUT slot, so we sort the keys/temps
162
142
# get and sort the new lut keys so that we can assign them in order
163
- flat_list = []
164
143
for idx , current_temp in enumerate (sorted (self .lut_values .keys ())):
165
144
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 )
171
147
172
148
# Set the remaining LUT entries to the default (Temp/Speed = max value)
173
149
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 )
176
152
self .emc_fan .lut_enabled = current_mode
177
153
178
154
0 commit comments