98_UbiquitiOut.pm 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ################################################################
  2. #
  3. # $Id: 98_UbiquitiOut.pm 8471 2015-04-23 17:46:01Z wzut $
  4. #
  5. # (c) 2015 Copyright: Wzut
  6. # forum : http://forum.fhem.de/index.php/topic,34131.0.html
  7. # All rights reserved
  8. #
  9. # This code is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. # The GNU General Public License can be found at
  14. # http://www.gnu.org/copyleft/gpl.html.
  15. # A copy is found in the textfile GPL.txt and important notices to the license
  16. # from the author is found in LICENSE.txt distributed with these scripts.
  17. # This script is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. #
  22. ################################################################
  23. # Changelog:
  24. package main;
  25. use strict;
  26. use warnings;
  27. use SetExtensions;
  28. sub UbiquitiOut_Initialize($)
  29. {
  30. my ($hash) = @_;
  31. $hash->{SetFn} = "UbiquitiOut_Set";
  32. $hash->{DefFn} = "UbiquitiOut_Define";
  33. $hash->{UndefFn} = "UbiquitiOut_Undef";
  34. $hash->{AttrList} = $readingFnAttributes;
  35. }
  36. ###################################
  37. sub UbiquitiOut_Define($$)
  38. {
  39. my ($hash, $def) = @_;
  40. my $name = $hash->{NAME};
  41. my @a = split("[ \t][ \t]*", $def);
  42. return "wrong syntax: use define $name UbiquitiOut <Device> <Out#>" if(int(@a) < 4);
  43. my $parent = $a[2];
  44. my $socket = $a[3];
  45. $hash->{IODEV} = $parent;
  46. $hash->{SOCKETNR} = $socket;
  47. $modules{UbiquitiOut}{defptr}{$parent.$socket} = $hash;
  48. if (defined($attr{$parent}{room})) { $attr{$name}{room} = $attr{$parent}{room}; }
  49. my $currentstate = ReadingsVal($parent, $name, "defined");
  50. $hash->{STATE} = $currentstate ;
  51. $hash->{READINGS}{lock}{VAL} = 0;
  52. return undef;
  53. }
  54. ###################################
  55. sub UbiquitiOut_Undef($$)
  56. {
  57. my ($hash, undef) = @_;
  58. my $parent = $hash->{IODEV};
  59. my $socket = $hash->{SOCKETNR};
  60. delete $modules{UbiquitiOut}{defptr}{$parent.$socket} ;
  61. return undef;
  62. }
  63. ###################################
  64. sub UbiquitiOut_Set($@)
  65. {
  66. my ($hash, $name , @a) = @_;
  67. my $cmd = $a[0];
  68. my $cmdList = "off:noArg on:noArg toggle:noArg";
  69. return "$name, no set value specified" if(int(@a) < 1);
  70. return "$name, I/O device not found please define UbiquitiPM device first" if(!defined($hash->{IODEV}));
  71. return undef if ($hash->{READINGS}{lock}{VAL} eq "1") && ($cmd eq "?");
  72. return "$name, set command is not available while device is locked !" if ($hash->{READINGS}{lock}{VAL} eq "1");
  73. if($cmd =~ /^(on|off|toggle)$/) # nur diese drei Kommandos kennt es selbst
  74. {
  75. CommandSet(undef,$hash->{IODEV}." Out".$hash->{SOCKETNR}. " $cmd");
  76. return undef;
  77. }
  78. return SetExtensions($hash,$cmdList,$name,@a);
  79. }
  80. #####################################
  81. 1;
  82. =pod
  83. =begin html
  84. <a name="UbiquitiOut"></a>
  85. <h3>UbiquitiOut</h3>
  86. <ul>
  87. <table><tr><td>
  88. sub device for the UbiquitiMP or InfratekPM modul
  89. </td></tr></table>
  90. <a name="UbiquitiOutdefine"></a>
  91. <b>Define</b>
  92. <ul>
  93. <code>define &lt;name&gt; UbiquitiOut &lt;UbiquitiMP device&gt; &lt;Out #&gt;</code>
  94. </ul>
  95. <a name="UbiquitiOutset"></a>
  96. <b>Set </b>
  97. <ul><a href="#setExtensions">set Extensions</a>
  98. </ul>
  99. </ul>
  100. =end html