mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-06-26 02:38:47 +02:00
Added support for captive portal authorization data #200
This commit is contained in:
parent
39498f073b
commit
9f19740c92
6 changed files with 76 additions and 1 deletions
|
@ -41,6 +41,8 @@ from .const import (
|
|||
DEFAULT_SENSOR_PORT_TRAFFIC,
|
||||
CONF_SENSOR_CLIENT_TRAFFIC,
|
||||
DEFAULT_SENSOR_CLIENT_TRAFFIC,
|
||||
CONF_SENSOR_CLIENT_CAPTIVE,
|
||||
DEFAULT_SENSOR_CLIENT_CAPTIVE,
|
||||
CONF_SENSOR_SIMPLE_QUEUES,
|
||||
DEFAULT_SENSOR_SIMPLE_QUEUES,
|
||||
CONF_SENSOR_NAT,
|
||||
|
@ -130,6 +132,7 @@ class MikrotikControllerData:
|
|||
"wireless_hosts": {},
|
||||
"host": {},
|
||||
"host_hass": {},
|
||||
"hostspot_host": {},
|
||||
"client_traffic": {},
|
||||
"environment": {},
|
||||
}
|
||||
|
@ -231,6 +234,16 @@ class MikrotikControllerData:
|
|||
CONF_SENSOR_CLIENT_TRAFFIC, DEFAULT_SENSOR_CLIENT_TRAFFIC
|
||||
)
|
||||
|
||||
# ---------------------------
|
||||
# option_sensor_client_captive
|
||||
# ---------------------------
|
||||
@property
|
||||
def option_sensor_client_captive(self):
|
||||
"""Config entry option to not track ARP."""
|
||||
return self.config_entry.options.get(
|
||||
CONF_SENSOR_CLIENT_CAPTIVE, DEFAULT_SENSOR_CLIENT_CAPTIVE
|
||||
)
|
||||
|
||||
# ---------------------------
|
||||
# option_sensor_simple_queues
|
||||
# ---------------------------
|
||||
|
@ -637,6 +650,9 @@ class MikrotikControllerData:
|
|||
elif 0 < self.major_fw_version >= 7:
|
||||
await self.hass.async_add_executor_job(self.process_kid_control_devices)
|
||||
|
||||
if self.api.connected() and self.option_sensor_client_captive:
|
||||
await self.hass.async_add_executor_job(self.get_captive)
|
||||
|
||||
if self.api.connected() and self.option_sensor_simple_queues:
|
||||
await self.hass.async_add_executor_job(self.get_queue)
|
||||
|
||||
|
@ -1501,6 +1517,32 @@ class MikrotikControllerData:
|
|||
],
|
||||
)
|
||||
|
||||
# ---------------------------
|
||||
# get_captive
|
||||
# ---------------------------
|
||||
def get_captive(self):
|
||||
"""Get list of all environment variables from Mikrotik"""
|
||||
self.data["hostspot_host"] = parse_api(
|
||||
data={},
|
||||
source=self.api.path("/ip/hotspot/host"),
|
||||
key="mac-address",
|
||||
vals=[
|
||||
{"name": "mac-address"},
|
||||
{
|
||||
"name": "authorized",
|
||||
"source": "disabled",
|
||||
"type": "bool",
|
||||
"reverse": True,
|
||||
},
|
||||
{
|
||||
"name": "bypassed",
|
||||
"source": "disabled",
|
||||
"type": "bool",
|
||||
"reverse": True,
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
# ---------------------------
|
||||
# get_queue
|
||||
# ---------------------------
|
||||
|
@ -1877,6 +1919,20 @@ class MikrotikControllerData:
|
|||
self.data["resource"]["clients_wired"] = 0
|
||||
self.data["resource"]["clients_wireless"] = 0
|
||||
for uid, vals in self.data["host"].items():
|
||||
# Captive portal data
|
||||
if self.option_sensor_client_captive:
|
||||
if uid in self.data["hostspot_host"]:
|
||||
self.data["host"][uid]["authorized"] = self.data["hostspot_host"][
|
||||
"authorized"
|
||||
]
|
||||
self.data["host"][uid]["bypassed"] = self.data["hostspot_host"][
|
||||
"bypassed"
|
||||
]
|
||||
else:
|
||||
if "authorized" in self.data["host"][uid]:
|
||||
del self.data["host"][uid]["authorized"]
|
||||
del self.data["host"][uid]["bypassed"]
|
||||
|
||||
# CAPS-MAN availability
|
||||
if vals["source"] == "capsman" and uid not in capsman_detected:
|
||||
self.data["host"][uid]["available"] = False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue