2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-09 20:57:11 +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:
eisler 2018-02-23 20:12:16 +00:00
parent 7832fd38a1
commit 2d5f434972
2 changed files with 29 additions and 1 deletions

View File

@ -1,5 +1,6 @@
# 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.
- feature: 10_MQTT_DEVICE: add SetExtensions
- bugfix: 00_MQTT: small bugfix
- feature: 98_DOIFtools: support for multiple holiday files in holiday2we for
next timer calculation

View File

@ -52,6 +52,7 @@ sub MQTT_DEVICE_Initialize($) {
"publishSet_.* ".
"subscribeReading_.* ".
"autoSubscribeReadings ".
"useSetExtensions:1,0 ".
$main::readingFnAttributes;
main::LoadModule("MQTT");
@ -64,6 +65,7 @@ use warnings;
use GPUtils qw(:all);
use Net::MQTT::Constants;
use SetExtensions qw/ :all /;
BEGIN {
MQTT->import(qw(:all));
@ -73,6 +75,8 @@ BEGIN {
CommandAttr
readingsSingleUpdate
Log3
SetExtensions
SetExtensionsCancel
fhem
defs
AttrVal
@ -91,6 +95,14 @@ sub Set($$$@) {
return "Need at least one parameters" unless defined $command;
my $msgid;
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(defined($hash->{publishSets}->{$command})) {
my $value = join " ",@values;
@ -115,8 +127,13 @@ sub Set($$$@) {
}
}
if(!$mark) {
return "Unknown argument $command, choose one of " . join(" ", map {$hash->{sets}->{$_} eq "" ? $_ : "$_:".$hash->{sets}->{$_}} sort keys %{$hash->{sets}})
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}})
}
}
SetExtensionsCancel($hash);
$hash->{message_ids}->{$msgid}++ if defined $msgid;
readingsSingleUpdate($hash,"transmission-state","outgoing publish sent",1);
return undef;
@ -264,6 +281,12 @@ sub onmessage($$$) {
<p><code>set &lt;name&gt; &lt;reading&gt; &lt;value&gt;</code><br/>
sets reading &lt;reading&gt; and publishes the command to topic configured via attr publishSet_&lt;reading&gt;</p>
</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>
<a name="MQTT_DEVICEattr"></a>
<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>
</p>
</li>
<li>
<p><code>attr &lt;name&gt; useSetExtensions &lt;flags&gt;</code><br/>
If set to 1, then the <a href="#setExtensions">set extensions</a> are supported.</p>
</li>
</ul>
</ul>