mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-07 16:04:29 +02:00
Added client count sensors for wired and wireless hosts, fixes #69
This commit is contained in:
parent
9cc4921658
commit
5badbc9053
2 changed files with 41 additions and 0 deletions
|
@ -1303,6 +1303,8 @@ class MikrotikControllerData:
|
||||||
ensure_vals=[
|
ensure_vals=[
|
||||||
{"name": "uptime", "default": 0},
|
{"name": "uptime", "default": 0},
|
||||||
{"name": "uptime_epoch", "default": 0},
|
{"name": "uptime_epoch", "default": 0},
|
||||||
|
{"name": "clients_wired", "default": 0},
|
||||||
|
{"name": "clients_wireless", "default": 0},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1804,6 +1806,8 @@ class MikrotikControllerData:
|
||||||
await self.async_ping_tracked_hosts(utcnow())
|
await self.async_ping_tracked_hosts(utcnow())
|
||||||
|
|
||||||
# Process hosts
|
# Process hosts
|
||||||
|
self.data["resource"]["clients_wired"] = 0
|
||||||
|
self.data["resource"]["clients_wireless"] = 0
|
||||||
for uid, vals in self.data["host"].items():
|
for uid, vals in self.data["host"].items():
|
||||||
# CAPS-MAN availability
|
# CAPS-MAN availability
|
||||||
if vals["source"] == "capsman" and uid not in capsman_detected:
|
if vals["source"] == "capsman" and uid not in capsman_detected:
|
||||||
|
@ -1899,6 +1903,13 @@ class MikrotikControllerData:
|
||||||
if vals["manufacturer"] == "detect":
|
if vals["manufacturer"] == "detect":
|
||||||
self.data["host"][uid]["manufacturer"] = ""
|
self.data["host"][uid]["manufacturer"] = ""
|
||||||
|
|
||||||
|
# Count hosts
|
||||||
|
if self.data["host"][uid]["available"]:
|
||||||
|
if vals["source"] in ["capsman", "wireless"]:
|
||||||
|
self.data["resource"]["clients_wireless"] += 1
|
||||||
|
else:
|
||||||
|
self.data["resource"]["clients_wired"] += 1
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# process_accounting
|
# process_accounting
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
|
@ -247,6 +247,36 @@ SENSOR_TYPES = {
|
||||||
data_uid="",
|
data_uid="",
|
||||||
data_reference="",
|
data_reference="",
|
||||||
),
|
),
|
||||||
|
"system_clients-wired": MikrotikSensorEntityDescription(
|
||||||
|
key="system_clients-wired",
|
||||||
|
name="Wired Clients",
|
||||||
|
icon="mdi:lan",
|
||||||
|
native_unit_of_measurement=None,
|
||||||
|
device_class=None,
|
||||||
|
state_class=None,
|
||||||
|
entity_category=None,
|
||||||
|
ha_group="System",
|
||||||
|
data_path="resource",
|
||||||
|
data_attribute="clients_wired",
|
||||||
|
data_name="",
|
||||||
|
data_uid="",
|
||||||
|
data_reference="",
|
||||||
|
),
|
||||||
|
"system_clients-wireless": MikrotikSensorEntityDescription(
|
||||||
|
key="system_clients-wireless",
|
||||||
|
name="Wireless Clients",
|
||||||
|
icon="mdi:wifi",
|
||||||
|
native_unit_of_measurement=None,
|
||||||
|
device_class=None,
|
||||||
|
state_class=None,
|
||||||
|
entity_category=None,
|
||||||
|
ha_group="System",
|
||||||
|
data_path="resource",
|
||||||
|
data_attribute="clients_wireless",
|
||||||
|
data_name="",
|
||||||
|
data_uid="",
|
||||||
|
data_reference="",
|
||||||
|
),
|
||||||
"traffic_tx": MikrotikSensorEntityDescription(
|
"traffic_tx": MikrotikSensorEntityDescription(
|
||||||
key="traffic_tx",
|
key="traffic_tx",
|
||||||
name="TX",
|
name="TX",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue