2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-19 12:46:03 +00:00

power supply information readings (ac, usb, battery) added

git-svn-id: https://svn.fhem.de/fhem/trunk@6364 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
hexenmeister 2014-08-06 13:45:40 +00:00
parent 448a479d5a
commit c1012c1325

View File

@ -169,6 +169,35 @@ SYSMON_updateCurrentReadingsMap($) {
$rMap->{+CPU_TEMP} = "CPU temperature";
$rMap->{"cpu_temp_avg"} = "Average CPU temperature";
}
if(SYSMON_isSysPowerAc($hash)) {
#$rMap->{"power_ac_online"} = "AC-Versorgung Status";
#$rMap->{"power_ac_present"} = "AC-Versorgung vorhanden";
#$rMap->{"power_ac_current"} = "AC-Versorgung Strom";
#$rMap->{"power_ac_voltage"} = "AC-Versorgung Spannung";
$rMap->{"power_ac_stat"} = "AC-Versorgung Info";
$rMap->{"power_ac_text"} = "AC-Versorgung Info";
}
if(SYSMON_isSysPowerUsb($hash)) {
#$rMap->{"power_usb_online"} = "USB-Versorgung Status";
#$rMap->{"power_usb_present"} = "USB-Versorgung vorhanden";
#$rMap->{"power_usb_current"} = "USB-Versorgung Strom";
#$rMap->{"power_usb_voltage"} = "USB-Versorgung Spannung";
$rMap->{"power_usb_stat"} = "USB-Versorgung Info";
$rMap->{"power_usb_text"} = "USB-Versorgung Info";
}
if(SYSMON_isSysPowerBat($hash)) {
#$rMap->{"power_battery_online"} = "Batterie-Versorgung Status";
#$rMap->{"power_battery_present"} = "Batterie-Versorgung vorhanden";
#$rMap->{"power_battery_current"} = "Batterie-Versorgung Strom";
#$rMap->{"power_battery_voltage"} = "Batterie-Versorgung Spannung";
$rMap->{"power_battery_stat"} = "Batterie-Versorgung Info";
$rMap->{"power_battery_text"} = "Batterie-Versorgung Info";
$rMap->{"power_battery_info"} = "Batterie-Versorgung Zusatzinfo";
}
#$rMap->{"fhemuptime"} = "Betriebszeit FHEM";
#$rMap->{"fhemuptime_text"} = "Betriebszeit FHEM";
#$rMap->{"idletime"} = "Leerlaufzeit";
@ -679,6 +708,17 @@ SYSMON_obtainParameters($$)
$map = SYSMON_getLoadAvg($hash, $map);
$map = SYSMON_getCPUProcStat($hash, $map);
#$map = SYSMON_getDiskStat($hash, $map);
# Power info (cubietruck)
if(SYSMON_isSysPowerAc($hash)) {
$map = SYSMON_PowerAcInfo($hash, $map);
}
if(SYSMON_isSysPowerUsb($hash)) {
$map = SYSMON_PowerUsbInfo($hash, $map);
}
if(SYSMON_isSysPowerBat($hash)) {
$map = SYSMON_PowerBatInfo($hash, $map);
}
}
}
@ -1853,6 +1893,130 @@ SYSMON_isFB($) {
return $sys_fb;
}
#-Power-------
my $sys_power_ac = undef;
sub
SYSMON_isSysPowerAc($) {
my ($hash) = @_;
if(!defined $sys_power_ac) {
$sys_power_ac = int(SYSMON_execute($hash, "[ -f /sys/class/power_supply/ac/online ] && echo 1 || echo 0"));
}
return $sys_power_ac;
}
my $sys_power_usb = undef;
sub
SYSMON_isSysPowerUsb($) {
my ($hash) = @_;
if(!defined $sys_power_usb) {
$sys_power_usb = int(SYSMON_execute($hash, "[ -f /sys/class/power_supply/usb/online ] && echo 1 || echo 0"));
}
return $sys_power_usb;
}
my $sys_power_bat = undef;
sub
SYSMON_isSysPowerBat($) {
my ($hash) = @_;
if(!defined $sys_power_bat) {
$sys_power_bat = int(SYSMON_execute($hash, "[ -f /sys/class/power_supply/battery/online ] && echo 1 || echo 0"));
}
return $sys_power_bat;
}
sub SYSMON_PowerAcInfo($$)
{
#online, present, current_now (/1000 =>mA), voltage_now (/1000000 => V)
my ($hash, $map) = @_;
my $type="ac";
my $base = "cat /sys/class/power_supply/".$type."/";
my $d_online = trim(SYSMON_execute($hash, $base."online"));
my $d_present = trim(SYSMON_execute($hash, $base."present"));
my $d_current = SYSMON_execute($hash, $base."current_now");
if(defined $d_current) {$d_current/=1000;}
my $d_voltage = SYSMON_execute($hash, $base."voltage_now");
if(defined $d_voltage) {$d_voltage/=1000000;}
#$map->{"power_".$type."_online"}=$d_online;
#$map->{"power_".$type."_present"}=$d_present;
#$map->{"power_".$type."_current"}=$d_current;
#$map->{"power_".$type."_voltage"}=$d_voltage;
$map->{"power_".$type."_stat"}="$d_online $d_present $d_voltage $d_current";
$map->{"power_".$type."_text"}=$type.": ".(($d_present eq "1") ? "present" : "absent")." / ".($d_online eq "1" ? "online" : "offline").", Voltage: ".$d_voltage." V, Current: ".$d_current." mA";
return $map;
}
sub SYSMON_PowerUsbInfo($$)
{
#online, present, current_now (/1000 =>mA), voltage_now (/1000000 => V)
my ($hash, $map) = @_;
my $type="usb";
my $base = "cat /sys/class/power_supply/".$type."/";
my $d_online = trim(SYSMON_execute($hash, $base."online"));
my $d_present = trim(SYSMON_execute($hash, $base."present"));
my $d_current = SYSMON_execute($hash, $base."current_now");
if(defined $d_current) {$d_current/=1000;}
my $d_voltage = SYSMON_execute($hash, $base."voltage_now");
if(defined $d_voltage) {$d_voltage/=1000000;}
#$map->{"power_".$type."_online"}=$d_online;
#$map->{"power_".$type."_present"}=$d_present;
#$map->{"power_".$type."_current"}=$d_current;
#$map->{"power_".$type."_voltage"}=$d_voltage;
$map->{"power_".$type."_stat"}="$d_online $d_present $d_voltage $d_current";
$map->{"power_".$type."_text"}=$type.": ".(($d_present eq "1") ? "present" : "absent")." / ".($d_online eq "1" ? "online" : "offline").", Voltage: ".$d_voltage." V, Current: ".$d_current." mA";
return $map;
}
sub SYSMON_PowerBatInfo($$)
{
#online, present, current_now (/1000 =>mA), voltage_now (/1000000 => V)
my ($hash, $map) = @_;
my $type="battery";
my $base = "cat /sys/class/power_supply/".$type."/";
my $d_online = trim(SYSMON_execute($hash, $base."online"));
my $d_present = trim(SYSMON_execute($hash, $base."present"));
my $d_current = SYSMON_execute($hash, $base."current_now");
if(defined $d_current) {$d_current/=1000;}
my $d_voltage = SYSMON_execute($hash, $base."voltage_now");
if(defined $d_voltage) {$d_voltage/=1000000;}
#$map->{"power_".$type."_online"}=$d_online;
#$map->{"power_".$type."_present"}=$d_present;
#$map->{"power_".$type."_current"}=$d_current;
#$map->{"power_".$type."_voltage"}=$d_voltage;
$map->{"power_".$type."_stat"}="$d_online $d_present $d_voltage $d_current";
$map->{"power_".$type."_text"}=$type.": ".(($d_present eq "1") ? "present" : "absent")." / ".($d_online eq "1" ? "online" : "offline").", Voltage: ".$d_voltage." V, Current: ".$d_current." mA";
# TODO
if($d_present eq "1") {
# Zusaetzlich: technology, capacity, status, health, temp (/10 => °C)
my $d_technology = trim(SYSMON_execute($hash, $base."technology"));
my $d_capacity = trim(SYSMON_execute($hash, $base."capacity"));
my $d_status = trim(SYSMON_execute($hash, $base."status"));
my $d_health = trim(SYSMON_execute($hash, $base."health"));
my $d_temp = trim(SYSMON_execute($hash, $base."temp"));
if(defined $d_temp) {$d_temp/=10;}
$map->{"power_".$type."_info"}=$type." info: ".$d_technology." , capacity: ".$d_capacity." %, status: ".$d_status." , health: ".$d_health." , temperatur: ".$d_temp." C";
# ggf. noch irgendwann: model_name, voltage_max_design, voltage_min_design
} else {
$map->{"power_".$type."_info"}=$type." info: n/a , capacity: n/a %, status: n/a , health: n/a , temperatur: n/a C";
}
return $map;
}
#-------------
sub
SYSMON_execute($$)
{
@ -2051,6 +2215,41 @@ If one (or more) of the multiplier is set to zero, the corresponding readings is
Information on the installed firmware version: <VersionNum> <creation date> <time>
</li>
<br>
<b>Power Supply Readings</b>
<li>power_ac_stat<br>
status information to the AC socket: present (0|1), online (0|1), voltage, current
Example:<br>
<code>power_ac_stat: 1 1 4.807 264</code><br>
</li>
<br>
<li>power_ac_text<br>
human readable status information to the AC socket<br>
Example:<br>
<code>power_ac_text ac: present / online, Voltage: 4.807 V, Current: 264 mA</code><br>
</li>
<br>
<li>power_usb_stat<br>
status information to the USB socket
</li>
<br>
<li>power_usb_text<br>
human readable status information to the USB socket
</li>
<br>
<li>power_battery_stat<br>
status information to the battery (if installed)
</li>
<br>
<li>power_battery_text<br>
human readable status information to the battery (if installed)
</li>
<br>
<li>power_battery_info<br>
human readable additional information to the battery (if installed): technology, capacity, status, health, temperatur<br>
Example:<br>
<code>power_battery_info: battery info: Li-Ion , capacity: 100 %, status: Full , health: Good , temperatur: 30 C</code><br>
</li>
<br>
<br>
</ul>
@ -2523,6 +2722,41 @@ If one (or more) of the multiplier is set to zero, the corresponding readings is
Angaben zu der installierten Firmware-Version: <VersionNr> <Erstelldatum> <Zeit>
</li>
<br>
<b>Readings zur Stromversorgung</b>
<li>power_ac_stat<br>
Statusinformation f&uuml;r die AC-Buchse: present (0|1), online (0|1), voltage, current
Beispiel:<br>
<code>power_ac_stat: 1 1 4.807 264</code><br>
</li>
<br>
<li>power_ac_text<br>
Statusinformation f&uuml;r die AC-Buchse in menschenlesbarer Form<br>
Beispiel:<br>
<code>power_ac_text ac: present / online, Voltage: 4.807 V, Current: 264 mA</code><br>
</li>
<br>
<li>power_usb_stat<br>
Statusinformation f&uuml;r die USB-Buchse
</li>
<br>
<li>power_usb_text<br>
Statusinformation f&uuml;r die USB-Buchse in menschenlesbarer Form
</li>
<br>
<li>power_battery_stat<br>
Statusinformation f&uuml;r die Batterie (wenn vorhanden)
</li>
<br>
<li>power_battery_text<br>
Statusinformation f&uuml;r die Batterie (wenn vorhanden) in menschenlesbarer Form
</li>
<br>
<li>power_battery_info<br>
Menschenlesbare Zusatzinformationen f&uuml;r die Batterie (wenn vorhanden): Technologie, Kapazit&auml;t, Status, Zustand, Temperatur<br>
Beispiel:<br>
<code>power_battery_info: battery info: Li-Ion , capacity: 100 %, status: Full , health: Good , temperatur: 30 C</code><br>
</li>
<br>
<br>
</ul>