local temperature = {}

local DEFAULT_SIGNAL = "temperature::value"

-- 'temp' get cpu temperature of motherboard
local temp = [[ cat /sys/class/thermal/thermal_zone0/temp ]]

--- callback: function(temperature)
function temperature.get(callback)
  awful.spawn.easy_async_with_shell(temp, function (out)
    callback(tonumber(out))
  end)
end

function temperature.emit(name)
	temperature.get(function(...)
		awesome.emit_signal(name or DEFAULT_SIGNAL, ...)
	end)
end

function temperature.register_signal(signal_name, update_interval)
	gears.timer {
		timeout = update_interval or 5,
		call_now = true,
		autostart = true,
		callback = function() temperature.emit(signal_name) end
	}
end

return temperature
