Skip to content

Commit

Permalink
Improved entities loading
Browse files Browse the repository at this point in the history
  • Loading branch information
elad-bar committed Oct 31, 2022
1 parent c4ff40e commit 42c707e
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 250 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.0.19

- Improved logic to identify interface types correctly and present all

## 2.0.18

- Removed configuration and service parameter of `store debug data`
Expand Down
79 changes: 68 additions & 11 deletions custom_components/edgeos/component/helpers/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import homeassistant.helpers.config_validation as cv

from ...core.helpers.const import *
from .enums import InterfaceTypes

ATTR_FRIENDLY_NAME = "friendly_name"

Expand Down Expand Up @@ -206,7 +207,7 @@

INTERFACE_DATA_NAME = "name"
INTERFACE_DATA_DESCRIPTION = "description"
INTERFACE_DATA_INTERFACE_TYPE = "type"
INTERFACE_DATA_TYPE = "type"
INTERFACE_DATA_DUPLEX = "duplex"
INTERFACE_DATA_SPEED = "speed"
INTERFACE_DATA_BRIDGE_GROUP = "bridge-group"
Expand All @@ -225,8 +226,7 @@
INTERFACE_DATA_UP = "up"
INTERFACE_DATA_LINK_UP = "l1up"
INTERFACE_DATA_MAC = "mac"

INTERFACE_TYPE_LOOPBACK = "loopback"
INTERFACE_DATA_HANDLER = "handler"

DEVICE_DATA_NAME = "hostname"
DEVICE_DATA_DOMAIN = "domain"
Expand Down Expand Up @@ -268,10 +268,6 @@
TRAFFIC_STATS_BYTES: TRAFFIC_DATA_TOTAL
}

UNMONITORED_INTERFACE_TYPES = [
INTERFACE_TYPE_LOOPBACK
]

INTERFACES_MAIN_MAP = [
INTERFACE_DATA_UP,
INTERFACE_DATA_LINK_UP,
Expand Down Expand Up @@ -306,8 +302,69 @@
]

SPECIAL_INTERFACES = {
"pppoe": "Internet Dail-Up",
"switch": "Switch",
"vtun": "Virtual Tunnel",
"openvpn": "OpenVPN"
InterfaceTypes.PPPOE_PREFIX: "Internet Dail-Up",
InterfaceTypes.SWITCH_PREFIX: "Switch",
InterfaceTypes.VIRTUAL_TUNNEL_PREFIX: "Virtual Tunnel",
InterfaceTypes.OPEN_VPN_PREFIX: "OpenVPN",
InterfaceTypes.BONDING_PREFIX: "VLAN"
}

IGNORED_INTERFACES = [
InterfaceTypes.LOOPBACK
]

RECEIVED_RATE_PREFIX = "Received Rate"
RECEIVED_TRAFFIC_PREFIX = "Received Traffic"
RECEIVED_DROPPED_PREFIX = "Received Dropped"
RECEIVED_ERRORS_PREFIX = "Received Errors"
RECEIVED_PACKETS_PREFIX = "Received Packets"

SENT_RATE_PREFIX = "Sent Rate"
SENT_TRAFFIC_PREFIX = "Sent Traffic"
SENT_DROPPED_PREFIX = "Sent Dropped"
SENT_ERRORS_PREFIX = "Sent Errors"
SENT_PACKETS_PREFIX = "Sent Packets"

RECEIVED_RATE_ICON = "mdi:download-network-outline"
RECEIVED_TRAFFIC_ICON = "mdi:download-network-outline"
RECEIVED_DROPPED_ICON = "mdi:package-variant-minus"
RECEIVED_ERRORS_ICON = "mdi:timeline-alert"
RECEIVED_PACKETS_ICON = "mdi:package-up"

SENT_RATE_ICON = "mdi:upload-network-outline"
SENT_TRAFFIC_ICON = "mdi:upload-network-outline"
SENT_DROPPED_ICON = "mdi:package-variant-minus"
SENT_ERRORS_ICON = "mdi:timeline-alert"
SENT_PACKETS_ICON = "mdi:package-up"

STATS_ICONS = {
RECEIVED_RATE_PREFIX: RECEIVED_RATE_ICON,
RECEIVED_TRAFFIC_PREFIX: RECEIVED_TRAFFIC_ICON,
RECEIVED_DROPPED_PREFIX: RECEIVED_DROPPED_ICON,
RECEIVED_ERRORS_PREFIX: RECEIVED_ERRORS_ICON,
RECEIVED_PACKETS_PREFIX: RECEIVED_PACKETS_ICON,
SENT_RATE_PREFIX: SENT_RATE_ICON,
SENT_TRAFFIC_PREFIX: SENT_TRAFFIC_ICON,
SENT_DROPPED_PREFIX: SENT_DROPPED_ICON,
SENT_ERRORS_PREFIX: SENT_ERRORS_ICON,
SENT_PACKETS_PREFIX: SENT_PACKETS_ICON,
}

STATS_RATE = [
RECEIVED_RATE_PREFIX,
SENT_RATE_PREFIX
]

STATS_TRAFFIC = [
RECEIVED_TRAFFIC_PREFIX,
SENT_TRAFFIC_PREFIX
]

STATS_UNITS = {
RECEIVED_DROPPED_PREFIX: TRAFFIC_DATA_DROPPED,
RECEIVED_ERRORS_PREFIX: TRAFFIC_DATA_ERRORS,
RECEIVED_PACKETS_PREFIX: TRAFFIC_DATA_PACKETS,
SENT_DROPPED_PREFIX: TRAFFIC_DATA_DROPPED,
SENT_ERRORS_PREFIX: TRAFFIC_DATA_ERRORS,
SENT_PACKETS_PREFIX: TRAFFIC_DATA_PACKETS,
}
24 changes: 24 additions & 0 deletions custom_components/edgeos/component/helpers/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from enum import Enum

from homeassistant.backports.enum import StrEnum


class InterfaceTypes(StrEnum):
BRIDGE = "bridge"
LOOPBACK = "loopback"
ETHERNET = "ethernet"

PPPOE_PREFIX = "pppoe"
SWITCH_PREFIX = "switch"
VIRTUAL_TUNNEL_PREFIX = "vtun"
OPEN_VPN_PREFIX = "openvpn"
BONDING_PREFIX = "bond"
INTERMEDIATE_QUEUEING_DEVICE_PREFIX = "imq"
NETWORK_PROGRAMMING_INTERFACE_PREFIX = "npi"
LOOPBACK_PREFIX = "lo"


class InterfaceHandlers(Enum):
REGULAR = 0
SPECIAL = 1
IGNORED = 99
Loading

0 comments on commit 42c707e

Please sign in to comment.