Skip to content

Commit

Permalink
Fortios device tracker updates (#92331)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
  • Loading branch information
3 people committed Jun 15, 2023
1 parent a7955e4 commit 562f0d3
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions homeassistant/components/fortios/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_scanner(hass: HomeAssistant, config: ConfigType) -> FortiOSDeviceScanner
fgt = FortiOSAPI()

try:
fgt.tokenlogin(host, token, verify_ssl)
fgt.tokenlogin(host, token, verify_ssl, None, 12, "root")
except ConnectionError as ex:
_LOGGER.error("ConnectionError to FortiOS API: %s", ex)
return None
Expand Down Expand Up @@ -77,16 +77,25 @@ def __init__(self, fgt) -> None:

def update(self):
"""Update clients from the device."""
clients_json = self._fgt.monitor("user/device/query", "")
clients_json = self._fgt.monitor(
"user/device/query",
"",
parameters={"filter": "format=master_mac|hostname|is_online"},
)

self._clients_json = clients_json

self._clients = []

if clients_json:
try:
for client in clients_json["results"]:
if client["is_online"]:
self._clients.append(client["mac"].upper())
if (
"is_online" in client
and "master_mac" in client
and client["is_online"]
):
self._clients.append(client["master_mac"].upper())
except KeyError as kex:
_LOGGER.error("Key not found in clients: %s", kex)

Expand All @@ -106,17 +115,10 @@ def get_device_name(self, device):
return None

for client in data["results"]:
if client["mac"] == device:
try:
if "master_mac" in client and client["master_mac"] == device:
if "hostname" in client:
name = client["hostname"]
_LOGGER.debug("Getting device name=%s", name)
return name
except KeyError as kex:
_LOGGER.debug(
"No hostname found for %s in client data: %s",
device,
kex,
)
return device.replace(":", "_")

else:
name = client["master_mac"].replace(":", "_")
return name
return None

0 comments on commit 562f0d3

Please sign in to comment.