🔌UNIFI work

This commit is contained in:
jokob-sk
2024-08-05 21:55:11 +10:00
parent 239ebd40b9
commit c21497c61e
2 changed files with 27 additions and 3 deletions

View File

@@ -19,7 +19,7 @@ from pyunifi.controller import Controller
INSTALL_PATH="/app"
sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"])
from plugin_helper import Plugin_Object, Plugin_Objects, rmBadChars
from plugin_helper import Plugin_Object, Plugin_Objects, rmBadChars, is_typical_router_ip
from logger import mylog
from helper import timeNowTZ, get_setting_value
import conf
@@ -158,11 +158,17 @@ def collect_details(device_type, devices, online_macs, processed_macs, plugin_ob
for device in devices:
mylog('verbose', [f'{json.dumps(device)}'])
# try extracting variables from teh json
name = get_name(get_unifi_val(device, 'name'), get_unifi_val(device, 'hostname'))
ipTmp = get_ip(get_unifi_val(device, 'last_ip'), get_unifi_val(device, 'fixed_ip'), get_unifi_val(device, 'ip'))
ipTmp = get_ip(get_unifi_val(device, 'lan_ip'), get_unifi_val(device, 'last_ip'), get_unifi_val(device, 'fixed_ip'), get_unifi_val(device, 'ip'))
macTmp = device['mac']
status = 1 if macTmp in online_macs else device.get('state', 0)
deviceType = device_type.get(device.get('type'), '')
parentMac = get_parent_mac(get_unifi_val(device, 'uplink_mac'), get_unifi_val(device, 'ap_mac'), get_unifi_val(device, 'sw_mac'))
# override parent MAC if this is a router
if parentMac == 'null' and is_typical_router_ip(ipTmp):
parentMac = 'Internet'
# Add object only if not processed
if macTmp not in processed_macs:
@@ -175,7 +181,7 @@ def collect_details(device_type, devices, online_macs, processed_macs, plugin_ob
watched4=status,
extra=get_unifi_val(device, 'connection_network_name', ''),
foreignKey="",
helpVal1=get_parent_mac(get_unifi_val(device, 'uplink_mac'), get_unifi_val(device, 'ap_mac'), get_unifi_val(device, 'sw_mac')),
helpVal1=parentMac,
helpVal2=get_port(get_unifi_val(device, 'sw_port'), get_unifi_val(device, 'uplink_remote_port')),
helpVal3=device_label,
helpVal4="",