From e203879aebc0b15dd93df2ae807d036d3cd44744 Mon Sep 17 00:00:00 2001 From: HomeAuto_User <> Date: Mon, 17 Aug 2020 17:29:09 +0000 Subject: [PATCH] 14_FLAMINGO: fix some perlcritic 5 warnings git-svn-id: https://svn.fhem.de/fhem/trunk@22619 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/14_FLAMINGO.pm | 434 ++++++++++++++++++++------------------- 2 files changed, 227 insertions(+), 208 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index f4f5bad0d..50f7f54c3 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -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: 14_FLAMINGO.pm: fix some perlcritic 5 warnings - feature: 98_DOIFtools: get subsInPackageDOIF for MODEL Perl (Forum #63938) - bugfix: 49_SSCam(STRM): avoid possible warnings during shutdown/restart - bugfix: 52_I2C_HDC1008: fix "temperature" (broken by change from Aug, 1st) diff --git a/fhem/FHEM/14_FLAMINGO.pm b/fhem/FHEM/14_FLAMINGO.pm index e3fb4c4cc..72280265c 100644 --- a/fhem/FHEM/14_FLAMINGO.pm +++ b/fhem/FHEM/14_FLAMINGO.pm @@ -3,9 +3,10 @@ ################################################################# # The module was taken over by an unknown maintainer! # It is part of the SIGNALduinos project. -# https://github.com/RFD-FHEM/RFFHEM/tree/dev-r33 +# https://github.com/RFD-FHEM/RFFHEM # -# 2018 - HomeAuto_User & elektron-bbs +# 2018 - takeover from unknown maintainer +# 2018-2020 - HomeAuto_User, elektron-bbs ################################################################# # FLAMINGO FA20RF # get sduino_dummy raw MU;;P0=-1384;;P1=815;;P2=-2725;;P3=-20001;;P4=8159;;P5=-891;;D=01010121212121010101210101345101210101210101212101010101012121212101010121010134510121010121010121210101010101212121210101012101013451012101012101012121010101010121212121010101210101345101210101210101212101010101012121212101010121010134510121010121010121;;CP=1;;O;; @@ -25,229 +26,246 @@ package main; use strict; use warnings; +our $VERSION = '200817'; my %sets = ( - "Testalarm:noArg", - "Counterreset:noArg", + 'Testalarm:noArg', + 'Counterreset:noArg', ); my %models = ( - "FA20RF", - "FA21RF", - "FA22RF", - "KD-101LA", - "LM-101LD", - "unknown", + 'FA20RF', + 'FA21RF', + 'FA22RF', + 'KD-101LA', + 'LM-101LD', + 'unknown', ); ##################################### -sub -FLAMINGO_Initialize($) -{ +sub FLAMINGO_Initialize { my ($hash) = @_; - - $hash->{Match} = "^P13\.?1?#[A-Fa-f0-9]+"; - $hash->{SetFn} = "FLAMINGO_Set"; - $hash->{DefFn} = "FLAMINGO_Define"; - $hash->{UndefFn} = "FLAMINGO_Undef"; - $hash->{ParseFn} = "FLAMINGO_Parse"; - $hash->{AttrList} = "IODev do_not_notify:0,1 showtime:0,1 ignore:0,1 ". - "model:".join(",", sort %models)." " . - "room:FLAMINGO ". - $readingFnAttributes; - $hash->{AutoCreate}= - { - "FLAMINGO.*" => { ATTR => "event-on-change-reading:.* event-min-interval:.*:300 room:FLAMINGO", FILTER => "%NAME", GPLOT => ""}, - }; + + $hash->{Match} = '^P13\.?1?#[A-Fa-f0-9]+'; + $hash->{SetFn} = 'FLAMINGO_Set'; + $hash->{DefFn} = 'FLAMINGO_Define'; + $hash->{UndefFn} = 'FLAMINGO_Undef'; + $hash->{ParseFn} = 'FLAMINGO_Parse'; + $hash->{AttrList} = 'IODev do_not_notify:0,1 showtime:0,1 ignore:0,1 '. + 'model:'.join(q{,}, sort %models).q{ } . + 'room:FLAMINGO '. + $readingFnAttributes; + $hash->{AutoCreate}= + { + 'FLAMINGO.*' => { ATTR => 'event-on-change-reading:.* event-min-interval:.*:300', FILTER => '%NAME', GPLOT => q{} }, + }; + + return } ##################################### -sub FLAMINGO_Define($$) { - my ($hash, $def) = @_; - my @a = split("[ \t][ \t]*", $def); +sub FLAMINGO_Define { + my ($hash, $def) = @_; + my @a = split("[ \t][ \t]*", $def); - # Argument 0 1 2 3 4 - return "wrong syntax: define FLAMINGO " if(int(@a) < 3 || int(@a) > 5); - ### check code ### - return "wrong hex value: ".$a[2] if not ($a[2] =~ /^[0-9a-fA-F]{6}$/m); - ### check model ### - return "wrong model: ".$a[3] . "\n\n(allowed modelvalues: " . join(" | ", sort %models).")" if $a[3] && ( !grep { $_ eq $a[3] } %models ); - - $hash->{CODE} = $a[2]; - $hash->{lastMSG} = "no data"; - $hash->{bitMSG} = "no data"; + # Argument 0 1 2 3 4 + return 'ERROR: wrong syntax, define FLAMINGO ' if(int(@a) < 3 || int(@a) > 5); + ### check hex code ### + return 'ERROR: wrong hex length ' . length($a[2]) . ', you need 6'if not length($a[2]) == 6; + return 'ERROR: wrong hex value ' . $a[2] if not ($a[2] =~ /^[0-9a-fA-F]{6}$/xms); + ### check model ### + return 'ERROR: wrong model: '.$a[3] . "\n\n(allowed modelvalues: " . join(' | ', sort %models).')' if $a[3] && ( !grep { $_ eq $a[3] } %models ); - $modules{FLAMINGO}{defptr}{$a[2]} = $hash; - $hash->{STATE} = "Defined"; + $hash->{CODE} = $a[2]; + $hash->{lastMSG} = 'no data'; + $hash->{bitMSG} = 'no data'; - my $name= $hash->{NAME}; - my $iodev = $a[3] if($a[3]); - $iodev = $modules{FLAMINGO}{defptr}{ioname} if (exists $modules{FLAMINGO}{defptr}{ioname} && not $iodev); + $modules{FLAMINGO}{defptr}{$a[2]} = $hash; + $hash->{STATE} = 'Defined'; - ### Attributes ### - if ( $init_done == 1 ) { - $attr{$name}{model} = $a[3] if $a[3]; - $attr{$name}{model} = "unknown" if not $a[3]; - - $attr{$name}{room} = "FLAMINGO"; - #$attr{$name}{stateFormat} = "{ReadingsVal($name, "state", "")." | ".ReadingsTimestamp($name, "state", "")}"; - } - - AssignIoPort($hash,$iodev); ## sucht nach einem passenden IO-Gerät (physikalische Definition) + my $name = $hash->{NAME}; + my $iodev; + if ($a[4]) { $iodev = $a[4]; }; + if (exists $modules{FLAMINGO}{defptr}{ioname} && !$iodev) { $iodev = $modules{FLAMINGO}{defptr}{ioname}; }; - return undef; + ### Attributes ### + if ( $init_done == 1 ) { + if ($a[3]) { CommandAttr($hash,"$name model $a[3]") ;}; + if (not $a[3]) { CommandAttr($hash,"$name model unknown") ;}; + } + + AssignIoPort($hash,$iodev); ## sucht nach einem passenden IO-Gerät (physikalische Definition) + + return; } ##################################### -sub FLAMINGO_Undef($$) { +sub FLAMINGO_Undef { my ($hash, $name) = @_; - RemoveInternalTimer($hash, "FLAMINGO_UpdateState"); - delete($modules{FLAMINGO}{defptr}{$hash->{CODE}}) if($hash && $hash->{CODE}); - delete($modules{FLAMINGO}{defptr}{testrunning}) if exists ($modules{FLAMINGO}{defptr}{testrunning}); - return undef; + RemoveInternalTimer($hash, 'FLAMINGO_UpdateState'); + if($hash && $hash->{CODE}) { + delete($modules{FLAMINGO}{defptr}{$hash->{CODE}}); + }; + + if ( exists $modules{FLAMINGO}{defptr}{testrunning} ) { + delete($modules{FLAMINGO}{defptr}{testrunning}); + } + return; } ##################################### -sub FLAMINGO_Set($$@) { - my ( $hash, $name, @args ) = @_; +sub FLAMINGO_Set { + my ( $hash, $name, @args ) = @_; - my $ret = undef; - my $message; - my $list; - my $model = AttrVal($name, "model", "unknown"); - my $iodev = $hash->{IODev}{NAME}; - - $list = join (" ", %sets); - return "ERROR: wrong command! (only $list)" if ($args[0] ne "?" && $args[0] ne "Testalarm" && $args[0] ne "Counterreset"); - - if ($args[0] eq "?") { - if ($model eq "unknown") { - $ret = ""; # no set if model unknown or no model attribut - } else { - $ret = $list; - } - } - - my $hlen = length($hash->{CODE}); - my $blen = $hlen * 4; - my $bitData= unpack("B$blen", pack("H$hlen", $hash->{CODE})); - - my $bitAdd = substr($bitData,23,1); # for last bit, is needed to send - - ## use the protocol ID how receive last message - my $sendID = ReadingsVal($name, "lastReceive_ID", ""); # for send command, because ID´s can vary / MU / MS message - - $message = "P".$sendID."#".$bitData.$bitAdd."P#R55"; + my $ret = undef; + my $message; + my $list; + my $model = AttrVal($name, 'model', 'unknown'); + my $iodev = $hash->{IODev}{NAME}; - ## Send Message to IODev and wait for correct answer - Log3 $hash, 3, "FLAMINGO set $name $args[0]" if ($args[0] ne "?"); - Log3 $hash, 4, "$iodev: FLAMINGO send raw Message: $message" if ($args[0] eq "Testalarm"); - - ## Counterreset ## - if ($args[0] eq "Counterreset") { - readingsSingleUpdate($hash, "alarmcounter", 0, 1); - } - - ## Testarlarm ## - if ($args[0] ne "?" and $args[0] ne "Counterreset") { - - # remove InternalTimer - RemoveInternalTimer($hash, "FLAMINGO_UpdateState"); - - $modules{FLAMINGO}{defptr}{testrunning} = "yes"; # marker, device send Testalarm to NOT register this alarm with other receivers in FHEM - Log3 $hash, 4, "FLAMINGO set marker TESTALARM is running"; - - readingsSingleUpdate($hash, "state", "Testalarm", 1); - IOWrite($hash, 'sendMsg', $message); - - InternalTimer(gettimeofday()+15, "FLAMINGO_UpdateState", $hash, 0); # set timer to Update status - } + $list = join (q{ }, %sets); + return "ERROR: wrong command! (only $list)" if ($args[0] ne '?' && $args[0] ne 'Testalarm' && $args[0] ne 'Counterreset'); - return $ret; + if ($args[0] eq '?') { + if ($model eq 'unknown') { + $ret = q{}; # no set if model unknown or no model attribut + } else { + $ret = $list; + } + } + + my $hlen = length($hash->{CODE}); + my $blen = $hlen * 4; + my $bitData= unpack("B$blen", pack("H$hlen", $hash->{CODE})); + + my $bitAdd = substr($bitData,23,1); # for last bit, is needed to send + + ## use the protocol ID how receive last message + my $sendID = ReadingsVal($name, 'lastReceive_ID', q{}); # for send command, because ID´s can vary / MU / MS message + + $message = 'P'.$sendID.'#'.$bitData.$bitAdd.'P#R55'; + + ## Send Message to IODev and wait for correct answer + if ($args[0] ne '?') { + Log3 $hash, 3, "FLAMINGO set $name $args[0]"; + } + + ## Counterreset ## + if ($args[0] eq 'Counterreset') { + readingsSingleUpdate($hash, 'alarmcounter', 0, 1); + } + + ## Testarlarm ## + if ($args[0] ne '?' and $args[0] ne 'Counterreset') { + + # remove InternalTimer + RemoveInternalTimer($hash, 'FLAMINGO_UpdateState'); + + $modules{FLAMINGO}{defptr}{testrunning} = 'yes'; # marker, device send Testalarm to NOT register this alarm with other receivers in FHEM + Log3 $hash, 4, 'FLAMINGO set marker TESTALARM is running'; + + readingsSingleUpdate($hash, 'state', 'Testalarm', 1); + Log3 $hash, 4, "$iodev: FLAMINGO send raw Message: $message"; + + IOWrite($hash, 'sendMsg', $message); + + InternalTimer(gettimeofday()+15, 'FLAMINGO_UpdateState', $hash, 0); # set timer to Update status + } + + return $ret; } ##################################### -sub FLAMINGO_Parse($$) { - my ($iohash, $msg) = @_; - #my $name = $iohash->{NAME}; - my ($protocol,$rawData) = split("#",$msg); - $protocol=~ s/^[P](\d+)/$1/; # extract protocol +sub FLAMINGO_Parse { + my ($iohash, $msg) = @_; + #my $name = $iohash->{NAME}; + my ($protocol,$rawData) = split('#',$msg); + $protocol=~ s/^[P](\d+)/$1/xms; # extract protocol - my $iodev = $iohash->{NAME}; - $modules{FLAMINGO}{defptr}{ioname} = $iodev; + my $iodev = $iohash->{NAME}; + $modules{FLAMINGO}{defptr}{ioname} = $iodev; - my $hlen = length($rawData); - my $blen = $hlen * 4; - my $bitData= unpack("B$blen", pack("H$hlen", $rawData)); + my $hlen = length($rawData); + my $blen = $hlen * 4; + my $bitData= unpack("B$blen", pack("H$hlen", $rawData)); - my $deviceCode = $rawData; # Message is in hex "4d4efd" - - my $def = $modules{FLAMINGO}{defptr}{$deviceCode}; - $def = $modules{FLAMINGO}{defptr}{$deviceCode} if(!$def); - my $hash = $def; + my $deviceCode = $rawData; # Message is in hex "4d4efd" - #my $model = AttrVal($name, "model", "unknown"); - - if(!$def) { - Log3 $iohash, 1, "FLAMINGO UNDEFINED sensor detected, code $deviceCode, protocol $protocol"; - return "UNDEFINED FLAMINGO_$deviceCode FLAMINGO $deviceCode"; - } - - my $name = $hash->{NAME}; - return "" if(IsIgnored($name)); - - $hash->{bitMSG} = $bitData; - $hash->{lastMSG} = $rawData; - $hash->{lastReceive} = time(); - - readingsSingleUpdate($hash, "lastReceive_ID", $protocol, 0); # to save lastReceive_ID for send command - - ## check if Testalarm received from a other transmitter in FHEM ## - my $testalarmcheck = ""; - $testalarmcheck = $modules{FLAMINGO}{defptr}{testrunning} if exists ($modules{FLAMINGO}{defptr}{testrunning}); - - if ($testalarmcheck eq "yes") { - return ""; - } - - my $alarmcounter = ReadingsVal($name, "alarmcounter", 0); - - if (ReadingsVal($name, "state", "") ne "Alarm") { - $alarmcounter = $alarmcounter+1; - } + my $def = $modules{FLAMINGO}{defptr}{$deviceCode}; + if(!$def) { + $def = $modules{FLAMINGO}{defptr}{$deviceCode}; + } + my $hash = $def; - Log3 $name, 5, "$iodev: FLAMINGO actioncode: $deviceCode"; - Log3 $name, 4, "$iodev: FLAMINGO $name: is receiving Alarm (Counter $alarmcounter)"; - - # remove InternalTimer - RemoveInternalTimer($hash, "FLAMINGO_UpdateState"); - - readingsBeginUpdate($hash); - readingsBulkUpdate($hash, "state", "Alarm"); - readingsBulkUpdate($hash, "alarmcounter", $alarmcounter); # register non testalarms how user can set via FHEM - readingsEndUpdate($hash, 1); # Notify is done by Dispatch + #my $model = AttrVal($name, 'model', 'unknown'); - InternalTimer(gettimeofday()+15, "FLAMINGO_UpdateState", $hash, 0); # set timer to Update status - - return $name; + if(!$def) { + Log3 $iohash, 1, "FLAMINGO UNDEFINED sensor detected, code $deviceCode, protocol $protocol"; + return "UNDEFINED FLAMINGO_$deviceCode FLAMINGO $deviceCode"; + } + + my $name = $hash->{NAME}; + if(IsIgnored($name)) { + return q{}; + } + + $hash->{bitMSG} = $bitData; + $hash->{lastMSG} = $rawData; + $hash->{lastReceive} = time(); + + readingsSingleUpdate($hash, 'lastReceive_ID', $protocol, 0); # to save lastReceive_ID for send command + + ## check if Testalarm received from a other transmitter in FHEM ## + my $testalarmcheck = q{}; + if ( exists $modules{FLAMINGO}{defptr}{testrunning} ) { + $testalarmcheck = $modules{FLAMINGO}{defptr}{testrunning}; + } + + if ($testalarmcheck eq 'yes') { + return q{}; + } + + my $alarmcounter = ReadingsVal($name, 'alarmcounter', 0); + + if (ReadingsVal($name, 'state', q{}) ne 'Alarm') { + $alarmcounter = $alarmcounter+1; + } + + Log3 $name, 5, "$iodev: FLAMINGO actioncode: $deviceCode"; + Log3 $name, 4, "$iodev: FLAMINGO $name: is receiving Alarm (Counter $alarmcounter)"; + + # remove InternalTimer + RemoveInternalTimer($hash, 'FLAMINGO_UpdateState'); + + readingsBeginUpdate($hash); + readingsBulkUpdate($hash, 'state', 'Alarm'); + readingsBulkUpdate($hash, 'alarmcounter', $alarmcounter); # register non testalarms how user can set via FHEM + readingsEndUpdate($hash, 1); # Notify is done by Dispatch + + InternalTimer(gettimeofday()+15, 'FLAMINGO_UpdateState', $hash, 0); # set timer to Update status + + return $name; } ##################################### -sub FLAMINGO_UpdateState($) { - my ($hash) = @_; - my $name = $hash->{NAME}; +sub FLAMINGO_UpdateState { + my ($hash) = @_; + my $name = $hash->{NAME}; - readingsBeginUpdate($hash); - readingsBulkUpdate($hash, "state", "no Alarm"); - readingsEndUpdate($hash, 1); # Notify is done by Dispatch + readingsBeginUpdate($hash); + readingsBulkUpdate($hash, 'state', 'no Alarm'); + readingsEndUpdate($hash, 1); # Notify is done by Dispatch - ## delete marker device Testalarm ## - Log3 $hash, 4, "FLAMINGO delete marker TESTALARM was running" if exists ($modules{FLAMINGO}{defptr}{testrunning}); - delete($modules{FLAMINGO}{defptr}{testrunning}) if exists ($modules{FLAMINGO}{defptr}{testrunning}); - - Log3 $name, 4, "FLAMINGO: $name: Alarm stopped"; + ## delete marker device Testalarm ## + if ( exists $modules{FLAMINGO}{defptr}{testrunning} ) { + Log3 $hash, 4, 'FLAMINGO delete marker TESTALARM was running'; + delete($modules{FLAMINGO}{defptr}{testrunning}) + }; + + Log3 $name, 4, "FLAMINGO: $name: Alarm stopped"; + return; } @@ -272,9 +290,9 @@ sub FLAMINGO_UpdateState($) {
  • <code> is the unic code of the autogenerated address of the FLAMINGO device. This changes, after pairing to the master
  • -
  • <model> is the model name

  • - - if autocreate, the defined model is unknown.
    - - with manual define you can choose the model which is available as attribute. +
  • <model> is the model name

  • + - if autocreate, the defined model is unknown.
    + - with manual define you can choose the model which is available as attribute.

    @@ -297,11 +315,11 @@ sub FLAMINGO_UpdateState($) {
  • do_not_notify
  • eventMap
  • ignore
  • - -
  • model
    - FA20RF, FA21RF, FA22RF, KD-101LA, LM-101LD, unknown
  • + +
  • model
    + FA20RF, FA21RF, FA22RF, KD-101LA, LM-101LD, unknown
  • -
  • showtime
  • +
  • showtime
  • readingFnAttributes


  • @@ -344,20 +362,20 @@ sub FLAMINGO_UpdateState($) {
  • <code> ist der automatisch angelegte eindeutige code des FLAMINGO Rauchmelders. Dieser ändern sich nach - dem Pairing mit einem Master.
  • -
  • <model> ist die Modelbezeichnung

  • - - Bei einem Autocreate wird als Model unknown definiert.
    - - Bei einem manuellen define kann man das Model frei wählen welche als Attribut verfügbar sind . + dem Pairing mit einem Master. +
  • <model> ist die Modelbezeichnung

  • + - Bei einem Autocreate wird als Model unknown definiert.
    + - Bei einem manuellen define kann man das Model frei wählen welche als Attribut verfügbar sind .

    Set
      -
    • Counterreset
      - - Alarmzähler auf 0 setzen
    • -
    • Testalarm
      - - auslösen eines Testalarmes. (Der Testalarm erhöht nicht den Alarmzähler!)
    • +
    • Counterreset
      + - Alarmzähler auf 0 setzen
    • +
    • Testalarm
      + - auslösen eines Testalarmes. (Der Testalarm erhöht nicht den Alarmzähler!)

    @@ -370,10 +388,10 @@ sub FLAMINGO_UpdateState($) {
  • do_not_notify
  • eventMap
  • ignore
  • - -
  • model
    - FA20RF, FA21RF, FA22RF, KD-101LA, LM-101LD, unknown
  • - + +
  • model
    + FA20RF, FA21RF, FA22RF, KD-101LA, LM-101LD, unknown
  • +
  • showtime
  • readingFnAttributes
  • @@ -386,16 +404,16 @@ sub FLAMINGO_UpdateState($) { Anleitung
    Melder paaren (Master-Slave Prinzip)
      -
    • Master bestimmen
      - LEARN-Taste bis grüne Anzeige LED leuchtet
    • -
    • Slave bestimmen
      - LEARN-Taste bis rote Anzeige LED leuchtet
    • -
    • Master, TEST-Taste gedrückt halten, bevor LEDś abschalten und alles "Slaves" ein Alarmsignal erzeugen
    • +
    • Master bestimmen
      + LEARN-Taste bis grüne Anzeige LED leuchtet
    • +
    • Slave bestimmen
      + LEARN-Taste bis rote Anzeige LED leuchtet
    • +
    • Master, TEST-Taste gedrückt halten, bevor LEDś abschalten und alles "Slaves" ein Alarmsignal erzeugen

    Paarung aufheben / Standalone Betrieb
      -
    • LEARN-Taste bis grüne Anzeige LED leuchtet
    • -
    • TEST-Taste gedrückt halten bis ein Alarmsignal erzeugt wird
    • +
    • LEARN-Taste bis grüne Anzeige LED leuchtet
    • +
    • TEST-Taste gedrückt halten bis ein Alarmsignal erzeugt wird