mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 03:06:37 +00:00
10_MQTT_DEVICE: add SetExtensions
git-svn-id: https://svn.fhem.de/fhem/trunk@16249 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
7832fd38a1
commit
2d5f434972
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
||||||
# Do not insert empty lines here, update check depends on it.
|
# Do not insert empty lines here, update check depends on it.
|
||||||
|
- feature: 10_MQTT_DEVICE: add SetExtensions
|
||||||
- bugfix: 00_MQTT: small bugfix
|
- bugfix: 00_MQTT: small bugfix
|
||||||
- feature: 98_DOIFtools: support for multiple holiday files in holiday2we for
|
- feature: 98_DOIFtools: support for multiple holiday files in holiday2we for
|
||||||
next timer calculation
|
next timer calculation
|
||||||
|
@ -52,6 +52,7 @@ sub MQTT_DEVICE_Initialize($) {
|
|||||||
"publishSet_.* ".
|
"publishSet_.* ".
|
||||||
"subscribeReading_.* ".
|
"subscribeReading_.* ".
|
||||||
"autoSubscribeReadings ".
|
"autoSubscribeReadings ".
|
||||||
|
"useSetExtensions:1,0 ".
|
||||||
$main::readingFnAttributes;
|
$main::readingFnAttributes;
|
||||||
|
|
||||||
main::LoadModule("MQTT");
|
main::LoadModule("MQTT");
|
||||||
@ -64,6 +65,7 @@ use warnings;
|
|||||||
use GPUtils qw(:all);
|
use GPUtils qw(:all);
|
||||||
|
|
||||||
use Net::MQTT::Constants;
|
use Net::MQTT::Constants;
|
||||||
|
use SetExtensions qw/ :all /;
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
MQTT->import(qw(:all));
|
MQTT->import(qw(:all));
|
||||||
@ -73,6 +75,8 @@ BEGIN {
|
|||||||
CommandAttr
|
CommandAttr
|
||||||
readingsSingleUpdate
|
readingsSingleUpdate
|
||||||
Log3
|
Log3
|
||||||
|
SetExtensions
|
||||||
|
SetExtensionsCancel
|
||||||
fhem
|
fhem
|
||||||
defs
|
defs
|
||||||
AttrVal
|
AttrVal
|
||||||
@ -91,6 +95,14 @@ sub Set($$$@) {
|
|||||||
return "Need at least one parameters" unless defined $command;
|
return "Need at least one parameters" unless defined $command;
|
||||||
my $msgid;
|
my $msgid;
|
||||||
my $mark=0;
|
my $mark=0;
|
||||||
|
|
||||||
|
if (AttrVal($name,"useSetExtensions",undef)) {
|
||||||
|
if ($command =~ m/^(blink|intervals|(off-|on-)(for-timer|till(-overnight)?))(.+)?|toggle$/) {
|
||||||
|
Log3($hash->{NAME},5,"calling SetExtensions(...) for $command");
|
||||||
|
return SetExtensions($hash, join(" ", map {$hash->{sets}->{$_} eq "" ? $_ : "$_:".$hash->{sets}->{$_}} sort keys %{$hash->{sets}}), $name, $command, @values);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if($command ne '?') {
|
if($command ne '?') {
|
||||||
if(defined($hash->{publishSets}->{$command})) {
|
if(defined($hash->{publishSets}->{$command})) {
|
||||||
my $value = join " ",@values;
|
my $value = join " ",@values;
|
||||||
@ -115,8 +127,13 @@ sub Set($$$@) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!$mark) {
|
if(!$mark) {
|
||||||
|
if(AttrVal($name,"useSetExtensions",undef)) {
|
||||||
|
return SetExtensions($hash, join(" ", map {$hash->{sets}->{$_} eq "" ? $_ : "$_:".$hash->{sets}->{$_}} sort keys %{$hash->{sets}}), $name, $command, @values);
|
||||||
|
} else {
|
||||||
return "Unknown argument $command, choose one of " . join(" ", map {$hash->{sets}->{$_} eq "" ? $_ : "$_:".$hash->{sets}->{$_}} sort keys %{$hash->{sets}})
|
return "Unknown argument $command, choose one of " . join(" ", map {$hash->{sets}->{$_} eq "" ? $_ : "$_:".$hash->{sets}->{$_}} sort keys %{$hash->{sets}})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
SetExtensionsCancel($hash);
|
||||||
$hash->{message_ids}->{$msgid}++ if defined $msgid;
|
$hash->{message_ids}->{$msgid}++ if defined $msgid;
|
||||||
readingsSingleUpdate($hash,"transmission-state","outgoing publish sent",1);
|
readingsSingleUpdate($hash,"transmission-state","outgoing publish sent",1);
|
||||||
return undef;
|
return undef;
|
||||||
@ -264,6 +281,12 @@ sub onmessage($$$) {
|
|||||||
<p><code>set <name> <reading> <value></code><br/>
|
<p><code>set <name> <reading> <value></code><br/>
|
||||||
sets reading <reading> and publishes the command to topic configured via attr publishSet_<reading></p>
|
sets reading <reading> and publishes the command to topic configured via attr publishSet_<reading></p>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<p>The <a href="#setExtensions">set extensions</a> are supported with useSetExtensions attribute.<br/>
|
||||||
|
Set eventMap if your publishSet commands are not on/off.</p>
|
||||||
|
<p>example for true/false:<br/>
|
||||||
|
<code>attr mqttest eventMap { dev=>{ 'true'=>'on', 'false'=>'off' }, usr=>{ '^on$'=>'true', '^off$'=>'false' }, fw=>{ '^on$'=>'on', '^off$'=>'off' } }</code></p>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<a name="MQTT_DEVICEattr"></a>
|
<a name="MQTT_DEVICEattr"></a>
|
||||||
<p><b>Attributes</b></p>
|
<p><b>Attributes</b></p>
|
||||||
@ -314,6 +337,10 @@ sub onmessage($$$) {
|
|||||||
defines QOS 0 for all readings/topics except the reading 'test'. Retain for 'test' is 1<br>
|
defines QOS 0 for all readings/topics except the reading 'test'. Retain for 'test' is 1<br>
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<p><code>attr <name> useSetExtensions <flags></code><br/>
|
||||||
|
If set to 1, then the <a href="#setExtensions">set extensions</a> are supported.</p>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user