diff --git a/fhem/FHEM/00_MQTT2_SERVER.pm b/fhem/FHEM/00_MQTT2_SERVER.pm index aec4a58ec..2507f6bdd 100644 --- a/fhem/FHEM/00_MQTT2_SERVER.pm +++ b/fhem/FHEM/00_MQTT2_SERVER.pm @@ -40,6 +40,7 @@ MQTT2_SERVER_Initialize($) clientOrder disable:1,0 disabledForIntervals + hideRetain:1,0 ignoreRegexp keepaliveFactor rePublish:1,0 @@ -185,6 +186,21 @@ MQTT2_SERVER_Attr(@) } } + if($attrName eq "hideRetain") { + my $hide = ($type eq "set" && $param[0]); + if($hide) { + if($hash->{READINGS}{RETAIN}) { + $hash->{READINGS}{".RETAIN"} = $hash->{READINGS}{RETAIN}; + delete($hash->{READINGS}{RETAIN}); + } + } else { + if($hash->{READINGS}{".RETAIN"}) { + $hash->{READINGS}{RETAIN} = $hash->{READINGS}{".RETAIN"}; + delete($hash->{READINGS}{".RETAIN"}); + } + } + } + return undef; } @@ -192,11 +208,13 @@ sub MQTT2_SERVER_Set($@) { my ($hash, @a) = @_; - my %sets = ( publish=>1 ); + my %sets = ( publish=>":textField,[-r] topic message", + clearRetain=>":noArg" ); shift(@a); - return "Unknown argument ?, choose one of ".join(" ", keys %sets) - if(!$a[0] || !$sets{$a[0]}); + return "Unknown argument ?, choose one of ". + join(" ", map { "$_$sets{$_}" } keys %sets) + if(!$a[0] || !defined($sets{$a[0]})); if($a[0] eq "publish") { shift(@a); @@ -211,6 +229,12 @@ MQTT2_SERVER_Set($@) readingsSingleUpdate($hash, "lastPublish", "$tp:$val", 1); MQTT2_SERVER_doPublish($hash->{CL}, $hash, $tp, $val, $retain); } + + if($a[0] eq "clearRetain") { + my $rname = AttrVal($hash->{NAME}, "hideRetain", 0) ? "RETAIN" : ".RETAIN"; + delete($hash->{READINGS}{$rname}); + delete($hash->{retain}); + } } sub @@ -218,13 +242,21 @@ MQTT2_SERVER_State() { my ($hash, $ts, $name, $val) = @_; - if($name eq "RETAIN") { + if($name eq "RETAIN" || $name eq ".RETAIN") { my $now = gettimeofday; my $ret = json2nameValue($val); for my $k (keys %{$ret}) { my %h = ( ts=>$now, val=>$ret->{$k} ); $hash->{retain}{$k} = \%h; } + + my $rname = AttrVal($hash->{NAME}, "hideRetain", 0) ? "RETAIN" : ".RETAIN"; + if($name ne $rname) { + InternalTimer(0, sub { + $hash->{READINGS}{$rname} = $hash->{READINGS}{$name}; + delete($hash->{READINGS}{$name}); + }, undef); + } } return undef; } @@ -505,7 +537,8 @@ MQTT2_SERVER_doPublish($$$$;$) # Save it my %nots = map { $_ => $server->{retain}{$_}{val} } keys %{$server->{retain}}; - setReadingsVal($server,"RETAIN",toJSON(\%nots),FmtDateTime(gettimeofday())); + my $rname = AttrVal($server->{NAME}, "hideRetain", 0) ? ".RETAIN" : "RETAIN"; + setReadingsVal($server, $rname, toJSON(\%nots), FmtDateTime(gettimeofday())); } foreach my $clName (keys %{$server->{clients}}) { @@ -687,9 +720,14 @@ MQTT2_SERVER_ReadDebug($$) Set
@@ -728,7 +766,6 @@ MQTT2_SERVER_ReadDebug($$) expression.
-
  • clientId <name>
    set the MQTT clientId for all connections, for setups with clients @@ -752,6 +789,12 @@ MQTT2_SERVER_ReadDebug($$) messages, but not forward them.

  • + +
  • hideRetain [0|1]
    + if set to 1, the RETAIN reading will be named .RETAIN, i.e. hidden by + default. +
  • +
  • ignoreRegexp
    if $topic:$message matches ignoreRegexp, then it will be silently ignored. diff --git a/fhem/www/pgm2/fhemweb.js b/fhem/www/pgm2/fhemweb.js index 18dac8893..33815db3d 100644 --- a/fhem/www/pgm2/fhemweb.js +++ b/fhem/www/pgm2/fhemweb.js @@ -1509,7 +1509,7 @@ FW_createTextField(elName, devName, vArr, currVal, set, params, cmd) vArr[0] != "textFieldNL-long") || (params && params.length)) return undefined; - + var is_long = (vArr[0].indexOf("long") > 0); var newEl = $("
    ").get(0); @@ -1521,6 +1521,8 @@ FW_createTextField(elName, devName, vArr, currVal, set, params, cmd) $(inp).attr('name', elName); if(currVal != undefined) $(inp).val(currVal); + if(vArr.length == 2 && !is_long) + $(inp).attr("placeholder", vArr[1]); function addBlur() { if(cmd) $(inp).blur(function() { cmd($(inp).val()) }); }; @@ -2173,9 +2175,9 @@ FW_checkNotifydev(reName)
  • noArg - show no input field.
  • time - show a JavaScript driven timepicker.
    Example: attr FS20dev widgetOverride on-till:time
  • -
  • textField - show an input field.
    +
  • textField[,placeholder] - show an input field.
    Example: attr WEB widgetOverride room:textField
  • -
  • textFieldNL - show the input field and hide the label.
  • +
  • textFieldNL[,placeholder] - show the input field and hide the label.
  • textField-long[,sizePct] - show an input-field, but upon clicking on the input field open a textArea. sizePct specifies the size of the dialog relative to the screen, in @@ -2208,9 +2210,9 @@ FW_checkNotifydev(reName)
  • noArg - es wird kein weiteres Eingabefeld angezeigt.
  • time - zeigt ein Zeitauswahlmenü. Beispiel: attr FS20dev widgetOverride on-till:time
  • -
  • textField - zeigt ein Eingabefeld.
    +
  • textField[,placeholder] - zeigt ein Eingabefeld.
    Beispiel: attr WEB widgetOverride room:textField
  • -
  • textFieldNL - Eingabefeld ohne Label.
  • +
  • textFieldNL[,placeholder] - Eingabefeld ohne Label.
  • textField-long[,sizePct] - ist wie textField, aber beim Click im Eingabefeld wird ein Dialog mit einer HTML textarea wird geöffnet. sizePct ist die relative Größe des Dialogs,