| 1 | -- hard drive temperatures widget type using hddtemp daemon |
| 2 | -- Copyright (C) 2010 Adrian C. <[email protected]> |
| 3 | -- Copyright (C) 2017 mutlusun <[email protected]> |
| 4 | -- Copyright (C) 2019 Nguyễn Gia Phong <[email protected]m> |
| 5 | -- |
| 6 | -- This file is part of Vicious. |
| 7 | -- |
| 8 | -- Vicious is free software: you can redistribute it and/or modify |
| 9 | -- it under the terms of the GNU General Public License as |
| 10 | -- published by the Free Software Foundation, either version 2 of the |
| 11 | -- License, or (at your option) any later version. |
| 12 | -- |
| 13 | -- Vicious is distributed in the hope that it will be useful, |
| 14 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | -- GNU General Public License for more details. |
| 17 | -- |
| 18 | -- You should have received a copy of the GNU General Public License |
| 19 | -- along with Vicious. If not, see <https://www.gnu.org/licenses/>. |
| 20 | |
| 21 | -- {{{ Grab environment |
| 22 | local tonumber = tonumber |
| 23 | |
| 24 | local helpers = require"vicious.helpers" |
| 25 | local spawn = require"vicious.spawn" |
| 26 | -- }}} |
| 27 | |
| 28 | -- Hddtemp: provides hard drive temperatures using the hddtemp daemon |
| 29 | -- vicious.widgets.hddtemp |
| 30 | return helpers.setasyncall{ |
| 31 | async = function(format, warg, callback) |
| 32 | if warg == nil then warg = 7634 end -- fallback to default hddtemp port |
| 33 | local hdd_temp = {} -- get info from the hddtemp daemon |
| 34 | spawn.with_line_callback_with_shell( |
| 35 | "echo | curl -fs telnet://127.0.0.1:" .. warg, |
| 36 | { stdout = function (line) |
| 37 | for d, t in line:gmatch"|([%/%w]+)|.-|(%d+)|[CF]|" do |
| 38 | hdd_temp["{"..d.."}"] = tonumber(t) |
| 39 | end |
| 40 | end, |
| 41 | output_done = function () callback(hdd_temp) end }) |
| 42 | end } |