Module: LmSensors::Feature

Defined in:
lib/lmsensors/features/fan.rb,
lib/lmsensors/features/beep.rb,
lib/lmsensors/features/temp.rb,
lib/lmsensors/features/alarm.rb,
lib/lmsensors/features/power.rb,
lib/lmsensors/features/current.rb,
lib/lmsensors/features/voltage.rb,
lib/lmsensors/features/humidity.rb,
lib/lmsensors/features/abs_feature.rb

Overview

Feature module is used to handle the formatting and inheritance of various feature types.

Defined Under Namespace

Classes: Alarm, Beep, Current, Fan, GenFeature, Humidity, Power, Temp, Voltage

Constant Summary collapse

FMT_FAN =

Default formatting proc for the X_FAN subtype.

lambda do |feature|
  # Formatted structure
  unit = feature.unit
  out = feature.feature
  tmp = { input: nil, max: nil }
  
  # Format the outputs
  # Strip each, in case the unit is empty
  feature.subfs.values.map do |v|
    if v[:value] then
      case v[:subtype]
      when SSF_FAN_INPUT
        tmp[:input] = v[:value]
        out[:input] = "#{v[:value]} #{unit}".strip
      when SSF_FAN_MAX
        tmp[:max] = v[:value]
        out[:max] = "#{v[:value]} #{unit}".strip
      when SSF_FAN_MIN
        out[:min] = "#{v[:value]} #{unit}".strip
      end
    end
  end # End value mapper for fan
  
  # Calculate the percentage of max speed of fan
  if tmp[:max] and tmp[:input] then
    perc = ((tmp[:input].to_f / tmp[:max]) * 100).round(2)
    out[:percent] = "#{perc}%".strip
  end # Only if both are present
  out
end
FMT_BEEP =

Default formatting proc for BEEP types

lambda do |feature|
  unit = feature.unit
  out = feature.feature
  # Don't need to return unit, as it is proc for this feature type
  out.delete(:unit)
  
  # Format the outputs
  feature.subfs.map do |k, v|
    if v[:value] then out[k] = unit.call(v[:value]) end
  end # End value mapper for beep
  out
end
FMT_TEMP =

Default temperature formatting proc

lambda do |feature|
  # Formatted structure
  unit = feature.unit
  out = feature.feature
  tmp = { input: nil, max: nil }
  
  # Format the outputs
  # Strip each, in case the unit is empty
  feature.subfs.values.map do |v|
    if v[:value] then
      case v[:subtype]
      when SSF_TEMP_INPUT
        tmp[:input] = v[:value]
        out[:input] = "#{v[:value].round(2)} #{unit}".strip
      when SSF_TEMP_MAX
        if v[:value] != 0 then
          tmp[:max] = v[:value]
          out[:max] = "#{v[:value].round(2)} #{unit}".strip
        end
      when SSF_TEMP_CRIT
        if v[:value] != 0 then
          tmp[:crit] = v[:value]
          out[:crit] = "#{v[:value].round(2)} #{unit}".strip
        end
      when SSF_TEMP_MIN
        if v[:value] != 0 then out[:min] = "#{v[:value].round(2)} #{unit}".strip end
      end
    end
  end # End value mapper for fan
  
  # Set the check symbols
  # Symbol for input, symbol for limit
  syi, syl = :input, :max
  
  # Calculate the percentage of voltage max
  # :percent is against max, for voltage
  if tmp[syl] and tmp[syi] then
    perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
    out[:percent] = "#{perc}%".strip
  end # Only if both are present
  
  syl = :crit
  
  # Calculate the percentage of voltage crit
  if tmp[syl] and tmp[syi] then
    perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
    out[:percent_crit] = "#{perc}%".strip
  end # Only if both are present
  out
end
FMT_ALARM =

Default formatting proc for ALARM types

lambda do |feature|
  # Formatted structure
  unit = feature.unit
  out = feature.feature
  # Don't need to return unit, as it is proc for this feature type
  out.delete(:unit)
  
  # Format the outputs
  feature.subfs.map do |k, v|
    # Only check is alarm is enabled.
    # The other option SSF_INTRUDE_BEEP
    # is not formatted in the normal sensor program
    if v[:value] and (v[:subtype] == SSF_INTRUDE_ALARM) then
      out[k] = unit.call(v[:value]) end
  end # End value mapper for alarm
  out
end
FMT_POWER =

Default power formatting proc

