local wibox = require("wibox")
local widgets_util = require("util.widgets")
local gears = require("gears")

local temperature = {}

function temperature:set_file(file)
	self._private.file = file
	self._timer:emit_signal("timeout")
end

function linux_update(widget)
	local tempf = io.open(widget._private.file)
	if tempf then
		local temp = tempf:read() / 1000
		tempf:close()
		widget:set_text(string.format(widget._private.format, temp))
	else
		widget:set_text("err")
	end
end

-- return correct widget for os
if osname == "Linux" then
	return function(file)
		local w = wibox.widget.textbox()
		gears.table.crush(w, temperature, true)
		w._private.file = file or ""
		w._private.format = "%d°"
		widgets_util.add_timer(w, linux_update, 5)
		--return widgets.watchfn(linux.temperature, 5)
		return w
	end
end

return wibox.widget.textbox("unsupported os")