mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
00_MQTT2_SERVER.pm: add "attr hideRetain", "set clearRetain" (Forum #126366)
git-svn-id: https://svn.fhem.de/fhem/trunk@25849 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
7f35f4502c
commit
eede448865
@ -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($$)
|
||||
<a id="MQTT2_SERVER-set"></a>
|
||||
<b>Set</b>
|
||||
<ul>
|
||||
<li>publish -r topic value<br>
|
||||
<a id="MQTT2_SERVER-set-publish"></a>
|
||||
<li>publish [-r] topic value<br>
|
||||
publish a message, -r denotes setting the retain flag.
|
||||
</li>
|
||||
<a id="MQTT2_SERVER-set-clearRetain"></a>
|
||||
<li>clearRetain<br>
|
||||
delete all the retained topics.
|
||||
</li>
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
@ -728,7 +766,6 @@ MQTT2_SERVER_ReadDebug($$)
|
||||
expression.
|
||||
</li><br>
|
||||
|
||||
|
||||
<a id="MQTT2_SERVER-attr-clientId"></a>
|
||||
<li>clientId <name><br>
|
||||
set the MQTT clientId for all connections, for setups with clients
|
||||
@ -752,6 +789,12 @@ MQTT2_SERVER_ReadDebug($$)
|
||||
messages, but not forward them.
|
||||
</li><br>
|
||||
|
||||
<a id="MQTT2_SERVER-attr-hideRetain"></a>
|
||||
<li>hideRetain [0|1]<br>
|
||||
if set to 1, the RETAIN reading will be named .RETAIN, i.e. hidden by
|
||||
default.
|
||||
</li>
|
||||
|
||||
<a id="MQTT2_SERVER-attr-ignoreRegexp"></a>
|
||||
<li>ignoreRegexp<br>
|
||||
if $topic:$message matches ignoreRegexp, then it will be silently ignored.
|
||||
|
@ -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)
|
||||
<li>noArg - show no input field.</li>
|
||||
<li>time - show a JavaScript driven timepicker.<br>
|
||||
Example: attr FS20dev widgetOverride on-till:time</li>
|
||||
<li>textField - show an input field.<br>
|
||||
<li>textField[,placeholder] - show an input field.<br>
|
||||
Example: attr WEB widgetOverride room:textField</li>
|
||||
<li>textFieldNL - show the input field and hide the label.</li>
|
||||
<li>textFieldNL[,placeholder] - show the input field and hide the label.</li>
|
||||
<li>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)
|
||||
<li>noArg - es wird kein weiteres Eingabefeld angezeigt.</li>
|
||||
<li>time - zeigt ein Zeitauswahlmenü.
|
||||
Beispiel: attr FS20dev widgetOverride on-till:time</li>
|
||||
<li>textField - zeigt ein Eingabefeld.<br>
|
||||
<li>textField[,placeholder] - zeigt ein Eingabefeld.<br>
|
||||
Beispiel: attr WEB widgetOverride room:textField</li>
|
||||
<li>textFieldNL - Eingabefeld ohne Label.</li>
|
||||
<li>textFieldNL[,placeholder] - Eingabefeld ohne Label.</li>
|
||||
<li>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,
|
||||
|
Loading…
Reference in New Issue
Block a user