2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-22 08:11:44 +00:00

MYSENSORS_DEVICE: support 'set extensions' (for setCommands) and 'slider' (for dimmer)

git-svn-id: https://svn.fhem.de/fhem/trunk@6894 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
ntruchsess 2014-11-05 11:39:17 +00:00
parent 4abef0233a
commit 5b987a5ae1

View File

@ -63,6 +63,7 @@ use GPUtils qw(:all);
use Device::MySensors::Constants qw(:all); use Device::MySensors::Constants qw(:all);
use Device::MySensors::Message qw(:all); use Device::MySensors::Message qw(:all);
use SetExtensions qw/ :all /;
BEGIN { BEGIN {
MYSENSORS->import(qw(:all)); MYSENSORS->import(qw(:all));
@ -75,6 +76,7 @@ BEGIN {
CommandDeleteReading CommandDeleteReading
AssignIoPort AssignIoPort
Log3 Log3
SetExtensions
)) ))
}; };
@ -109,11 +111,11 @@ my %static_types = (
my %static_mappings = ( my %static_mappings = (
V_TEMP => { type => "temperature" }, V_TEMP => { type => "temperature" },
V_HUM => { type => "humidity", range => { min => 0, max => 100 }}, V_HUM => { type => "humidity" },
V_PRESSURE => { type => "pressure" }, V_PRESSURE => { type => "pressure" },
V_LIGHT_LEVEL => { type => "brightness" }, V_LIGHT_LEVEL => { type => "brightness" },
V_LIGHT => { type => "switch", val => { 0 => 'off', 1 => 'on' }}, V_LIGHT => { type => "switch", val => { 0 => 'off', 1 => 'on' }},
V_DIMMER => { type => "dimmer", range => { min => 0, max => 100 }}, V_DIMMER => { type => "dimmer", range => { min => 0, step => 1, max => 100 }},
V_FORECAST => { type => "forecast", val => { # PressureSensor, DP/Dt explanation V_FORECAST => { type => "forecast", val => { # PressureSensor, DP/Dt explanation
0 => 'stable', # 0 = "Stable Weather Pattern" 0 => 'stable', # 0 = "Stable Weather Pattern"
1 => 'slow rising', # 1 = "Slowly rising Good Weather", "Clear/Sunny " 1 => 'slow rising', # 1 = "Slowly rising Good Weather", "Clear/Sunny "
@ -150,7 +152,7 @@ my %static_mappings = (
V_IR_RECEIVE => { type => "ir_receive" }, V_IR_RECEIVE => { type => "ir_receive" },
V_FLOW => { type => "flow" }, V_FLOW => { type => "flow" },
V_VOLUME => { type => "volume" }, V_VOLUME => { type => "volume" },
V_LOCK_STATUS => { type => "lockstatus", val => { 0 => 'locked', 1 => 'unlocked' }}, V_LOCK_STATUS => { type => "lockstatus", val => { 0 => 'off', 1 => 'on' }},
V_DUST_LEVEL => { type => "dustlevel" }, V_DUST_LEVEL => { type => "dustlevel" },
V_VOLTAGE => { type => "voltage" }, V_VOLTAGE => { type => "voltage" },
V_CURRENT => { type => "current" }, V_CURRENT => { type => "current" },
@ -182,8 +184,10 @@ sub UnDefine($) {
sub Set($@) { sub Set($@) {
my ($hash,$name,$command,@values) = @_; my ($hash,$name,$command,@values) = @_;
return "Need at least one parameters" unless defined $command; return "Need at least one parameters" unless defined $command;
return "Unknown argument $command, choose one of " . join(" ", map {$hash->{sets}->{$_} ne "" ? "$_:$hash->{sets}->{$_}" : $_} sort keys %{$hash->{sets}}) if(!defined($hash->{sets}->{$command})) {
if(!defined($hash->{sets}->{$command})); my $list = join(" ", map {$hash->{sets}->{$_} ne "" ? "$_:$hash->{sets}->{$_}" : $_} sort keys %{$hash->{sets}});
return grep (/(^on$)|(^off$)/,keys %{$hash->{sets}}) == 2 ? SetExtensions($hash, $list, $name, $command, @values) : "Unknown argument $command, choose one of $list";
}
COMMAND_HANDLER: { COMMAND_HANDLER: {
$command eq "clear" and do { $command eq "clear" and do {
sendClientMessage($hash, childId => 255, cmd => C_INTERNAL, subType => I_CHILDREN, payload => "C"); sendClientMessage($hash, childId => 255, cmd => C_INTERNAL, subType => I_CHILDREN, payload => "C");
@ -390,7 +394,13 @@ sub onPresentationMessage($$) {
my $typeStr = $typeMapping->{type}; my $typeStr = $typeMapping->{type};
next if (defined $hash->{sets}->{"$typeStr$idStr"}); next if (defined $hash->{sets}->{"$typeStr$idStr"});
if ($hash->{IODev}->{'inclusion-mode'}) { if ($hash->{IODev}->{'inclusion-mode'}) {
if (my $ret = CommandAttr(undef,"$name setReading_$typeStr$idStr".($typeMapping->{val} ? " ".join (",",values %{$typeMapping->{val}}) : ""))) { my @values = ();
if ($typeMapping->{range}) {
@values = ('slider',$typeMapping->{range}->{min},$typeMapping->{range}->{step},$typeMapping->{range}->{max});
} elsif ($typeMapping->{val}) {
@values = values %{$typeMapping->{val}};
}
if (my $ret = CommandAttr(undef,"$name setReading_$typeStr$idStr".(@values ? " ".join (",",@values) : ""))) {
push @ret,$ret; push @ret,$ret;
} }
} else { } else {
@ -586,7 +596,8 @@ sub mappedReadingToRaw($$$) {
<li> <li>
<p><code>attr &lt;name&gt; setCommands [&lt;command:reading:value&gt;]*</code><br/> <p><code>attr &lt;name&gt; setCommands [&lt;command:reading:value&gt;]*</code><br/>
configures one or more commands that can be executed by set.<br/> configures one or more commands that can be executed by set.<br/>
e.g.: <code>attr &lt;name&gt; setCommands on:switch_1:on off:switch_1:off</code></p> e.g.: <code>attr &lt;name&gt; setCommands on:switch_1:on off:switch_1:off</code><br/>
if list of commands contains both 'on' and 'off' <a href="#setExtensions">set extensions</a> are supported</p>
</li> </li>
<li> <li>
<p><code>attr &lt;name&gt; setReading_&lt;reading&gt; [&lt;value&gt;]*</code><br/> <p><code>attr &lt;name&gt; setReading_&lt;reading&gt; [&lt;value&gt;]*</code><br/>