74_Unifi: support UDM
git-svn-id: https://svn.fhem.de/fhem/trunk@22962 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -75,10 +75,12 @@
|
|||||||
# - fixed: 74_Unifi: fixed AP-Readingnames (use makeReadingName())
|
# - fixed: 74_Unifi: fixed AP-Readingnames (use makeReadingName())
|
||||||
# V 3.4.0
|
# V 3.4.0
|
||||||
# - feature: 74_Unifi: new setter to start RF-Scan
|
# - feature: 74_Unifi: new setter to start RF-Scan
|
||||||
|
# V 3.5.0
|
||||||
|
# - feature: 74_Unifi: support UDM
|
||||||
|
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
my $version="3.4.0";
|
my $version="3.5.0";
|
||||||
# Default f<>r clientReadings setzen. Die Readings waren der Standard vor Einf<6E>hrung des Attributes customClientReadings.
|
# Default f<>r clientReadings setzen. Die Readings waren der Standard vor Einf<6E>hrung des Attributes customClientReadings.
|
||||||
# Eine <20>nderung hat Auswirkungen auf (alte) Moduldefinitionen ohne dieses Attribut.
|
# Eine <20>nderung hat Auswirkungen auf (alte) Moduldefinitionen ohne dieses Attribut.
|
||||||
my $defaultClientReadings=".:^accesspoint|^essid|^hostname|^last_seen|^snr|^uptime"; #ist wegen snr vs rssi nur halb korrekt, wird aber auch nicht wirklich verwendet ;-)
|
my $defaultClientReadings=".:^accesspoint|^essid|^hostname|^last_seen|^snr|^uptime"; #ist wegen snr vs rssi nur halb korrekt, wird aber auch nicht wirklich verwendet ;-)
|
||||||
@@ -185,6 +187,7 @@ sub Unifi_Initialize($$) {
|
|||||||
."voucherCache "
|
."voucherCache "
|
||||||
."customClientReadings:textField-long "
|
."customClientReadings:textField-long "
|
||||||
."customClientNames "
|
."customClientNames "
|
||||||
|
."isUDM:0,1 "
|
||||||
# ."readClientInsights "
|
# ."readClientInsights "
|
||||||
.$readingFnAttributes;
|
.$readingFnAttributes;
|
||||||
|
|
||||||
@@ -210,6 +213,8 @@ sub Unifi_Define($$) {
|
|||||||
eventPeriod => int(AttrVal($name,"eventPeriod",24)),
|
eventPeriod => int(AttrVal($name,"eventPeriod",24)),
|
||||||
interval => $a[6] || 30,
|
interval => $a[6] || 30,
|
||||||
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').'/',
|
||||||
|
ucurl => "https://".$a[2].(($a[3] == 443) ? '' : ':'.$a[3]).'/api/s/'.(($a[7]) ? $a[7] : 'default').'/',
|
||||||
|
udmurl => "https://".$a[2].(($a[3] == 443) ? '' : ':'.$a[3]).'/proxy/network/api/s/'.(($a[7]) ? $a[7] : 'default').'/',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
$hash->{httpParams} = {
|
$hash->{httpParams} = {
|
||||||
@@ -277,36 +282,6 @@ sub Unifi_Notify($$) {
|
|||||||
if($dev->{NAME} eq "global"){ #INITIALIZED|REREADCFG
|
if($dev->{NAME} eq "global"){ #INITIALIZED|REREADCFG
|
||||||
$hash->{unifi}->{customClientReadings}->{attr_value} = AttrVal($name,"customClientReadings",$defaultClientReadings);
|
$hash->{unifi}->{customClientReadings}->{attr_value} = AttrVal($name,"customClientReadings",$defaultClientReadings);
|
||||||
Unifi_initCustomClientReadings($hash);
|
Unifi_initCustomClientReadings($hash);
|
||||||
|
|
||||||
|
|
||||||
# TODO: der folgende Block kann Ende 2019 entfernt werden. Es ist der alte Restore-Mechanismus
|
|
||||||
# Dieser wurde ersetzt durch de restore von mac-Adressen und anschlie<69>endem updateClient in doUpdate()
|
|
||||||
#for my $readingName (keys %{$hash->{READINGS}}) {
|
|
||||||
# #Log3 $name, 1, "$name ($self) - checking 1 $readingName";
|
|
||||||
# if($readingName =~ m/\..*_id$/){
|
|
||||||
# #Log3 $name, 1, "$name ($self) - found 1 $readingName";
|
|
||||||
# my $readingValue=ReadingsVal($name,$readingName,"");
|
|
||||||
# if($readingValue =~ m/^[a-fA-F0-9]*$/g){
|
|
||||||
# my $clientName=substr($readingName,1,index($readingName,"_id")-1);
|
|
||||||
# $hash->{clients}->{$readingValue}->{name} = $clientName;
|
|
||||||
# Log3 $name, 5, "$name ($self) - restored client $clientName with ID $readingValue";
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
#}
|
|
||||||
#for my $clientID (keys %{$hash->{clients}}) {
|
|
||||||
# my $clientName=$hash->{clients}->{$clientID}->{name}."_";
|
|
||||||
# # TODO: Pr<50>fen, ob es f<>r $clientName ein UnifiClient-Devices gibt und die Werte aus den Readings des UnifiClients wiederherstellen.
|
|
||||||
# for my $readingName (keys %{$hash->{READINGS}}) {
|
|
||||||
# #Log3 $name, 1, "$name ($self) - checking 2 $readingName for $clientName";
|
|
||||||
# if($readingName =~ m/^$clientName.*/){
|
|
||||||
# #Log3 $name, 1, "$name ($self) - found 2 $readingName";
|
|
||||||
# my $readingValue=ReadingsVal($name,$readingName,"");
|
|
||||||
# my $readingName=substr($readingName,length($clientName));
|
|
||||||
# $hash->{clients}->{$clientID}->{$readingName} = $readingValue;
|
|
||||||
# Log3 $name, 5, "$name ($self) - restored internal $readingName = $readingValue for client $clientName";
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
#}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@@ -784,6 +759,14 @@ sub Unifi_Attr(@) {
|
|||||||
elsif($attr_name eq "customClientNames") {
|
elsif($attr_name eq "customClientNames") {
|
||||||
$hash->{unifi}->{customClientNames}->{attr_value} = $attr_value;
|
$hash->{unifi}->{customClientNames}->{attr_value} = $attr_value;
|
||||||
}
|
}
|
||||||
|
elsif($attr_name eq "isUDM") {
|
||||||
|
$hash->{unifi}->{isUDM}->{attr_value} = $attr_value;
|
||||||
|
if($attr_value==1){
|
||||||
|
$hash->{unifi}->{url} = $hash->{unifi}->{udmurl};
|
||||||
|
}else{
|
||||||
|
$hash->{unifi}->{url} = $hash->{unifi}->{ucurl};
|
||||||
|
}
|
||||||
|
}
|
||||||
#elsif($attr_name eq "readClientInsights") {
|
#elsif($attr_name eq "readClientInsights") {
|
||||||
# if (!looks_like_number($attr_value) || int($attr_value) < 1 || int($attr_value) > 365) {
|
# if (!looks_like_number($attr_value) || int($attr_value) < 1 || int($attr_value) > 365) {
|
||||||
# return "$name: Value \"$attr_value\" is not allowed.\n"
|
# return "$name: Value \"$attr_value\" is not allowed.\n"
|
||||||
@@ -814,6 +797,10 @@ sub Unifi_Attr(@) {
|
|||||||
elsif($attr_name eq "customClientNames") {
|
elsif($attr_name eq "customClientNames") {
|
||||||
$hash->{unifi}->{customClientNames}->{attr_value} = $customClientName;
|
$hash->{unifi}->{customClientNames}->{attr_value} = $customClientName;
|
||||||
}
|
}
|
||||||
|
elsif($attr_name eq "isUDM") {
|
||||||
|
$hash->{unifi}->{isUDM}->{attr_value} = 0;
|
||||||
|
$hash->{unifi}->{url} = $hash->{unifi}->{ucurl};
|
||||||
|
}
|
||||||
#elsif($attr_name eq "readClientInsights") {
|
#elsif($attr_name eq "readClientInsights") {
|
||||||
# $hash->{unifi}->{readClientInsights} = undef;
|
# $hash->{unifi}->{readClientInsights} = undef;
|
||||||
#}
|
#}
|
||||||
@@ -850,6 +837,8 @@ sub Unifi_DoUpdate($@) {
|
|||||||
my ($name,$self) = ($hash->{NAME},Unifi_Whoami());
|
my ($name,$self) = ($hash->{NAME},Unifi_Whoami());
|
||||||
Log3 $name, 5, "$name ($self) - executed.";
|
Log3 $name, 5, "$name ($self) - executed.";
|
||||||
|
|
||||||
|
$hash->{VERSION}=$version;
|
||||||
|
|
||||||
if (Unifi_CONNECTED($hash) eq "disabled") {
|
if (Unifi_CONNECTED($hash) eq "disabled") {
|
||||||
Log3 $name, 5, "$name ($self) - Device '$name' is disabled, End now...";
|
Log3 $name, 5, "$name ($self) - Device '$name' is disabled, End now...";
|
||||||
return undef;
|
return undef;
|
||||||
@@ -899,13 +888,18 @@ 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(int(AttrVal($name,"isUDM",0) == 1)){
|
||||||
|
( $loginurl = $hash->{unifi}->{url} ) =~ s/proxy\/network\/api\/s.+/api\/auth\/login/;
|
||||||
|
}else{
|
||||||
( $loginurl = $hash->{unifi}->{url} ) =~ s/api\/s.+/api\/login/;
|
( $loginurl = $hash->{unifi}->{url} ) =~ s/api\/s.+/api\/login/;
|
||||||
$logindata = '{"username":"'.$user.'", "password":"'.$password.'"}';
|
}
|
||||||
|
$logindata = '{"username":"'.$user.'", "password":"'.$password.'", "rememberMe":true}';
|
||||||
|
|
||||||
HttpUtils_NonblockingGet( {
|
HttpUtils_NonblockingGet( {
|
||||||
%{$hash->{httpParams}},
|
%{$hash->{httpParams}},
|
||||||
url => $loginurl,
|
url => $loginurl,
|
||||||
data => $logindata,
|
data => $logindata,
|
||||||
|
header => "Content-Type: application/json",
|
||||||
callback => \&Unifi_Login_Receive
|
callback => \&Unifi_Login_Receive
|
||||||
} );
|
} );
|
||||||
return undef;
|
return undef;
|
||||||
@@ -922,7 +916,7 @@ sub Unifi_Login_Receive($) {
|
|||||||
if ($param->{code} == 200 || $param->{code} == 400 || $param->{code} == 401 || $param->{code} == 200) {
|
if ($param->{code} == 200 || $param->{code} == 400 || $param->{code} == 401 || $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 ($data->{meta}->{rc} eq "ok") {
|
if ($data->{meta}->{rc} eq "ok" || $data->{username} ne '') {
|
||||||
Log3 $name, 5, "$name ($self) - state=ok";
|
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})) {
|
||||||
@@ -1335,6 +1329,7 @@ sub Unifi_GetUnarchivedAlerts_Send($) {
|
|||||||
%{$hash->{httpParams}},
|
%{$hash->{httpParams}},
|
||||||
url => $hash->{unifi}->{url}."list/alarm",
|
url => $hash->{unifi}->{url}."list/alarm",
|
||||||
callback => $hash->{updateDispatch}->{$self}[2],
|
callback => $hash->{updateDispatch}->{$self}[2],
|
||||||
|
method => "GET",
|
||||||
data => "{\"_sort\":\"-time\", \"archived\":false}",
|
data => "{\"_sort\":\"-time\", \"archived\":false}",
|
||||||
} );
|
} );
|
||||||
return undef;
|
return undef;
|
||||||
@@ -1375,6 +1370,7 @@ sub Unifi_GetEvents_Send($) {
|
|||||||
%{$hash->{httpParams}},
|
%{$hash->{httpParams}},
|
||||||
url => $hash->{unifi}->{url}."stat/event",
|
url => $hash->{unifi}->{url}."stat/event",
|
||||||
callback => $hash->{updateDispatch}->{$self}[2],
|
callback => $hash->{updateDispatch}->{$self}[2],
|
||||||
|
method => "GET",
|
||||||
data => "{\"_sort\":\"-time\", \"within\":".$hash->{unifi}->{eventPeriod}."}", # last 24 hours
|
data => "{\"_sort\":\"-time\", \"within\":".$hash->{unifi}->{eventPeriod}."}", # last 24 hours
|
||||||
} );
|
} );
|
||||||
return undef;
|
return undef;
|
||||||
@@ -1416,6 +1412,7 @@ sub Unifi_GetAccesspoints_Send($) { # TODO Umbenennen in Unifi_GetDevices_Send.
|
|||||||
%{$hash->{httpParams}},
|
%{$hash->{httpParams}},
|
||||||
url => $hash->{unifi}->{url}."stat/device",
|
url => $hash->{unifi}->{url}."stat/device",
|
||||||
callback => $hash->{updateDispatch}->{$self}[2],
|
callback => $hash->{updateDispatch}->{$self}[2],
|
||||||
|
method => "GET",
|
||||||
data => "{\"_depth\":2, \"test\":0}",
|
data => "{\"_depth\":2, \"test\":0}",
|
||||||
} );
|
} );
|
||||||
return undef;
|
return undef;
|
||||||
@@ -1438,7 +1435,7 @@ sub Unifi_GetAccesspoints_Receive($) {# TODO Umbenennen in Unifi_GetDevices_Rece
|
|||||||
for my $h (@{$data->{data}}) {
|
for my $h (@{$data->{data}}) {
|
||||||
$hash->{accespoints}->{$h->{_id}} = $h;
|
$hash->{accespoints}->{$h->{_id}} = $h;
|
||||||
#TODO: Switch-Modelle anders festlegen ? Oder passt usw?
|
#TODO: Switch-Modelle anders festlegen ? Oder passt usw?
|
||||||
if (defined $h->{model} && $h->{type} eq "usw"){
|
if (defined $h->{type} && (($h->{type} eq "usw") || ($h->{type} eq "udm"))){
|
||||||
my $usw_name="";
|
my $usw_name="";
|
||||||
if (defined $h->{name}){
|
if (defined $h->{name}){
|
||||||
$usw_name=makeDeviceName($h->{name});
|
$usw_name=makeDeviceName($h->{name});
|
||||||
@@ -2655,8 +2652,13 @@ Or you can use the other readings or set and get features to control your unifi-
|
|||||||
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> <br>
|
</ul>
|
||||||
|
UDM?
|
||||||
|
<ul>
|
||||||
|
<code>If you use an UDM as Controller:<br>
|
||||||
|
Additionally set Attribute isUDM to 1.</code><br>
|
||||||
|
</ul>
|
||||||
|
<br>
|
||||||
</ul>
|
</ul>
|
||||||
<h4>Examples</h4>
|
<h4>Examples</h4>
|
||||||
<ul>
|
<ul>
|
||||||
@@ -2815,6 +2817,10 @@ Or you can use the other readings or set and get features to control your unifi-
|
|||||||
</ol>
|
</ol>
|
||||||
</li>
|
</li>
|
||||||
<br>
|
<br>
|
||||||
|
<li>attr isUDM <0,1><br>
|
||||||
|
Informs the module that the Unifi-Controller API is provided by an UDM if set to 1.<br>
|
||||||
|
<code>default: 0</code></li>
|
||||||
|
<br>
|
||||||
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
|
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|||||||
@@ -29,12 +29,14 @@
|
|||||||
# - fixed: 74_UnifiSwitch: Log-Messages
|
# - fixed: 74_UnifiSwitch: Log-Messages
|
||||||
# V 0.0.97
|
# V 0.0.97
|
||||||
# - fixed: 74_UnifiSwitch: new readings for general_temperature, overheating, fan_level, cpu and mem
|
# - fixed: 74_UnifiSwitch: new readings for general_temperature, overheating, fan_level, cpu and mem
|
||||||
|
# V 1.0.00
|
||||||
|
# - fixed: 74_UnifiSwitch: supports UDM-Switch
|
||||||
#
|
#
|
||||||
# TODOs:
|
# TODOs:
|
||||||
# - state des USW für weiter state-Numbers korrekt in Worte übersetzen
|
# - state des USW für weiter state-Numbers korrekt in Worte übersetzen
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
my $version="0.0.97";
|
my $version="1.0.00";
|
||||||
# Laden evtl. abhängiger Perl- bzw. FHEM-Module
|
# Laden evtl. abhängiger Perl- bzw. FHEM-Module
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
@@ -292,7 +294,7 @@ sub UnifiSwitch_Parse($$) {
|
|||||||
# Nachricht für $hash verarbeiten
|
# Nachricht für $hash verarbeiten
|
||||||
my $apRef = decode_json($message_json);
|
my $apRef = decode_json($message_json);
|
||||||
$hash->{usw} = $apRef;
|
$hash->{usw} = $apRef;
|
||||||
if( $apRef->{type} eq 'usw' ){
|
if( $apRef->{type} eq 'usw' || $apRef->{type} eq 'udm' ){
|
||||||
if ($apRef->{state} eq "1"){
|
if ($apRef->{state} eq "1"){
|
||||||
$hash->{STATE} = "connected";
|
$hash->{STATE} = "connected";
|
||||||
}elsif($apRef->{state} eq "2"){
|
}elsif($apRef->{state} eq "2"){
|
||||||
|
|||||||
Reference in New Issue
Block a user