mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-08 08:24:30 +02:00
Added PPP user connection tracker #76
This commit is contained in:
parent
8cf577b780
commit
53f2f63a73
1 changed files with 91 additions and 5 deletions
|
@ -24,6 +24,8 @@ from .const import (
|
||||||
DEFAULT_TRACK_HOST_TIMEOUT,
|
DEFAULT_TRACK_HOST_TIMEOUT,
|
||||||
CONF_SENSOR_PORT_TRACKER,
|
CONF_SENSOR_PORT_TRACKER,
|
||||||
DEFAULT_SENSOR_PORT_TRACKER,
|
DEFAULT_SENSOR_PORT_TRACKER,
|
||||||
|
CONF_SENSOR_PPP,
|
||||||
|
DEFAULT_SENSOR_PPP,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -54,6 +56,15 @@ DEVICE_ATTRIBUTES_HOST = [
|
||||||
"last-seen",
|
"last-seen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
DEVICE_ATTRIBUTES_PPP_SECRET = [
|
||||||
|
"connected",
|
||||||
|
"service",
|
||||||
|
"profile",
|
||||||
|
"comment",
|
||||||
|
"caller-id",
|
||||||
|
"encoding",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# format_attribute
|
# format_attribute
|
||||||
|
@ -115,15 +126,19 @@ def update_items(inst, config_entry, mikrotik_controller, async_add_entities, tr
|
||||||
# Add switches
|
# Add switches
|
||||||
for sid, sid_uid, sid_name, sid_ref, sid_func in zip(
|
for sid, sid_uid, sid_name, sid_ref, sid_func in zip(
|
||||||
# Data point name
|
# Data point name
|
||||||
["interface", "host"],
|
["interface", "host", "ppp_secret"],
|
||||||
# Data point unique id
|
# Data point unique id
|
||||||
["default-name", "mac-address"],
|
["default-name", "mac-address", "name"],
|
||||||
# Entry Name
|
# Entry Name
|
||||||
["name", "host-name"],
|
["name", "host-name", "name"],
|
||||||
# Entry Unique id
|
# Entry Unique id
|
||||||
["port-mac-address", "mac-address"],
|
["port-mac-address", "mac-address", "name"],
|
||||||
# Tracker function
|
# Tracker function
|
||||||
[MikrotikControllerPortDeviceTracker, MikrotikControllerHostDeviceTracker],
|
[
|
||||||
|
MikrotikControllerPortDeviceTracker,
|
||||||
|
MikrotikControllerHostDeviceTracker,
|
||||||
|
MikrotikControllerPPPSecretDeviceTracker,
|
||||||
|
],
|
||||||
):
|
):
|
||||||
if (
|
if (
|
||||||
sid_func == MikrotikControllerPortDeviceTracker
|
sid_func == MikrotikControllerPortDeviceTracker
|
||||||
|
@ -410,3 +425,74 @@ class MikrotikControllerHostDeviceTracker(MikrotikControllerDeviceTracker):
|
||||||
info["name"] = f"{self._inst} {self._data[self._sid_data['sid_name']]}"
|
info["name"] = f"{self._inst} {self._data[self._sid_data['sid_name']]}"
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------
|
||||||
|
# MikrotikControllerPPPSecretDeviceTracker
|
||||||
|
# ---------------------------
|
||||||
|
class MikrotikControllerPPPSecretDeviceTracker(MikrotikControllerDeviceTracker):
|
||||||
|
"""Representation of a network device."""
|
||||||
|
|
||||||
|
def __init__(self, inst, uid, mikrotik_controller, config_entry, sid_data):
|
||||||
|
"""Set up tracked port."""
|
||||||
|
super().__init__(inst, uid, mikrotik_controller, config_entry, sid_data)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def option_sensor_ppp(self):
|
||||||
|
"""Config entry option to not track ARP."""
|
||||||
|
return self._config_entry.options.get(CONF_SENSOR_PPP, DEFAULT_SENSOR_PPP)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
"""Return the name of the port."""
|
||||||
|
return f"{self._inst} PPP {self._data['name']}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_connected(self):
|
||||||
|
"""Return true if the host is connected to the network."""
|
||||||
|
if not self.option_sensor_ppp:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return self._data["connected"]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self) -> bool:
|
||||||
|
"""Return if controller is available."""
|
||||||
|
if not self.option_sensor_ppp:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return self._ctrl.connected()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
"""Return a unique identifier for this port."""
|
||||||
|
return f"{self._inst.lower()}-{self._sid_data['sid']}_tracker-{self._data[self._sid_data['sid_ref']]}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def icon(self):
|
||||||
|
"""Return the icon."""
|
||||||
|
if self._data["connected"]:
|
||||||
|
return "mdi:account-network-outline"
|
||||||
|
else:
|
||||||
|
return "mdi:account-off-outline"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_state_attributes(self):
|
||||||
|
"""Return the port state attributes."""
|
||||||
|
attributes = self._attrs
|
||||||
|
for variable in DEVICE_ATTRIBUTES_IFACE:
|
||||||
|
if variable in self._data:
|
||||||
|
attributes[format_attribute(variable)] = self._data[variable]
|
||||||
|
|
||||||
|
return attributes
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_info(self):
|
||||||
|
"""Return a description for device registry."""
|
||||||
|
info = {
|
||||||
|
"connections": {
|
||||||
|
(CONNECTION_NETWORK_MAC, self._data[self._sid_data["sid_ref"]])
|
||||||
|
},
|
||||||
|
"name": self._data[self._sid_data["sid_name"]],
|
||||||
|
}
|
||||||
|
return info
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue