From e14d018b20d54873be8ca75d7e14032f8553e90a Mon Sep 17 00:00:00 2001 From: Tomaae <23486452+tomaae@users.noreply.github.com> Date: Sat, 25 Jun 2022 15:18:00 +0200 Subject: [PATCH] Added captive portal authorized clients count #200 --- .../mikrotik_router/mikrotik_controller.py | 8 ++++++++ custom_components/mikrotik_router/sensor_types.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/custom_components/mikrotik_router/mikrotik_controller.py b/custom_components/mikrotik_router/mikrotik_controller.py index 6300738..e7ef06a 100644 --- a/custom_components/mikrotik_router/mikrotik_controller.py +++ b/custom_components/mikrotik_router/mikrotik_controller.py @@ -1381,6 +1381,7 @@ class MikrotikControllerData: {"name": "uptime_epoch", "default": 0}, {"name": "clients_wired", "default": 0}, {"name": "clients_wireless", "default": 0}, + {"name": "captive_authorized", "default": 0}, ], ) @@ -1547,6 +1548,13 @@ class MikrotikControllerData: ], ) + auth_hosts = sum( + 1 + for uid in self.data["hostspot_host"] + if self.data["hostspot_host"][uid]["authorized"] + ) + self.data["resource"]["captive_authorized"] = auth_hosts + # --------------------------- # get_queue # --------------------------- diff --git a/custom_components/mikrotik_router/sensor_types.py b/custom_components/mikrotik_router/sensor_types.py index 51a8068..1a6f98f 100644 --- a/custom_components/mikrotik_router/sensor_types.py +++ b/custom_components/mikrotik_router/sensor_types.py @@ -286,6 +286,21 @@ SENSOR_TYPES = { data_uid="", data_reference="", ), + "system_captive-authorized": MikrotikSensorEntityDescription( + key="system_captive-authorized", + name="Captive Portal Clients", + icon="mdi:key-wireless", + native_unit_of_measurement=None, + device_class=None, + state_class=None, + entity_category=None, + ha_group="System", + data_path="resource", + data_attribute="captive_authorized", + data_name="", + data_uid="", + data_reference="", + ), "traffic_tx": MikrotikSensorEntityDescription( key="traffic_tx", name="TX",