From 79e24d56d436511e8d89df4bd5198cf9e825800c Mon Sep 17 00:00:00 2001 From: wuehler <> Date: Thu, 14 May 2020 19:28:57 +0000 Subject: [PATCH] 74_UnifiSwitch: new readings for general_temperature, overheating, fan_level, cpu and mem git-svn-id: https://svn.fhem.de/fhem/trunk@21942 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/74_UnifiSwitch.pm | 62 +++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/fhem/FHEM/74_UnifiSwitch.pm b/fhem/FHEM/74_UnifiSwitch.pm index fb87a5611..b11ed162a 100755 --- a/fhem/FHEM/74_UnifiSwitch.pm +++ b/fhem/FHEM/74_UnifiSwitch.pm @@ -27,12 +27,14 @@ # - feature: 74_UnifiSwitch: supports disablePort # V 0.0.96 # - fixed: 74_UnifiSwitch: Log-Messages +# V 0.0.97 +# - fixed: 74_UnifiSwitch: new readings for general_temperature, overheating, fan_level, cpu and mem # # TODOs: # - state des USW für weiter state-Numbers korrekt in Worte übersetzen package main; -my $version="0.0.96"; +my $version="0.0.97"; # Laden evtl. abhängiger Perl- bzw. FHEM-Module use strict; use warnings; @@ -130,10 +132,16 @@ sub UnifiSwitch_Set($@){ my $portProfileDisableID=AttrVal($name,"portProfileDisableID",undef); my $isPortprofileID = ""; $isPortprofileID ="disablePort" if (defined $portProfileDisableID); - if($setName !~ /clear|poeMode|disablePort/) { + if($setName !~ /clear|poeMode|disablePort/) { return "Unknown argument $setName, choose one of " ."clear:all,readings poeMode ".$isPortprofileID; #TODO: PortNamen sowie die Modes als Auswahl anhängen - } else { + }elsif ($setName eq 'clear') { + if ($setVal eq 'readings' || $setVal eq 'all') { + for (keys %{$hash->{READINGS}}) { + delete $hash->{READINGS}->{$_} if($_ ne 'state'); + } + } + } else { Log3 $name, 4, "$name: set $setName"; my $apRef = $hash->{usw}; if( $setVal !~ m/\d+/ ) { #falls der Portname angegeben wurde, diesen in eine ID umwandeln. @@ -200,12 +208,6 @@ sub UnifiSwitch_Set($@){ }else { return "unknwon poe mode $setVal2"; } - }elsif ($setName eq 'clear') { - if ($setVal eq 'readings' || $setVal eq 'all') { - for (keys %{$hash->{READINGS}}) { - delete $hash->{READINGS}->{$_} if($_ ne 'state'); - } - } } } return undef; @@ -304,6 +306,18 @@ sub UnifiSwitch_Parse($$) { } $hash->{MODEL}=$apRef->{model}; readingsBeginUpdate($hash); + Log3 $name, 5, "$name ($self) - executed. UnifiSwitch: message_json: ".$message_json; + if (defined $apRef->{has_fan} && $apRef->{has_fan}){ + readingsBulkUpdate($hash,"switch_fan_level",$apRef->{fan_level}); + } + if (defined $apRef->{has_temperature} && $apRef->{has_temperature}){ + readingsBulkUpdate($hash,"switch_general_temperature",$apRef->{general_temperature}); + readingsBulkUpdate($hash,"switch_overheating",$apRef->{overheating}); + } + if (defined $apRef->{"system-stats"}){ + readingsBulkUpdate($hash,"switch_sys_cpu",$apRef->{"system-stats"}->{cpu}) if defined $apRef->{"system-stats"}->{cpu} ; + readingsBulkUpdate($hash,"switch_sys_mem",$apRef->{"system-stats"}->{mem}) if defined $apRef->{"system-stats"}->{mem} ; + } if( $apRef->{port_table} ){ for my $port (@{$apRef->{port_table}}) { my $port_id=$port->{port_idx} > 9 ? "port_".$port->{port_idx} : "port_0".$port->{port_idx}; @@ -430,23 +444,39 @@ You can use the readings or set features to control your unifi-switch.

Readings