Skip to content

Commit 13cb313

Browse files
authored
Client devices history (#266)
* Add list active devices endpoint * Add list clients history endpoint
1 parent 1d363de commit 13cb313

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/Client.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,45 @@ public function list_clients(?string $mac = null)
10911091
return $this->fetch_results('/api/s/' . $this->site . '/stat/sta/' . $mac);
10921092
}
10931093

1094+
/**
1095+
* Fetch active client devices
1096+
*
1097+
* @param bool $includeTrafficUsage include the traffic usage of the client devices in the response
1098+
* @param bool $includeUnifiDevices include UniFi devices in the response
1099+
* @return array|bool returns an array of active client device objects, false upon error
1100+
* @throws Exception
1101+
*/
1102+
public function list_active_clients(bool $includeTrafficUsage = true, bool $includeUnifiDevices = true)
1103+
{
1104+
$query = http_build_query([
1105+
'includeTrafficUsage' => $includeTrafficUsage,
1106+
'includeUnifiDevices' => $includeUnifiDevices,
1107+
]);
1108+
1109+
return $this->fetch_results('/v2/api/site/' . $this->site . '/clients/active?' . $query);
1110+
}
1111+
1112+
/**
1113+
* Fetch client devices history (offline client devices)
1114+
*
1115+
* @param bool $onlyNonBlocked include non-blocked client devices in the response
1116+
* @param bool $includeUnifiDevices include UniFi devices in the response
1117+
* @param int $withinHours the number of hours a device has been offline to be included in the response
1118+
* (0 = no limit)
1119+
* @return array|bool returns an array of (offline) client device objects, false upon error
1120+
* @throws Exception
1121+
*/
1122+
public function list_clients_history(bool $onlyNonBlocked = true, bool $includeUnifiDevices = true, int $withinHours = 0)
1123+
{
1124+
$query = http_build_query([
1125+
'onlyNonBlocked' => $onlyNonBlocked,
1126+
'includeUnifiDevices' => $includeUnifiDevices,
1127+
'withinHours' => $withinHours,
1128+
]);
1129+
1130+
return $this->fetch_results('/v2/api/site/' . $this->site . '/clients/history?' . $query);
1131+
}
1132+
10941133
/**
10951134
* Fetch details for a single client device
10961135
*

0 commit comments

Comments
 (0)