My Changes so far.

This commit is contained in:
2019-02-02 21:57:21 +01:00
parent 111bc806b0
commit 6a331c1dff
+28 -11
View File
@@ -130,6 +130,10 @@ class Drive:
""" Return True if drive is in low power state, False otherwise. """ """ Return True if drive is in low power state, False otherwise. """
return (self.getState() in (Drive.DriveState.STANDBY, Drive.DriveState.SLEEPING)) return (self.getState() in (Drive.DriveState.STANDBY, Drive.DriveState.SLEEPING))
def isUnknown(self):
""" Return True if drive is in unknown state, False otherwise. """
return self.getState() == Drive.DriveState.UNKNOWN
def getTemperature(self): def getTemperature(self):
""" Get drive temperature in Celcius using either hddtemp or hdparm. """ """ Get drive temperature in Celcius using either hddtemp or hdparm. """
if not self.supports_hitachi_temp_query: if not self.supports_hitachi_temp_query:
@@ -156,7 +160,8 @@ class Drive:
temp_unit = drive_data[4] temp_unit = drive_data[4]
if temp_unit != "C": if temp_unit != "C":
raise RuntimeError("hddtemp daemon is not returning temp as Celsius") raise RuntimeError("hddtemp daemon is not returning temp as Celsius")
temp = int(drive_data[3]) else:
temp = int(drive_data[3])
found = True found = True
break break
if not found: if not found:
@@ -342,12 +347,12 @@ class Fan:
def setPwmValue(self, value): def setPwmValue(self, value):
""" Set fan PWM value. """ """ Set fan PWM value. """
assert(0 <= value <= 255) assert(0 <= value <= 255)
with open(self.enable_filepath, "r+t") as enable_file: # with open(self.enable_filepath, "r+t") as enable_file:
enabled_val = int(enable_file.read().strip()) # enabled_val = int(enable_file.read().strip())
if enabled_val != 1: # if enabled_val != 1:
self.logger.warning("%s was %u, setting it to 1", self.enable_filepath, enabled_val) # self.logger.warning("%s was %u, setting it to 1", self.enable_filepath, enabled_val)
enable_file.seek(0) # enable_file.seek(0)
enable_file.write("1") # enable_file.write("1")
self.logger.debug("Setting PWM value to %u" % (value)) self.logger.debug("Setting PWM value to %u" % (value))
with open(self.pwm_filepath, "wt") as pwm_file: with open(self.pwm_filepath, "wt") as pwm_file:
pwm_file.write("%u" % (value)) pwm_file.write("%u" % (value))
@@ -571,18 +576,28 @@ def main(drive_filepaths, fan_pwm_filepaths, fan_start_values, fan_stop_values,
# calc max drive temperature # calc max drive temperature
temps = [] temps = []
awakes = [] awakes = []
unknowns= []
for drive in drives: for drive in drives:
awake = not drive.isSleeping() awake = not drive.isSleeping()
unknown = drive.isUnknown()
awakes.append(awake) awakes.append(awake)
if awake or drive.supports_hitachi_temp_query: unknowns.append(unknown)
temps.append(drive.getTemperature()) if (awake and not unknown) or drive.supports_hitachi_temp_query:
else: try:
temps.append(drive.getTemperature())
except Exception as e:
logger.error("Could not get Temperature: " + str(e))
temps.append(35)
elif not awake:
logger.debug("Drive %s is in low power state, unable to query temperature" % (drive)) logger.debug("Drive %s is in low power state, unable to query temperature" % (drive))
else:
logger.debug("Drive %s is in unknown state, unable to query temperature" % (drive))
if temps: if temps:
temp = max(temps) temp = max(temps)
logger.info("Maximum drive temperature: %u C" % (temp)) logger.info("Maximum drive temperature: %u C" % (temp))
else: else:
assert(not any(awakes)) #assert(not any(awakes))
logger.info("All drives are in low power state") logger.info("All drives are in low power state")
if not any(awakes): if not any(awakes):
@@ -592,6 +607,8 @@ def main(drive_filepaths, fan_pwm_filepaths, fan_start_values, fan_stop_values,
if temps and (temp > min_temp): if temps and (temp > min_temp):
fan_speed_prct = 100 * (temp - min_temp) // (max_temp - min_temp) fan_speed_prct = 100 * (temp - min_temp) // (max_temp - min_temp)
fan_speed_prct = int(min(fan_speed_prct, 100)) fan_speed_prct = int(min(fan_speed_prct, 100))
elif any(unknowns):
fan_speed_prct = 6
else: else:
fan_speed_prct = 0 fan_speed_prct = 0
fan_speed_prct = max(fan_speed_prct, min_fan_speed_prct) fan_speed_prct = max(fan_speed_prct, min_fan_speed_prct)