lambda do |feature|
  # Formatted structure
  unit = feature.unit
  out = feature.feature
  tmp = { input: nil, max: nil }
  
  # Format the outputs
  # Strip each, in case the unit is empty
  feature.subfs.values.map do |v|
    if v[:value] then
      case v[:subtype]
      when SSF_POWER_INPUT
        out[:input] = "#{v[:value].round(2)} #{unit}".strip
      when SSF_POWER_AVG
        tmp[:average] = v[:value]
        out[:average] = "#{v[:value].round(2)} #{unit}".strip
      when SSF_POWER_MAX
        tmp[:max] = v[:value]
        out[:max] = "#{v[:value].round(2)} #{unit}".strip
      when SSF_POWER_CRIT
        tmp[:crit] = v[:value]
        out[:crit] = "#{v[:value].round(2)} #{unit}".strip
      when SSF_POWER_CAP
        tmp[:cap] = v[:value]
        out[:cap] = "#{v[:value].round(2)} #{unit}".strip
      when SSF_POWER_MIN
        out[:min] = "#{v[:value].round(2)} #{unit}".strip
      end
    end
  end # End value mapper for fan
  
  # Set the check symbols
  # Symbol for input, symbol for limit
  syi, syl = :average, :cap
  
  # Calculate the percentage of power cap
  # :percent is against cap for power, and it is
  # in respect to :average, not :input, as not all
  # sensors will use input for power.
  if tmp[syl] and tmp[syi] then
    perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
    out[:percent] = "#{perc}%".strip
  end # Only if both are present
  
  syl = :max
  
  # Calculate the percentage of power max
  if tmp[syl] and tmp[syi] then
    perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
    out[:percent_max] = "#{perc}%".strip
  end # Only if both are present
  
  syl = :crit
  
  # Calculate the percentage of power crit
  if tmp[syl] and tmp[syi] then
    perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
    out[:percent_crit] = "#{perc}%".strip
  end # Only if both are present
  out
end
FMT_CURR =

Default current formatting proc

lambda do |feature|
  # Formatted structure
  unit = feature.unit
  out = feature.feature
  tmp = { input: nil, max: nil }
  
  # Format the outputs
  # Strip each, in case the unit is empty
  feature.subfs.values.map do |v|
    if v[:value] then
      case v[:subtype]
      when SSF_CURR_INPUT
        tmp[:input] = v[:value]
        out[:input] = "#{v[:value].round(2)} #{unit}".strip
      when SSF_CURR_MAX
        if v[:value] != 0 then
          tmp[:max] = v[:value]
          out[:max] = "#{v[:value].round(2)} #{unit}".strip
        end
      when SSF_CURR_CRIT
        if v[:value] != 0 then
          tmp[:crit] = v[:value]
          out[:crit] = "#{v[:value].round(2)} #{unit}".strip
        end
      when SSF_CURR_MIN
        if v[:value] != 0 then out[:min] = "#{v[:value].round(2)} #{unit}".strip end
      end
    end
  end # End value mapper for fan
  
  # Set the check symbols
  # Symbol for input, symbol for limit
  syi, syl = :input, :max
  
  # Calculate the percentage of current max
  # :percent is against max, for current
  if tmp[syl] and tmp[syi] then
    perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
    out[:percent] = "#{perc}%".strip
  end # Only if both are present
  
  syl = :crit
  
  # Calculate the percentage of current crit
  if tmp[syl] and tmp[syi] then
    perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
    out[:percent_crit] = "#{perc}%".strip
  end # Only if both are present
  out
end
FMT_VOLTAGE =

Default voltage formatting proc

lambda do |feature|
  # Formatted structure
  unit = feature.unit
  out = feature.feature
  tmp = { input: nil, max: nil }
  
  # Format the outputs
  # Strip each, in case the unit is empty
  feature.subfs.values.map do |v|
    if v[:value] then 
      case v[:subtype]
      when SSF_IN_INPUT
        tmp[:input] = v[:value]
        out[:input] = "#{v[:value].round(2)} #{unit}".strip
      when SSF_IN_MAX
        if v[:value] != 0 then
          tmp[:max] = v[:value]
          out[:max] = "#{v[:value].round(2)} #{unit}".strip
        end
      when SSF_IN_CRIT
        if v[:value] != 0 then
          tmp[:crit] = v[:value]
          out[:crit] = "#{v[:value].round(2)} #{unit}".strip
        end
      when SSF_IN_MIN
        if v[:value] != 0 then out[:min] = "#{v[:value].round(2)} #{unit}".strip end
      end
    end
  end # End value mapper for fan
  
  # Set the check symbols
  # Symbol for input, symbol for limit
  syi, syl = :input, :max
  
  # Calculate the percentage of voltage max
  # :percent is against max, for voltage
  if tmp[syl] and tmp[syi] then
    perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
    out[:percent] = "#{perc}%".strip
  end # Only if both are present
  
  syl = :crit
  
  # Calculate the percentage of voltage crit
  if tmp[syl] and tmp[syi] then
    perc = ((tmp[syi].to_f / tmp[syl]) * 100).round(2)
    out[:percent_crit] = "#{perc}%".strip
  end # Only if both are present
  out
end
FMT_HUMIDITY =

Default humidity formatting proc.

I cannot test this on any of my systems, so it might need to be overridden.

lambda do |feature|
  # Formatted structure
  unit = feature.unit
  out = feature.feature
  
  # Format the outputs
  feature.subfs.map do |k, v|
    if v[:value] then out[k] = "#{v[:value].round(2)}#{unit}" end
  end # End value mapper for humidity
  out
end
BASE_FMT =

Base formatting for anything else. This pretty much just converts a general feature object into a hash, so it can be indexed in post-processing.

lambda do |feature|
  # Attach the main feature name and unit type
  fstruct = { name: feature.name, type: feature.type, unit: feature.unit }
  # Merge the subfeatures
  fstruct.merge(feature.subfs)
end