Module: Rsensors::Notification

Defined in:
lib/rsensors.rb

Overview

Uses system notification to notify of current temperature. Currently works/tested only on Linux

Class Method Summary collapse

Class Method Details

.create_notificationObject



153
154
155
156
157
158
159
# File 'lib/rsensors.rb', line 153

def self.create_notification()
 return Libnotify.new(
      summary: 'Temperature',
      timeout: 2.5,
      append: true
      )
end

.notify(max_temp_cpu = 77, max_temp_hd = 46) ⇒ Object

optional max_temperature CPU hard disk values



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/rsensors.rb', line 178

def self.notify(max_temp_cpu = 77, max_temp_hd = 46) # optional max_temperature CPU hard disk values
  # change to multiple assignation
  temp, temp2, temp4, temp_hd, n = notifyInit
  n.urgency = Sensor.maxTemperatureHd > max_temp_hd ? :critical : :normal # temp_hd[1] store number
  if temp2 && temp4
   n.body = text4cores(temp2, temp4, temp_hd) #code climate refactor
   n.urgency = temp2 > max_temp_cpu ? :critical : :normal
   n.urgency = temp4 > max_temp_cpu ? :critical : :normal
  elsif temp
    n.body = text1cpu(temp, temp_hd)
    n.urgency = temp > max_temp ? :critical : :normal
  else
     n.body = textHdOnly(temp_hd) 
  end
	  notifyOutput(n)
  exit (0)
end

.notifyInitObject



175
176
177
# File 'lib/rsensors.rb', line 175

def self.notifyInit
  return Sensor.temperature1, Sensor.temperature2, Sensor.temperature4, Sensor.temperature_hd, create_notification()
end

.notifyOutput(n) ⇒ Object



169
170
171
172
173
174
# File 'lib/rsensors.rb', line 169

def self.notifyOutput(n)
	  puts n.body #sentence # check exit, now nothing on console
  puts "URGENT!" if n.urgency == :critical
  puts "Normal temperatures" if n.urgency == :normal
  n.show!
end

.text1cpu(t, t_hd) ⇒ Object



163
164
165
# File 'lib/rsensors.rb', line 163

def self.text1cpu(t, t_hd)
  return "Your computer's temperature is now: #{t} °C\n" + t_hd
end

.text4cores(t2, t4, t_hd) ⇒ Object



160
161
162
# File 'lib/rsensors.rb', line 160

def self.text4cores(t2, t4, t_hd)
  return "Your computer's temperature is now:\n Core 2 #{t2} °C, Core 4: #{t4} °C\n Average temperature: #{(t4+t2)/2} °C\n" + t_hd
end

.textHdOnly(t_hd) ⇒ Object



166
167
168
# File 'lib/rsensors.rb', line 166

def self.textHdOnly(t_hd)
  return "Your computer's temperature is currently unknown by this app, sorry. Wait for a brilliant update. Peace\n" + temp_hd
end