mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-19 18:56:03 +00:00
74_Unifi: new cattribute customClientNames
git-svn-id: https://svn.fhem.de/fhem/trunk@19030 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
22ed6a08b5
commit
28119fcb3b
@ -50,12 +50,15 @@
|
|||||||
# - feature: 74_Unifi: textField-long support for customClientReadings
|
# - feature: 74_Unifi: textField-long support for customClientReadings
|
||||||
# V 3.2.3
|
# V 3.2.3
|
||||||
# - feature: 74_Unifi: new customClientReading _f_last_seen_duration
|
# - feature: 74_Unifi: new customClientReading _f_last_seen_duration
|
||||||
|
# V 3.2.4
|
||||||
|
# - feature: 74_Unifi: new cattribute customClientNames
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
my $version="3.2.3";
|
my $version="3.2.4";
|
||||||
# Default für clientRedings setzen. Die Readings waren der Standard vor Einführung des Attributes customClientReadings.
|
# Default für clientRedings setzen. Die Readings waren der Standard vor Einführung des Attributes customClientReadings.
|
||||||
# Eine Änderung hat Auswirkungen auf (alte) Moduldefinitionen ohne dieses Attribut.
|
# Eine Ä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 ;-)
|
||||||
|
my $customClientName="";
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use HttpUtils;
|
use HttpUtils;
|
||||||
@ -148,6 +151,7 @@ sub Unifi_Initialize($$) {
|
|||||||
."eventPeriod "
|
."eventPeriod "
|
||||||
."voucherCache "
|
."voucherCache "
|
||||||
."customClientReadings:textField-long "
|
."customClientReadings:textField-long "
|
||||||
|
."customClientNames "
|
||||||
.$readingFnAttributes;
|
.$readingFnAttributes;
|
||||||
|
|
||||||
$hash->{Clients} = "UnifiSwitch";
|
$hash->{Clients} = "UnifiSwitch";
|
||||||
@ -624,6 +628,9 @@ sub Unifi_Attr(@) {
|
|||||||
$hash->{unifi}->{customClientReadings}->{attr_value} = $attr_value;
|
$hash->{unifi}->{customClientReadings}->{attr_value} = $attr_value;
|
||||||
Unifi_initCustomClientReadings($hash);
|
Unifi_initCustomClientReadings($hash);
|
||||||
}
|
}
|
||||||
|
elsif($attr_name eq "customClientNames") {
|
||||||
|
$hash->{unifi}->{customClientNames}->{attr_value} = $attr_value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elsif($cmd eq "del") {
|
elsif($cmd eq "del") {
|
||||||
if($attr_name eq "disable" && Unifi_CONNECTED($hash) eq "disabled") {
|
if($attr_name eq "disable" && Unifi_CONNECTED($hash) eq "disabled") {
|
||||||
@ -644,6 +651,9 @@ sub Unifi_Attr(@) {
|
|||||||
$hash->{unifi}->{customClientReadings}->{attr_value} = $defaultClientReadings;
|
$hash->{unifi}->{customClientReadings}->{attr_value} = $defaultClientReadings;
|
||||||
Unifi_initCustomClientReadings($hash);
|
Unifi_initCustomClientReadings($hash);
|
||||||
}
|
}
|
||||||
|
elsif($attr_name eq "customClientNames") {
|
||||||
|
$hash->{unifi}->{customClientNames}->{attr_value} = $customClientName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -1253,11 +1263,11 @@ sub Unifi_SetClientReadings($) {
|
|||||||
|
|
||||||
|
|
||||||
if (defined $hash->{unifi}->{connectedClients}->{$clientID}) {
|
if (defined $hash->{unifi}->{connectedClients}->{$clientID}) {
|
||||||
|
|
||||||
if (! defined ReadingsVal($hash->{NAME},$clientName,undef)){
|
if (! defined ReadingsVal($hash->{NAME},$clientName,undef)){
|
||||||
$newClients.=$sep.$clientName;
|
$newClients.=$sep.$clientName;
|
||||||
$sep=",";
|
$sep=",";
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsBulkUpdate($hash,$clientName,'connected');
|
readingsBulkUpdate($hash,$clientName,'connected');
|
||||||
|
|
||||||
# altes Standardverhalten kann man auch ohne RegEx-Auswertungen beibehalten
|
# altes Standardverhalten kann man auch ohne RegEx-Auswertungen beibehalten
|
||||||
@ -1852,16 +1862,21 @@ sub Unifi_ClientNames($@) {
|
|||||||
|
|
||||||
my $clientRef;
|
my $clientRef;
|
||||||
my $devAliases = AttrVal($hash->{NAME},"devAlias",0);
|
my $devAliases = AttrVal($hash->{NAME},"devAlias",0);
|
||||||
|
my $attrCustomClientNames = AttrVal($hash->{NAME},"customClientNames",0);
|
||||||
|
|
||||||
if(defined $ID && defined $W && $W eq 'makeAlias') { # Return Alias from ID
|
if(defined $ID && defined $W && $W eq 'makeAlias') { # Return Alias from ID
|
||||||
$clientRef = $hash->{clients}->{$ID};
|
$clientRef = $hash->{clients}->{$ID};
|
||||||
if ( ($devAliases && $devAliases =~ /$ID:(.+?)(\s|$)/)
|
if ( ($devAliases && $devAliases =~ /$ID:(.+?)(\s|$)/)
|
||||||
|| ($devAliases && defined $clientRef->{name} && $devAliases =~ /$clientRef->{name}:(.+?)(\s|$)/)
|
|| ($devAliases && defined $clientRef->{name} && $devAliases =~ /$clientRef->{name}:(.+?)(\s|$)/)
|
||||||
|| ($devAliases && defined $clientRef->{hostname} && $devAliases =~ /$clientRef->{hostname}:(.+?)(\s|$)/)
|
|| ($devAliases && defined $clientRef->{hostname} && $devAliases =~ /$clientRef->{hostname}:(.+?)(\s|$)/)
|
||||||
|| (defined $clientRef->{name} && $clientRef->{name} =~ /^([\w\.\-]+)$/)
|
|
||||||
|| (defined $clientRef->{hostname} && $clientRef->{hostname} =~ /^([\w\.\-]+)$/)
|
|
||||||
) {
|
) {
|
||||||
$ID = $1;
|
$ID = $1;
|
||||||
|
}elsif ( $attrCustomClientNames && defined $clientRef->{$attrCustomClientNames}){
|
||||||
|
$ID = makeReadingName($clientRef->{$attrCustomClientNames});
|
||||||
|
}elsif ( (defined $clientRef->{name} && $clientRef->{name} =~ /^([\w\.\-]+)$/)
|
||||||
|
|| (defined $clientRef->{hostname} && $clientRef->{hostname} =~ /^([\w\.\-]+)$/)
|
||||||
|
){
|
||||||
|
$ID = $1;
|
||||||
}
|
}
|
||||||
return $ID;
|
return $ID;
|
||||||
}
|
}
|
||||||
@ -1873,7 +1888,13 @@ sub Unifi_ClientNames($@) {
|
|||||||
if ( ($devAliases && $devAliases =~ /$clientID:$ID/)
|
if ( ($devAliases && $devAliases =~ /$clientID:$ID/)
|
||||||
|| ($devAliases && defined $clientRef->{name} && ($devAliases =~ /$clientRef->{name}:$ID/ || $devAliases =~ /$goodName:$ID/) )
|
|| ($devAliases && defined $clientRef->{name} && ($devAliases =~ /$clientRef->{name}:$ID/ || $devAliases =~ /$goodName:$ID/) )
|
||||||
|| ($devAliases && defined $clientRef->{hostname} && ($devAliases =~ /$clientRef->{hostname}:$ID/ || $devAliases =~ /$goodHostname:$ID/) )
|
|| ($devAliases && defined $clientRef->{hostname} && ($devAliases =~ /$clientRef->{hostname}:$ID/ || $devAliases =~ /$goodHostname:$ID/) )
|
||||||
|| (defined $clientRef->{name} && ($clientRef->{name} eq $ID || $goodName eq $ID) )
|
) {
|
||||||
|
$ID = $clientID;
|
||||||
|
last;
|
||||||
|
}elsif ( $attrCustomClientNames && defined $clientRef->{$attrCustomClientNames} && $ID eq makeReadingName($clientRef->{$attrCustomClientNames})){
|
||||||
|
$ID = $clientID;
|
||||||
|
last;
|
||||||
|
} elsif ( (defined $clientRef->{name} && ($clientRef->{name} eq $ID || $goodName eq $ID) )
|
||||||
|| (defined $clientRef->{hostname} && ($clientRef->{hostname} eq $ID || $goodHostname eq $ID) )
|
|| (defined $clientRef->{hostname} && ($clientRef->{hostname} eq $ID || $goodHostname eq $ID) )
|
||||||
) {
|
) {
|
||||||
$ID = $clientID;
|
$ID = $clientID;
|
||||||
@ -2370,6 +2391,17 @@ Or you can use the other readings or set and get features to control your unifi-
|
|||||||
Can be used to customize the readings for clients. <br>
|
Can be used to customize the readings for clients. <br>
|
||||||
<code>default: .:^accesspoint$|^essid$|^hostname$|^last_seen$|^snr$|^uptime$</code> Note: rssi ist called snr in old default before attr customClientReadings.</li>
|
<code>default: .:^accesspoint$|^essid$|^hostname$|^last_seen$|^snr$|^uptime$</code> Note: rssi ist called snr in old default before attr customClientReadings.</li>
|
||||||
<br>
|
<br>
|
||||||
|
<li>attr customClientNames <value><br>
|
||||||
|
Can be used to control the naming convention for client readings. Any valid clientData field is allowed, though only <code>mac</code> seems to be useful. For a list, see <code><unifi> get ClientData all</code>.<br>
|
||||||
|
Client naming follows these rules:
|
||||||
|
<ol>
|
||||||
|
<li><code>devAlias</code> (if present for this client)</li>
|
||||||
|
<li>attribute <code>customClientNames</code> (if it is set <i>and</i> the corresponding data field exists for client)</li>
|
||||||
|
<li>name (alias) in Unifi-Controller</li>
|
||||||
|
<li>hostname of the client</li>
|
||||||
|
</ol>
|
||||||
|
</li>
|
||||||
|
<br>
|
||||||
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
|
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user