From 065b27c358edd62bdb437797c1b7431fde0756b0 Mon Sep 17 00:00:00 2001 From: wuehler <> Date: Fri, 19 Jan 2018 21:11:09 +0000 Subject: [PATCH] 74_Unifi.pm:fixed blockClient git-svn-id: https://svn.fhem.de/fhem/trunk@15930 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/74_Unifi.pm | 50 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index cc5715ff3..0e0ca6cb6 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. + - bugfix: 74_Unifi: fixed blockClient - bugfix: 98_dewpoint.pm: Fix event processing when updating STATE - bugfix: 73_ElectricityCalculator.pm: Spelling error - change: 74_XiaomiBTLESens: Code clean diff --git a/fhem/FHEM/74_Unifi.pm b/fhem/FHEM/74_Unifi.pm index 2857d173c..d0bbb6ed8 100644 --- a/fhem/FHEM/74_Unifi.pm +++ b/fhem/FHEM/74_Unifi.pm @@ -8,6 +8,8 @@ # enable/disable WLAN, new client-Reading essid # V2.1 # - feature: 74_Unifi: add new set command to en-/disable Site Status-LEDs +# V2.1.1 +# - bugfix: 74_Unifi: fixed blockClient package main; @@ -1121,6 +1123,52 @@ sub Unifi_DisconnectClient_Receive($) { return undef; } +############################################################################### +sub Unifi_BlockClient_Send($@) { + my ($hash,@clients) = @_; + my ($name,$self) = ($hash->{NAME},Unifi_Whoami()); + Log3 $name, 5, "$name ($self) - executed with count:'".scalar(@clients)."', ID:'".$clients[0]."'"; + my $id = shift @clients; + HttpUtils_NonblockingGet( { + %{$hash->{httpParams}}, + url => $hash->{unifi}->{url}."cmd/stamgr", + callback => \&Unifi_BlockClient_Receive, + clients => [@clients], + data => "{'mac': '".$hash->{clients}->{$id}->{mac}."', 'cmd': 'block-sta'}", + } ); + + return undef; +} + +############################################################################### +sub Unifi_BlockClient_Receive($) { + my ($param, $err, $data) = @_; + my ($name,$self,$hash) = ($param->{hash}->{NAME},Unifi_Whoami(),$param->{hash}); + Log3 $name, 5, "$name ($self) - executed."; + + if ($err ne "") { + Unifi_ReceiveFailure($hash,{rc => 'Error while requesting', msg => $param->{url}." - $err"}); + } + elsif ($data ne "") { + if ($param->{code} == 200 || $param->{code} == 400 || $param->{code} == 401) { + eval { $data = decode_json($data); 1; } or do { $data = { meta => {rc => 'error.decode_json', msg => $@} }; }; + + if ($data->{meta}->{rc} eq "ok") { + Log3 $name, 5, "$name ($self) - state:'$data->{meta}->{rc}'"; + } + else { Unifi_ReceiveFailure($hash,$data->{meta}); } + } else { + Unifi_ReceiveFailure($hash,{rc => $param->{code}, msg => "Failed with HTTP Code $param->{code}."}); + } + } + + if (scalar @{$param->{clients}}) { + Unifi_BlockClient_Send($hash,@{$param->{clients}}); + } + + return undef; +} + ############################################################################### sub Unifi_UnblockClient_Send($@) { my ($hash,@clients) = @_; @@ -1161,7 +1209,7 @@ sub Unifi_UnblockClient_Receive($) { } if (scalar @{$param->{clients}}) { - Unifi_BlockClient_Send($hash,@{$param->{clients}}); + Unifi_UnblockClient_Send($hash,@{$param->{clients}}); } return undef;