mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Update fortios device tracker to support FortiOS 7.0 (#51640)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
3a2d50fe23
commit
e1538594cd
@ -46,29 +46,50 @@ def get_scanner(hass, config):
|
|||||||
_LOGGER.error("Failed to login to FortiOS API: %s", ex)
|
_LOGGER.error("Failed to login to FortiOS API: %s", ex)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return FortiOSDeviceScanner(fgt)
|
status_json = fgt.monitor("system/status", "")
|
||||||
|
fos_major_version = int(status_json["version"][1])
|
||||||
|
|
||||||
|
if fos_major_version < 6 or fos_major_version > 7:
|
||||||
|
_LOGGER.error(
|
||||||
|
"Unsupported FortiOS version, fos_major_version = %s",
|
||||||
|
fos_major_version,
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
api_url = "user/device/query"
|
||||||
|
if fos_major_version == 6:
|
||||||
|
api_url = "user/device/select"
|
||||||
|
|
||||||
|
return FortiOSDeviceScanner(fgt, fos_major_version, api_url)
|
||||||
|
|
||||||
|
|
||||||
class FortiOSDeviceScanner(DeviceScanner):
|
class FortiOSDeviceScanner(DeviceScanner):
|
||||||
"""This class queries a FortiOS unit for connected devices."""
|
"""This class queries a FortiOS unit for connected devices."""
|
||||||
|
|
||||||
def __init__(self, fgt) -> None:
|
def __init__(self, fgt, fos_major_version, api_url) -> None:
|
||||||
"""Initialize the scanner."""
|
"""Initialize the scanner."""
|
||||||
self._clients = {}
|
self._clients = {}
|
||||||
self._clients_json = {}
|
self._clients_json = {}
|
||||||
self._fgt = fgt
|
self._fgt = fgt
|
||||||
|
self._fos_major_version = fos_major_version
|
||||||
|
self._api_url = api_url
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update clients from the device."""
|
"""Update clients from the device."""
|
||||||
clients_json = self._fgt.monitor("user/device/select", "")
|
clients_json = self._fgt.monitor(self._api_url, "")
|
||||||
self._clients_json = clients_json
|
self._clients_json = clients_json
|
||||||
|
|
||||||
self._clients = []
|
self._clients = []
|
||||||
|
|
||||||
if clients_json:
|
if clients_json:
|
||||||
|
if self._fos_major_version == 6:
|
||||||
for client in clients_json["results"]:
|
for client in clients_json["results"]:
|
||||||
if client["last_seen"] < 180:
|
if client["last_seen"] < 180:
|
||||||
self._clients.append(client["mac"].upper())
|
self._clients.append(client["mac"].upper())
|
||||||
|
elif self._fos_major_version == 7:
|
||||||
|
for client in clients_json["results"]:
|
||||||
|
if client["is_online"]:
|
||||||
|
self._clients.append(client["mac"].upper())
|
||||||
|
|
||||||
def scan_devices(self):
|
def scan_devices(self):
|
||||||
"""Scan for new devices and return a list with found device IDs."""
|
"""Scan for new devices and return a list with found device IDs."""
|
||||||
@ -90,7 +111,11 @@ class FortiOSDeviceScanner(DeviceScanner):
|
|||||||
for client in data["results"]:
|
for client in data["results"]:
|
||||||
if client["mac"] == device:
|
if client["mac"] == device:
|
||||||
try:
|
try:
|
||||||
|
name = ""
|
||||||
|
if self._fos_major_version == 6:
|
||||||
name = client["host"]["name"]
|
name = client["host"]["name"]
|
||||||
|
elif self._fos_major_version == 7:
|
||||||
|
name = client["hostname"]
|
||||||
_LOGGER.debug("Getting device name=%s", name)
|
_LOGGER.debug("Getting device name=%s", name)
|
||||||
return name
|
return name
|
||||||
except KeyError as kex:
|
except KeyError as kex:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"domain": "fortios",
|
"domain": "fortios",
|
||||||
"name": "FortiOS",
|
"name": "FortiOS",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/fortios/",
|
"documentation": "https://www.home-assistant.io/integrations/fortios/",
|
||||||
"requirements": ["fortiosapi==0.10.8"],
|
"requirements": ["fortiosapi==1.0.5"],
|
||||||
"codeowners": ["@kimfrellsen"],
|
"codeowners": ["@kimfrellsen"],
|
||||||
"iot_class": "local_polling"
|
"iot_class": "local_polling"
|
||||||
}
|
}
|
||||||
|
@ -624,7 +624,7 @@ fnvhash==0.1.0
|
|||||||
foobot_async==1.0.0
|
foobot_async==1.0.0
|
||||||
|
|
||||||
# homeassistant.components.fortios
|
# homeassistant.components.fortios
|
||||||
fortiosapi==0.10.8
|
fortiosapi==1.0.5
|
||||||
|
|
||||||
# homeassistant.components.freebox
|
# homeassistant.components.freebox
|
||||||
freebox-api==0.0.10
|
freebox-api==0.0.10
|
||||||
|
Loading…
x
Reference in New Issue
Block a user