mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 03:06:37 +00:00
74_Unifi: removed UCv3 support
git-svn-id: https://svn.fhem.de/fhem/trunk@18927 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
0481ef7fa6
commit
ed982c4139
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# 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.
|
# Do not insert empty lines here, update check depends on it.
|
||||||
|
- changed: 74_Unifi: removed UCv3 support
|
||||||
- feature: 59_Weather: and APIs fix utf8 encode bug, insert patch from lippie
|
- feature: 59_Weather: and APIs fix utf8 encode bug, insert patch from lippie
|
||||||
- change: 98_Text2Speech.pm: changed to new mpv API and removed some bugs
|
- change: 98_Text2Speech.pm: changed to new mpv API and removed some bugs
|
||||||
thanks to RomanticBoy83
|
thanks to RomanticBoy83
|
||||||
|
@ -42,10 +42,12 @@
|
|||||||
# - feature: 74_Unifi: Added readings for wan_ip and results of speedtest
|
# - feature: 74_Unifi: Added readings for wan_ip and results of speedtest
|
||||||
# V 3.1.0
|
# V 3.1.0
|
||||||
# - changed: 74_Unifi: removed deprecated UnifiSwitch-functions!
|
# - changed: 74_Unifi: removed deprecated UnifiSwitch-functions!
|
||||||
|
# V 3.2.0
|
||||||
|
# - changed: 74_Unifi: removed UCv3 support
|
||||||
|
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
my $version="3.1.0";
|
my $version="3.2.0";
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use HttpUtils;
|
use HttpUtils;
|
||||||
@ -147,13 +149,11 @@ sub Unifi_Initialize($$) {
|
|||||||
sub Unifi_Define($$) {
|
sub Unifi_Define($$) {
|
||||||
my ($hash, $def) = @_;
|
my ($hash, $def) = @_;
|
||||||
my @a = split("[ \t][ \t]*", $def);
|
my @a = split("[ \t][ \t]*", $def);
|
||||||
return "Wrong syntax: use define <name> Unifi <ip> <port> <username> <password> [<interval> [<siteID> [<version>]]]" if(int(@a) < 6);
|
return "Wrong syntax: use define <name> Unifi <ip> <port> <username> <password> [<interval> [<siteID>]]" if(int(@a) < 6);
|
||||||
return "Wrong syntax: <port> is not a number!" if(!looks_like_number($a[3]));
|
return "Wrong syntax: <port> is not a number!" if(!looks_like_number($a[3]));
|
||||||
return "Wrong syntax: <interval> is not a number!" if($a[6] && !looks_like_number($a[6]));
|
return "Wrong syntax: <interval> is not a number!" if($a[6] && !looks_like_number($a[6]));
|
||||||
return "Wrong syntax: <interval> too small, must be at least 5" if($a[6] && $a[6] < 5);
|
return "Wrong syntax: <interval> too small, must be at least 5" if($a[6] && $a[6] < 5);
|
||||||
return "Wrong syntax: <version> is not a valid number! Must be 3 or 4." if($a[8] && (!looks_like_number($a[8]) || $a[8] !~ /3|4/));
|
|
||||||
|
|
||||||
#TODO: Passwort verschlüsseln! (ala Harmony?)
|
|
||||||
my $name = $a[0];
|
my $name = $a[0];
|
||||||
%$hash = ( %$hash,
|
%$hash = ( %$hash,
|
||||||
NOTIFYDEV => 'global',
|
NOTIFYDEV => 'global',
|
||||||
@ -162,7 +162,6 @@ sub Unifi_Define($$) {
|
|||||||
eventPeriod => int(AttrVal($name,"eventPeriod",24)),
|
eventPeriod => int(AttrVal($name,"eventPeriod",24)),
|
||||||
deprecatedClientNames => int(AttrVal($name,"deprecatedClientNames",1)),
|
deprecatedClientNames => int(AttrVal($name,"deprecatedClientNames",1)),
|
||||||
interval => $a[6] || 30,
|
interval => $a[6] || 30,
|
||||||
version => $a[8] || 4,
|
|
||||||
url => "https://".$a[2].(($a[3] == 443) ? '' : ':'.$a[3]).'/api/s/'.(($a[7]) ? $a[7] : 'default').'/',
|
url => "https://".$a[2].(($a[3] == 443) ? '' : ':'.$a[3]).'/api/s/'.(($a[7]) ? $a[7] : 'default').'/',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -184,10 +183,9 @@ sub Unifi_Define($$) {
|
|||||||
my $define="$a[2] $a[3] $username $password";
|
my $define="$a[2] $a[3] $username $password";
|
||||||
$define.=" $a[6]" if($a[6]);
|
$define.=" $a[6]" if($a[6]);
|
||||||
$define.=" $a[7]" if($a[7]);
|
$define.=" $a[7]" if($a[7]);
|
||||||
$define.=" $a[8]" if($a[8]);
|
|
||||||
$hash->{DEF} = $define;
|
$hash->{DEF} = $define;
|
||||||
|
|
||||||
Log3 $name, 5, "$name: Defined with url:$hash->{unifi}->{url}, interval:$hash->{unifi}->{interval}, version:$hash->{unifi}->{version}";
|
Log3 $name, 5, "$name: Defined with url:$hash->{unifi}->{url}, interval:$hash->{unifi}->{interval}";
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -702,13 +700,9 @@ sub Unifi_Login_Send($) {
|
|||||||
my $password = $hash->{helper}{password};
|
my $password = $hash->{helper}{password};
|
||||||
$user = Unifi_decrypt( $user );
|
$user = Unifi_decrypt( $user );
|
||||||
$password = Unifi_decrypt( $password );
|
$password = Unifi_decrypt( $password );
|
||||||
if($hash->{unifi}->{version} == 3) {
|
( $loginurl = $hash->{unifi}->{url} ) =~ s/api\/s.+/api\/login/;
|
||||||
( $loginurl = $hash->{unifi}->{url} ) =~ s/api\/s.+/login/;
|
$logindata = '{"username":"'.$user.'", "password":"'.$password.'"}';
|
||||||
$logindata = "login=login&username=".$user."&password=".$password;
|
|
||||||
}else {
|
|
||||||
( $loginurl = $hash->{unifi}->{url} ) =~ s/api\/s.+/api\/login/;
|
|
||||||
$logindata = '{"username":"'.$user.'", "password":"'.$password.'"}';
|
|
||||||
}
|
|
||||||
HttpUtils_NonblockingGet( {
|
HttpUtils_NonblockingGet( {
|
||||||
%{$hash->{httpParams}},
|
%{$hash->{httpParams}},
|
||||||
url => $loginurl,
|
url => $loginurl,
|
||||||
@ -725,19 +719,12 @@ sub Unifi_Login_Receive($) {
|
|||||||
if ($err ne "") {
|
if ($err ne "") {
|
||||||
Log3 $name, 5, "$name ($self) - Error while requesting ".$param->{url}." - $err";
|
Log3 $name, 5, "$name ($self) - Error while requesting ".$param->{url}." - $err";
|
||||||
}
|
}
|
||||||
elsif ($data ne "" && $hash->{unifi}->{version} == 3) {
|
elsif ($data ne "" ) {
|
||||||
if ($data =~ /Invalid username or password/si) {
|
if ($param->{code} == 200 || $param->{code} == 400 || $param->{code} == 401 || $param->{code} == 200) {
|
||||||
Log3 $name, 1, "$name ($self) - Login Failed! Invalid username or password!";
|
|
||||||
} else {
|
|
||||||
Log3 $name, 5, "$name ($self) - Login Failed! Version 3 should not deliver data on successfull login.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elsif ($data ne "" || $hash->{unifi}->{version} == 3) { # v3 Login is empty if login is successfully
|
|
||||||
if ($param->{code} == 200 || $param->{code} == 400 || $param->{code} == 401 || ($hash->{unifi}->{version} == 3 && ($param->{code} == 302 || $param->{code} == 200))) {
|
|
||||||
eval { $data = decode_json($data); 1; } or do { $data = { meta => {rc => 'error.decode_json', msg => $@} }; };
|
eval { $data = decode_json($data); 1; } or do { $data = { meta => {rc => 'error.decode_json', msg => $@} }; };
|
||||||
|
|
||||||
if ($hash->{unifi}->{version} == 3 || $data->{meta}->{rc} eq "ok") { # v3 has no rc-state
|
if ($data->{meta}->{rc} eq "ok") {
|
||||||
Log3 $name, 5, "$name ($self) - state=ok || version=3";
|
Log3 $name, 5, "$name ($self) - state=ok";
|
||||||
$hash->{httpParams}->{header} = '';
|
$hash->{httpParams}->{header} = '';
|
||||||
for (split("\r\n",$param->{httpheader})) {
|
for (split("\r\n",$param->{httpheader})) {
|
||||||
if(/^Set-Cookie/) {
|
if(/^Set-Cookie/) {
|
||||||
@ -763,8 +750,7 @@ sub Unifi_Login_Receive($) {
|
|||||||
." - state:'$data->{meta}->{rc}' - msg:'$data->{meta}->{msg}'";
|
." - state:'$data->{meta}->{rc}' - msg:'$data->{meta}->{msg}'";
|
||||||
} elsif ($data->{meta}->{msg} eq 'api.err.LoginRequired') {
|
} elsif ($data->{meta}->{msg} eq 'api.err.LoginRequired') {
|
||||||
Log3 $name, 1, "$name ($self) - Login Failed! - state:'$data->{meta}->{rc}' - msg:'$data->{meta}->{msg}' -"
|
Log3 $name, 1, "$name ($self) - Login Failed! - state:'$data->{meta}->{rc}' - msg:'$data->{meta}->{msg}' -"
|
||||||
." This error while login indicates that you use wrong <version> or"
|
." This error while login indicates that you use an unsupported UnifiController-version";
|
||||||
." have to define <version> in your fhem definition.";
|
|
||||||
} else {
|
} else {
|
||||||
Log3 $name, 5, "$name ($self) - Login Failed! - state:'$data->{meta}->{rc}' - msg:'$data->{meta}->{msg}'";
|
Log3 $name, 5, "$name ($self) - Login Failed! - state:'$data->{meta}->{rc}' - msg:'$data->{meta}->{msg}'";
|
||||||
}
|
}
|
||||||
@ -2015,7 +2001,7 @@ sub Unifi_ReceiveFailure($$) {
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ($meta->{msg} eq "api.err.NoSiteContext" || ($hash->{unifi}->{version} == 3 && $meta->{msg} eq "api.err.InvalidObject")) {
|
elsif ($meta->{msg} eq "api.err.NoSiteContext") {
|
||||||
Log3 $name, 1, "$name ($self) - Failed! - state:'$meta->{rc}' - msg:'$meta->{msg}'"
|
Log3 $name, 1, "$name ($self) - Failed! - state:'$meta->{rc}' - msg:'$meta->{msg}'"
|
||||||
." - This error indicates that the <siteID> in your definition is wrong."
|
." - This error indicates that the <siteID> in your definition is wrong."
|
||||||
." Try to modify your definition with <sideID> = default.";
|
." Try to modify your definition with <sideID> = default.";
|
||||||
@ -2126,7 +2112,7 @@ Or you can use the other readings or set and get features to control your unifi-
|
|||||||
|
|
||||||
<h4>Define</h4>
|
<h4>Define</h4>
|
||||||
<ul>
|
<ul>
|
||||||
<code>define <name> Unifi <ip> <port> <username> <password> [<interval> [<siteID> [<version>]]]</code>
|
<code>define <name> Unifi <ip> <port> <username> <password> [<interval> [<siteID>]]</code>
|
||||||
<br><br>
|
<br><br>
|
||||||
<br>
|
<br>
|
||||||
<name>:
|
<name>:
|
||||||
@ -2151,23 +2137,16 @@ Or you can use the other readings or set and get features to control your unifi-
|
|||||||
</ul>
|
</ul>
|
||||||
[<interval>]:
|
[<interval>]:
|
||||||
<ul>
|
<ul>
|
||||||
<code>(optional without <siteID> and <version>)<br>
|
<code>(optional without <siteID>)<br>
|
||||||
Interval to fetch the information from the unifi-api. <br>
|
Interval to fetch the information from the unifi-api. <br>
|
||||||
default: 30 seconds</code><br>
|
default: 30 seconds</code><br>
|
||||||
</ul>
|
</ul>
|
||||||
[<siteID>]:
|
[<siteID>]:
|
||||||
<ul>
|
<ul>
|
||||||
<code>(optional without <version>)<br>
|
<code>(optional)<br>
|
||||||
You can find the site-ID by selecting the site in the UniFi web interface.<br>
|
You can find the site-ID by selecting the site in the UniFi web interface.<br>
|
||||||
e.g. https://192.168.12.13:8443/manage/s/foobar the siteId you must use is: foobar.<br>
|
e.g. https://192.168.12.13:8443/manage/s/foobar the siteId you must use is: foobar.<br>
|
||||||
default: default</code><br>
|
default: default</code><br>
|
||||||
</ul>
|
|
||||||
[<version>]:
|
|
||||||
<ul>
|
|
||||||
<code>(optional if you use unifi v4)<br>
|
|
||||||
Unifi-controller version. <br>
|
|
||||||
Version must be specified if version is not 4. At the moment version 3 and 4 are supported.<br>
|
|
||||||
default: 4</code><br>
|
|
||||||
</ul> <br>
|
</ul> <br>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
@ -2175,8 +2154,8 @@ Or you can use the other readings or set and get features to control your unifi-
|
|||||||
<ul>
|
<ul>
|
||||||
<code>define my_unifi_controller Unifi 192.168.1.15 443 admin secret</code><br>
|
<code>define my_unifi_controller Unifi 192.168.1.15 443 admin secret</code><br>
|
||||||
<br>
|
<br>
|
||||||
Or with optional parameters <interval>, <siteID> and <version>:<br>
|
Or with optional parameters <interval> and <siteID> :<br>
|
||||||
<code>define my_unifi_controller Unifi 192.168.1.15 443 admin secret 30 default 3</code><br>
|
<code>define my_unifi_controller Unifi 192.168.1.15 443 admin secret 30 default</code><br>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h4>Set</h4>
|
<h4>Set</h4>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user