98_uptime.pm 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. =for comment
  2. # $Id: 98_uptime.pm 14706 2017-07-13 17:22:27Z betateilchen $
  3. This script free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. any later version.
  7. The GNU General Public License can be found at
  8. http://www.gnu.org/copyleft/gpl.html.
  9. A copy is found in the textfile GPL.txt and important notices to the license
  10. from the author is found in LICENSE.txt distributed with these scripts.
  11. This script is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. =cut
  16. package main;
  17. use strict;
  18. use warnings;
  19. sub uptime_Initialize($$) {
  20. my %hash = (
  21. Fn => "CommandUptime",
  22. Hlp => ",show FHEM uptime",
  23. );
  24. $cmds{uptime} = \%hash;
  25. }
  26. sub CommandUptime($$) {
  27. my ($cl,$param) = @_;
  28. my @args = split("[ \t]+", $param);
  29. $args[0] = defined($args[0]) ? lc($args[0]) : "";
  30. my $diff = time - $fhem_started;
  31. return $diff if(lc($args[0]) eq 'raw');
  32. my ($d,$h,$m,$ret);
  33. ($d,$diff) = _upT_Div($diff,86400);
  34. ($h,$diff) = _upT_Div($diff,3600);
  35. ($m,$diff) = _upT_Div($diff,60);
  36. $ret = "";
  37. $ret .= "$d days, " if($d > 1);
  38. $ret .= "1 day, " if($d == 1);
  39. $ret .= sprintf("%02s:%02s:%02s", $h, $m, $diff);
  40. return $ret;
  41. }
  42. sub _upT_Div($$) {
  43. my ($p1,$p2) = @_;
  44. return (int($p1/$p2), $p1 % $p2);
  45. }
  46. 1;
  47. =pod
  48. =item command
  49. =item summary show FHEM uptime
  50. =item summary_DE zeigt FHEM Laufzeit an
  51. =begin html
  52. <a name="uptime"></a>
  53. <h3>uptime</h3>
  54. <ul>
  55. <code>uptime [raw]</code><br/>
  56. <br/>
  57. uptime shows FHEM uptime since last FHEM (re-)start.<br/>
  58. if called with optional parameter "raw" only seconds will be shown,<br/>
  59. without any fomatting.<br/>
  60. </ul>
  61. =end html
  62. =cut