2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-25 09:55:38 +00:00

36_Shelly: removed Debug commands

git-svn-id: https://svn.fhem.de/fhem/trunk@29079 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Starkstrombastler 2024-08-17 22:37:46 +00:00
parent 6aedf0763f
commit 845d056114

View File

@ -100,6 +100,11 @@
# 6.00 Beta_4 add: client without definition --> reading 'no definition' # 6.00 Beta_4 add: client without definition --> reading 'no definition'
# new: attr timeout controls write out readings with response times # new: attr timeout controls write out readings with response times
# 6.00 fix some details in commandref (german only) # 6.00 fix some details in commandref (german only)
# 6.00.1 fix: selection of readings for command 'set clear responsetimes' improved; Debug commands removed
# to do roller: get maxtime open/close from shelly
# get status on stopp even when interval == 0
# check write out of reading /_nextUpdateTimer
package main; package main;
@ -118,7 +123,7 @@ sub Log($$);
sub Shelly_Set ($@); sub Shelly_Set ($@);
#-- globals on start #-- globals on start
my $version = "6.00 15.08.2024"; my $version = "6.00.1 18.08.2024";
my $defaultINTERVAL = 60; my $defaultINTERVAL = 60;
my $multiplyIntervalOnError = 1.0; # mechanism disabled if value=1 my $multiplyIntervalOnError = 1.0; # mechanism disabled if value=1
@ -1336,7 +1341,7 @@ sub Shelly_Attr(@) {
} }
#--------------------------------------- #---------------------------------------
}elsif( $init_done == 0 ){ }elsif( $init_done == 0 ){
Log3 $name,5,"[Shelly_Attr Debug]leaving Shelly_Attr for cmd $attrName while init is not finished "; Log3 $name,5,"[Shelly_Attr:noinit]leaving Shelly_Attr for cmd $attrName while init is not finished ";
return undef; return undef;
########## following commands are only passed when init is done ! ############# ########## following commands are only passed when init is done ! #############
@ -1580,6 +1585,8 @@ sub Shelly_Attr(@) {
return $error; return $error;
}elsif( $attrVal == 0 ){ }elsif( $attrVal == 0 ){
readingsSingleUpdate( $hash,"state","disabled",1 ); readingsSingleUpdate( $hash,"state","disabled",1 );
readingsSingleUpdate($hash,"/_nextUpdateTimer","disabled",1)
if(0&& AttrVal($name,'timeout',undef) );
} }
#-- update timer #-- update timer
if(0&& $model eq "shellypro3em" && $attrVal > 0 ){ if(0&& $model eq "shellypro3em" && $attrVal > 0 ){
@ -1827,8 +1834,18 @@ sub Shelly_Set ($@) {
my $name = shift @a; my $name = shift @a;
my $cmd = shift @a; my @args=@a; my $cmd = shift @a; my @args=@a;
my $parameters=( scalar(@a)?" and ".scalar(@a)." parameters: ".join(" ",@a) : ", no parameters" ); my $parameters; ##=( scalar(@a)?" and ".scalar(@a)." parameters: ".join(" ",@a) : ", no parameters" );
Log3 $name,4,"[Shelly_Set] calling for device $name with command \'$cmd\'$parameters" if( defined($cmd) && $cmd ne "?");#4 if( defined($cmd) && $cmd ne "?"){
if( scalar(@a) ){
$parameters= join(" ",@a);
$parameters = " and ".scalar(@a)." parameters: ".$parameters;
}else{
$parameters=", no parameters" ;
}
readingsSingleUpdate($hash,"/_set.command",join(" ",$cmd,@a),1) if( AttrVal($name,"timeout",undef) );
Log3 $name,3,"[Shelly_Set] calling for device $name with command \'$cmd\'$parameters"; #4
}
my $value = shift @a; # 1st parameter my $value = shift @a; # 1st parameter
@ -1917,6 +1934,8 @@ sub Shelly_Set ($@) {
Log3 $name,6,"[Shelly_Set] calling for device $name with command $cmd".( defined($value)?" and channel $value":", without channel" ). Log3 $name,6,"[Shelly_Set] calling for device $name with command $cmd".( defined($value)?" and channel $value":", without channel" ).
(defined($isWhat)?", iswhat=$isWhat":", isWhat not defined"); #6 (defined($isWhat)?", iswhat=$isWhat":", isWhat not defined"); #6
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdateMonitored($hash,"/_set.command","$cmd $parameters") if(0&& AttrVal($name,"timeout",undef) );
if( $cmd =~ /^(out)/ ){ if( $cmd =~ /^(out)/ ){
my $channels = maxNum($shelly_models{$model}[0],$shelly_models{$model}[2]); # device has one or more relay or dimmer - channels my $channels = maxNum($shelly_models{$model}[0],$shelly_models{$model}[2]); # device has one or more relay or dimmer - channels
$channels = 1 if( !$value ); #no channel given - change of single channel device output $channels = 1 if( !$value ); #no channel given - change of single channel device output
@ -2066,17 +2085,17 @@ if(0){
my $actionselect = shift @a; my $actionselect = shift @a;
my $actionchannel = shift @a; my $actionchannel = shift @a;
$actionselect = "" if( !defined($actionselect) ); $actionselect = "" if( !defined($actionselect) );
$actionselect = "info" if( $actioncmd eq "y" ); # for debugging only $actionselect = "info" if( $actioncmd eq "y" ); # for_debugging only
Log3 $name,4,"[Shelly_Set:actions] $name: \'set $cmd $actioncmd $actionselect\' called"; Log3 $name,4,"[Shelly_Set:actions] $name: \'set $cmd $actioncmd $actionselect\' called";
my $gen=$shelly_models{$model}[4]; my $gen=$shelly_models{$model}[4];
#-- check parameter #-- check parameter
if( $actioncmd eq "y" ){ #ok if( $actioncmd eq "y" ){ #ok
}elsif( $actioncmd !~ /create|delete|disable|enable|update|y/ ){ }elsif( $actioncmd !~ /create|delete|disable|enable|update|y/ ){
return "Command \'$actioncmd\' is not valid"; return "Command \'$actioncmd\' is not valid";
}elsif( $actioncmd !~ /create|enable/ && ReadingsNum($name,"webhook_cnt",0)==0 ){ }elsif( $actioncmd !~ /create|enable/ && ReadingsNum($name,"webhook_cnt",0)==0 ){ # commands: delete, disable, update
return "No enabled actions on device $name"; return "No enabled actions on device $name";
}elsif( $actioncmd =~ /update/ ){ }elsif( $actioncmd =~ /update/ ){
return "Please define attr webhook first" if( !defined(AttrVal($name,"webhook",undef)) ); return "$name: Please define attr webhook first" if( !defined(AttrVal($name,"webhook",undef)) );
} }
if( $gen == 0 ){ if( $gen == 0 ){
$actionchannel=0 unless( defined($actionchannel) ); $actionchannel=0 unless( defined($actionchannel) );
@ -2212,7 +2231,7 @@ if(0){
$delta =~ m/(.*):(.*)/; $delta =~ m/(.*):(.*)/;
$delta = $1; $delta = $1;
$transit=$2; $transit=$2;
Debug "$1 - $2"; #Debug "$1 - $2";
return "brightness-difference not given or not numerical" if( $delta =~ /\D/ ); return "brightness-difference not given or not numerical" if( $delta =~ /\D/ );
return "transit duration not given or not numerical" if( $transit !~ /[\d.]/ ); return "transit duration not given or not numerical" if( $transit !~ /[\d.]/ );
return "transit duration must not exceed 5 sec" if( $transit>5 && ReadingsVal($name,"model_family","-") eq "Gen1" ); return "transit duration must not exceed 5 sec" if( $transit>5 && ReadingsVal($name,"model_family","-") eq "Gen1" );
@ -2728,6 +2747,9 @@ if(0){
RemoveInternalTimer($hash,"Shelly_getEMData"); RemoveInternalTimer($hash,"Shelly_getEMData");
if( $timer ){ if( $timer ){
$msg = "(Re-)Starting cyclic timers: "; $msg = "(Re-)Starting cyclic timers: ";
#---------------------------
readingsSingleUpdate($hash,"/_nextUpdateTimer",$timer.$si_units{time}[$hash->{units}],1)
if(0&& AttrVal($name,'timeout',undef) );
InternalTimer(time()+$timer, "Shelly_status", $hash); InternalTimer(time()+$timer, "Shelly_status", $hash);
$msg .= "status-timer=$timer"; $msg .= "status-timer=$timer";
if( $model eq "shellypro3em" ){ if( $model eq "shellypro3em" ){
@ -2744,8 +2766,10 @@ if(0){
} }
}else{ }else{
$msg = "Device $name is disabled, timer canceled"; $msg = "Device $name is disabled, timer canceled";
# readingsSingleUpdate($hash,"/_nextUpdateTimer","disabled",1)
# if( AttrVal($name,'timeout',undef) );
} }
Log3 $name,4,"[Shelly_Set:startTimer] $name: $msg"; Log3 $name,3,"[Shelly_Set:startTimer] $name: $msg";
return undef; return undef;
}elsif( $cmd eq "calibrate" ){ # shelly-dimmer }elsif( $cmd eq "calibrate" ){ # shelly-dimmer
@ -2798,11 +2822,8 @@ if(0){
readingsSingleUpdate($hash,"error","-",1); readingsSingleUpdate($hash,"error","-",1);
}elsif( $doreset eq "responsetimes" ){ }elsif( $doreset eq "responsetimes" ){
my $ptrclrcnt = 0; my $ptrclrcnt = 0;
foreach my $ptr ('/rpc/Shelly.GetStatus','/rpc/Shelly.GetConfig','/rpc/Shelly.GetDeviceInfo','/rpc/EM.GetStatus','/rpc/EMData.GetStatus', foreach my $ptr ( keys %{$defs{$name}{READINGS}} ){
'/rpc/BLE.CloudRelay.List','/rpc/Webhook.List','/rpc/Webhook.Update','/rpc/Wifi.ListAPClients', if( $ptr =~ /^\// ){ # select all readings beginning with a '/'
'/rpc/PM1.ResetCounters',
'/shelly','/status','/settings','/settings/actions','/_nextUpdateTimer' ){
if( ReadingsVal($name,$ptr,undef) ){
readingsSingleUpdate($hash,$ptr,"-",1); #clear process time reading readingsSingleUpdate($hash,$ptr,"-",1); #clear process time reading
$ptrclrcnt++; $ptrclrcnt++;
} }
@ -3147,10 +3168,10 @@ sub Shelly_status1G {
#-- timer #-- timer
my $remaining = $jhash->{relays}[$i]{timer_remaining}; my $remaining = $jhash->{relays}[$i]{timer_remaining};
readingsBulkUpdateMonitored($hash,"timer".$subs,$remaining.$si_units{time}[$hash->{units}]); readingsBulkUpdateMonitored($hash,"timer".$subs,$remaining.$si_units{time}[$hash->{units}]);
#-- nextUpdateTimer #-- next update timer
if( $remaining>0 && AttrVal($name,'verbose',1) > 5 ){ if( $remaining>0 && AttrVal($name,'verbose',1) > 5 ){
$intervalN = minNum($intervalN,$remaining+0.95); $intervalN = minNum($intervalN,$remaining+0.95);
readingsBulkUpdateMonitored($hash,"/_nextUpdateTimer",$intervalN.$si_units{time}[$hash->{units}]); # readingsBulkUpdateMonitored($hash,"/_nextUpdateTimer",$intervalN.$si_units{time}[$hash->{units}]);
} }
}else{ # Shelly4pro }else{ # Shelly4pro
my $onofftmr = 0; my $onofftmr = 0;
@ -3292,7 +3313,7 @@ sub Shelly_status1G {
readingsBulkUpdateMonitored($hash,"timer".$subs,$remaining.$si_units{time}[$hash->{units}]); readingsBulkUpdateMonitored($hash,"timer".$subs,$remaining.$si_units{time}[$hash->{units}]);
$intervalN = minNum($intervalN,$remaining+0.95) if( $remaining>0 ); $intervalN = minNum($intervalN,$remaining+0.95) if( $remaining>0 );
readingsBulkUpdateMonitored($hash,"/_nextUpdateTimer",$intervalN.$si_units{time}[$hash->{units}]) readingsBulkUpdateMonitored($hash,"/_nextUpdateTimer",$intervalN.$si_units{time}[$hash->{units}])
if( AttrVal($name,'timeout',undef) ); if(0&& AttrVal($name,'timeout',undef) );
# source # source
$source = $jhash->{'lights'}[$i]{'source'}; # 'timer' will occur as 'http' $source = $jhash->{'lights'}[$i]{'source'}; # 'timer' will occur as 'http'
@ -4353,7 +4374,7 @@ sub Shelly_status2G {
} }
} }
readingsSingleUpdate($hash,"/_nextUpdateTimer",$timer.$si_units{time}[$hash->{units}],1) readingsSingleUpdate($hash,"/_nextUpdateTimer",$timer.$si_units{time}[$hash->{units}],1)
if( AttrVal($name,'timeout',undef) ); ## for debugging only if(0&& AttrVal($name,'timeout',undef) );
if( $hash->{INTERVAL}>0 ){ if( $hash->{INTERVAL}>0 ){
#-- initiate next run #-- initiate next run
@ -4899,7 +4920,7 @@ sub Shelly_procEMvalues {
$reading=$pr.$mapping{E1}{aprt_power}.$ps; $reading=$pr.$mapping{E1}{aprt_power}.$ps;
$aprt_power=$jhash->{$emch.'aprt_power'}; $aprt_power=$jhash->{$emch.'aprt_power'};
Debug "may be system error" if( !defined($aprt_power) ); #Debug "may be system error" if( !defined($aprt_power) );
$value =sprintf("%4.1f%s",$aprt_power, $si_units{apparentpower}[$hash->{units}] ); $value =sprintf("%4.1f%s",$aprt_power, $si_units{apparentpower}[$hash->{units}] );
readingsBulkUpdateMonitored($hash,$reading,$value); readingsBulkUpdateMonitored($hash,$reading,$value);
$reading=$pr.$mapping{E1}{act_power}.$ps; $reading=$pr.$mapping{E1}{act_power}.$ps;
@ -5353,14 +5374,14 @@ sub Shelly_response {
} }
# check on successful execution # check on successful execution
$urlcmd =~ m/\/(\d)\?turn=(o.*)(\&timer=)?(\d+)?/; # $urlcmd =~ m/\/(\d)\?turn=(o.*)(\&timer=)?(\d+)?/;
my $channel = $1; my $channel = $1;
my $turnstate=$2; #Debug $turnstate; my $turnstate=$2; #Debug $turnstate;
$onofftimer = $4 if( $model eq "shelly4" && $urlcmd=~/timer/ ); # get remaining time from command (is not supported by /status call) $onofftimer = $4 if( $model eq "shelly4" && $urlcmd=~/timer/ ); # get remaining time from command (is not supported by /status call)
Log3 $name,1,"[Shelly_response:onoff] returns with problem for device $name, timer not set" if( $4 && !$hastimer ); Log3 $name,1,"[Shelly_response:onoff] returns with problem for device $name, timer not set" if( $4 && !$hastimer );
$urlcmd =~ m/turn=(on|off)/; Debug $1; $urlcmd =~ m/turn=(on|off)/; #Debug $1;
Log3 $name,1,"[Shelly_response:onoff] returns without success for device $name, cmd=$urlcmd but ison=$ison vs $1" if( $ison ne $1 ); Log3 $name,1,"[Shelly_response:onoff] returns without success for device $name, cmd=$urlcmd but ison=$ison vs $1" if( $ison ne $1 );
if( defined($overpower) && $overpower eq "1") { if( defined($overpower) && $overpower eq "1") {
@ -5521,7 +5542,7 @@ if(0){
} }
#--------------------------- #---------------------------
readingsSingleUpdate($hash,"/_nextUpdateTimer",$timer.$si_units{time}[$hash->{units}],1) readingsSingleUpdate($hash,"/_nextUpdateTimer",$timer.$si_units{time}[$hash->{units}],1)
if( AttrVal($name,'timeout',undef) ); ## for debugging only if(0&& AttrVal($name,'timeout',undef) );
#-- Call status after switch. #-- Call status after switch.
Log3 $name,4,"[Shelly_response] scheduled status call for $name in $timer sec"; Log3 $name,4,"[Shelly_response] scheduled status call for $name in $timer sec";
RemoveInternalTimer($hash,"Shelly_status"); RemoveInternalTimer($hash,"Shelly_status");
@ -5927,8 +5948,11 @@ sub Shelly_webhook_update {
Log3 $name,4, "[Shelly_webhook_update] $name: checking action with hookid $sh_hookid"; Log3 $name,4, "[Shelly_webhook_update] $name: checking action with hookid $sh_hookid";
} }
$sh_hookname = $jhash->{hooks}[$i]{name}; $sh_hookname = $jhash->{hooks}[$i]{name};
if( $sh_hookname !~ /^_/ ){ if( !defined($sh_hookname) ){
Log3 $name,4,"[Shelly_webhook_update] hookname $sh_hookname not selected, skipping update"; Log3 $name,1,"[Shelly_webhook_update] $name: expected hookname for hook-ID=$sh_hookid ($i) not given, skipping" ;
next;
}elsif( $sh_hookname !~ /^_/ ){
Log3 $name,4,"[Shelly_webhook_update] $name: hookname $sh_hookname not selected, skipping update";
next; next;
} }
$urlcmd = ""; $urlcmd = "";
@ -6021,7 +6045,6 @@ sub Shelly_webhook_update {
} }
} }
} }
#Debug $msg;
# FW_directNotify("FILTER=$name","#FHEMWEB:$FW_wname","FW_okDialog( \"$msg\" )", ""); # FW_directNotify("FILTER=$name","#FHEMWEB:$FW_wname","FW_okDialog( \"$msg\" )", "");
if( $ttlChanges == 0 ){ if( $ttlChanges == 0 ){
Log3 $name,3,"[Shelly_webhook_update] $name: no actions to update"; Log3 $name,3,"[Shelly_webhook_update] $name: no actions to update";
@ -7533,11 +7556,14 @@ sub Shelly_HttpResponse($){
</li> </li>
<li> <li>
<a id="Shelly-attr-timeout"></a> <a id="Shelly-attr-timeout"></a>
<code>attr &lt;name&gt; timeout &lt;timeout&gt;</code> <code>attr &lt;name&gt; timeout &lt;seconds&gt;</code>
<br />Zeitlimit für nichtblockierende Anfragen an den Shelly. Der Standardwert ist 4 Sekunden. <br />Zeitlimit für nichtblockierende Anfragen an den Shelly. Der Standardwert ist 4 Sekunden.
Dieses Attribut sollte bei Timingproblemen ('connect to ... timed out' in der Logdatei) angepasst werden. Dieses Attribut sollte bei Timingproblemen ('connect to ... timed out' in der Logdatei) angepasst werden.
<br />Durch das Setzen dieses Attributs werden für die diversen Anfragen an den Shelly Readings mit Angaben der Reaktionszeit geschrieben. <br />Durch das Setzen dieses Attributs werden für die diversen Anfragen an den Shelly Readings (beginnend mit '/')
Diese Readings werden durch Löschen des Attributes entfernt. mit Angaben der Reaktionszeit,
der letzte Set-Befehl sowie die Zeitspanne bis zur nächsten Status-Aktualisierung geschrieben.
Diese Readings werden durch Löschen des Attributes entfernt und
mit <code>set &lt;name&gt; clear responsetimes</code> zurückgesetzt.
</li> </li>
<li> <li>
<a id="Shelly-attr-webhook"></a> <a id="Shelly-attr-webhook"></a>