diff --git a/CHANGELOG.md b/CHANGELOG.md index 57d8649..7aa9a96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 2.1.3 + +- Update supported interfaces [#137](https://github.com/elad-bar/ha-edgeos/issues/137) +- Removed unused constants + ## 2.1.2 - Re-add interface status (Binary Sensor and Switch) [#135](https://github.com/elad-bar/ha-edgeos/issues/135) diff --git a/custom_components/edgeos/common/consts.py b/custom_components/edgeos/common/consts.py index ff0d8a3..d4723d4 100644 --- a/custom_components/edgeos/common/consts.py +++ b/custom_components/edgeos/common/consts.py @@ -4,18 +4,10 @@ from datetime import timedelta import aiohttp -import voluptuous as vol -from homeassistant.const import ( - CONF_HOST, - CONF_PASSWORD, - CONF_USERNAME, - UnitOfDataRate, - UnitOfInformation, -) -import homeassistant.helpers.config_validation as cv +from homeassistant.const import UnitOfDataRate, UnitOfInformation -from .enums import DeviceTypes, DynamicInterfaceTypes, UnitOfEdgeOS +from .enums import DeviceTypes, DynamicInterfaceTypes, InterfaceTypes, UnitOfEdgeOS ENTITY_CONFIG_ENTRY_ID = "entry_id" @@ -27,18 +19,11 @@ STORAGE_DATA_KEY = "key" -SIGNAL_INTERFACE_DISCOVERED = f"{DOMAIN}_INTERFACE_DISCOVERED_SIGNAL" SIGNAL_INTERFACE_ADDED = f"{DOMAIN}_INTERFACE_ADDED_SIGNAL" - -SIGNAL_DEVICE_DISCOVERED = f"{DOMAIN}_DEVICE_DISCOVERED_SIGNAL" SIGNAL_DEVICE_ADDED = f"{DOMAIN}_DEVICE_ADDED_SIGNAL" - -SIGNAL_SYSTEM_DISCOVERED = f"{DOMAIN}_SYSTEM_DISCOVERED_SIGNAL" SIGNAL_SYSTEM_ADDED = f"{DOMAIN}_SYSTEM_ADDED_SIGNAL" - SIGNAL_DATA_CHANGED = f"{DOMAIN}_DATA_CHANGED_SIGNAL" -SIGNAL_WS_READY = f"{DOMAIN}_WS_READY_SIGNAL" SIGNAL_WS_STATUS = f"{DOMAIN}_WS_STATUS_SIGNAL" SIGNAL_API_STATUS = f"{DOMAIN}_API_STATUS_SIGNAL" @@ -48,8 +33,6 @@ SIGNAL_SYSTEM_ADDED, ] -DATA_KEYS = [CONF_HOST, CONF_USERNAME, CONF_PASSWORD] - MAXIMUM_RECONNECT = 3 CONFIGURATION_FILE = f"{DOMAIN}.config.json" @@ -66,7 +49,6 @@ EMPTY_STRING = "" CONF_TITLE = "title" -ATTR_FRIENDLY_NAME = "friendly_name" ATTR_ATTRIBUTES = "attributes" ATTR_ACTIONS = "actions" ATTR_IS_ON = "is_on" @@ -78,30 +60,20 @@ ACTION_ENTITY_SET_NATIVE_VALUE = "set_native_value" ACTION_ENTITY_SELECT_OPTION = "select_option" -CONF_DEVICE_ID = "device_id" - WS_MAX_MSG_SIZE = 0 DISCONNECT_INTERVAL = 5 WS_RECONNECT_INTERVAL = timedelta(seconds=30) WS_TIMEOUT = timedelta(minutes=1) -WS_WARNING_INTERVAL = timedelta(seconds=95) WS_COMPRESSION_DEFLATE = 15 DEFAULT_UPDATE_API_INTERVAL = timedelta(minutes=1) DEFAULT_UPDATE_ENTITIES_INTERVAL = timedelta(seconds=1) -DEFAULT_HEARTBEAT_INTERVAL = timedelta(seconds=50) DEFAULT_CONSIDER_AWAY_INTERVAL = timedelta(minutes=3) API_RECONNECT_INTERVAL = timedelta(seconds=30) HEARTBEAT_INTERVAL = timedelta(seconds=25) -STORAGE_DATA_FILE_CONFIG = "config" - -STORAGE_DATA_FILES = [STORAGE_DATA_FILE_CONFIG] - -MESSAGES_COUNTER_SECTION = "messages" - STORAGE_DATA_MONITORED_INTERFACES = "monitored-interfaces" STORAGE_DATA_MONITORED_DEVICES = "monitored-devices" STORAGE_DATA_LOG_INCOMING_MESSAGES = "log-incoming-messages" @@ -137,9 +109,6 @@ TRUE_STR = "true" FALSE_STR = "false" -LINK_ENABLED = "up" -LINK_CONNECTED = "l1up" - INTERFACES_STATS = "stats" # CHANGE TO API DATA @@ -168,9 +137,6 @@ WS_RECEIVED_MESSAGES = "received-messages" WS_IGNORED_MESSAGES = "ignored-messages" -WS_ERROR_MESSAGES = "error-messages" - -WS_MESSAGES = [WS_RECEIVED_MESSAGES, WS_IGNORED_MESSAGES, WS_ERROR_MESSAGES] UPDATE_DATE_ENDPOINTS = [API_DATA_SYS_INFO, API_DATA_DHCP_STATS, API_DATA_DHCP_LEASES] @@ -183,10 +149,8 @@ DEVICE_LIST = "devices" ADDRESS_LIST = "addresses" -FW_LATEST = "addresses" ADDRESS_IPV4 = "ipv4" ADDRESS_HW_ADDR = "hwaddr" -LAST_ACTIVITY = "Last Activity" RESPONSE_SUCCESS_KEY = "success" RESPONSE_ERROR_KEY = "error" @@ -200,8 +164,6 @@ WS_TOPIC_SUBSCRIBE = "SUBSCRIBE" WS_SESSION_ID = "SESSION_ID" -SERVICE_UPDATE_CONFIGURATION = "update_configuration" - BEGINS_WITH_SIX_DIGITS = "^([0-9]{1,6})" STRING_DASH = "-" @@ -255,7 +217,6 @@ INTERFACE_DATA_RECEIVED = "received" INTERFACE_DATA_SENT = "sent" INTERFACE_DATA_MULTICAST = "multicast" -INTERFACE_DATA_STATS = "stats" INTERFACE_DATA_UP = "up" INTERFACE_DATA_LINK_UP = "l1up" INTERFACE_DATA_MAC = "mac" @@ -314,90 +275,26 @@ "system_status", ] -SERVICE_SCHEMA_UPDATE_CONFIGURATION = vol.Schema( - { - vol.Required(CONF_DEVICE_ID): cv.string, - vol.Optional( - STORAGE_DATA_CONSIDER_AWAY_INTERVAL.replace(STRING_DASH, STRING_UNDERSCORE) - ): vol.Range(10, 1800), - vol.Optional( - STORAGE_DATA_UPDATE_ENTITIES_INTERVAL.replace( - STRING_DASH, STRING_UNDERSCORE - ) - ): vol.Range(1, 60), - vol.Optional( - STORAGE_DATA_UPDATE_API_INTERVAL.replace(STRING_DASH, STRING_UNDERSCORE) - ): vol.Range(30, 180), - vol.Optional( - STORAGE_DATA_LOG_INCOMING_MESSAGES.replace(STRING_DASH, STRING_UNDERSCORE) - ): cv.boolean, - } -) - WS_CLOSING_MESSAGE = [ aiohttp.WSMsgType.CLOSE, aiohttp.WSMsgType.CLOSED, aiohttp.WSMsgType.CLOSING, ] -INTERFACE_DYNAMIC_SUPPORTED = [ +SUPPORTED_INTERFACES = [ + InterfaceTypes.ETHERNET, + InterfaceTypes.BRIDGE, + InterfaceTypes.SWITCH, + InterfaceTypes.OPEN_VPN, + InterfaceTypes.WIREGUARD, +] + +SUPPORTED_DYNAMIC_INTERFACES = [ DynamicInterfaceTypes.PPPOE, - DynamicInterfaceTypes.SWITCH, DynamicInterfaceTypes.VIRTUAL_TUNNEL, - DynamicInterfaceTypes.OPEN_VPN, DynamicInterfaceTypes.BONDING, ] -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_DATA_RATE = [RECEIVED_RATE_PREFIX, SENT_RATE_PREFIX] - -STATS_DATA_SIZE = [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, -} - ATTR_UNIT_INFORMATION = "information" ATTR_UNIT_RATE = "rate" ATTR_UNIT_CONVERTOR = "unit_convertor" diff --git a/custom_components/edgeos/common/enums.py b/custom_components/edgeos/common/enums.py index 1746cfd..3369b9f 100644 --- a/custom_components/edgeos/common/enums.py +++ b/custom_components/edgeos/common/enums.py @@ -12,14 +12,14 @@ class InterfaceTypes(StrEnum): LOOPBACK = "loopback" ETHERNET = "ethernet" SWITCH = "switch" + OPEN_VPN = "openvpn" + WIREGUARD = "wireguard" DYNAMIC = "dynamic" class DynamicInterfaceTypes(StrEnum): PPPOE = "pppoe" - SWITCH = "switch" VIRTUAL_TUNNEL = "vtun" - OPEN_VPN = "openvpn" BONDING = "bond" INTERMEDIATE_QUEUEING_DEVICE = "imq" NETWORK_PROGRAMMING_INTERFACE = "npi" diff --git a/custom_components/edgeos/common/exceptions.py b/custom_components/edgeos/common/exceptions.py index 54a4d74..8317017 100644 --- a/custom_components/edgeos/common/exceptions.py +++ b/custom_components/edgeos/common/exceptions.py @@ -1,7 +1,6 @@ +from custom_components.edgeos.common.connectivity_status import ConnectivityStatus from homeassistant.exceptions import HomeAssistantError -from ...core.helpers.enums import ConnectivityStatus - class MonitorNotFoundError(HomeAssistantError): monitor_id: str diff --git a/custom_components/edgeos/data_processors/system_processor.py b/custom_components/edgeos/data_processors/system_processor.py index 171ddf3..21fb672 100644 --- a/custom_components/edgeos/data_processors/system_processor.py +++ b/custom_components/edgeos/data_processors/system_processor.py @@ -15,6 +15,7 @@ DISCOVER_DATA_FW_VERSION, DISCOVER_DATA_PRODUCT, FW_LATEST_STATE_CAN_UPGRADE, + MANUFACTURER, SYSTEM_DATA_HOSTNAME, SYSTEM_DATA_LOGIN, SYSTEM_DATA_LOGIN_USER, @@ -67,7 +68,7 @@ def get_device_info(self, item_id: str | None = None) -> DeviceInfo: identifiers={(DEFAULT_NAME, name)}, name=name, model=self._system.product, - manufacturer=DEFAULT_NAME, + manufacturer=MANUFACTURER, hw_version=self._system.fw_version, ) diff --git a/custom_components/edgeos/manifest.json b/custom_components/edgeos/manifest.json index 70d9a94..38a99dc 100644 --- a/custom_components/edgeos/manifest.json +++ b/custom_components/edgeos/manifest.json @@ -8,5 +8,5 @@ "iot_class": "local_polling", "issue_tracker": "https://github.com/elad-bar/ha-edgeos/issues", "requirements": ["aiohttp"], - "version": "2.1.2" + "version": "2.1.3" } diff --git a/custom_components/edgeos/models/edge_os_device_data.py b/custom_components/edgeos/models/edge_os_device_data.py index f2d406b..90c0051 100644 --- a/custom_components/edgeos/models/edge_os_device_data.py +++ b/custom_components/edgeos/models/edge_os_device_data.py @@ -10,10 +10,6 @@ DEVICE_DATA_RECEIVED, DEVICE_DATA_SENT, DHCP_SERVER_LEASED, - RECEIVED_RATE_PREFIX, - RECEIVED_TRAFFIC_PREFIX, - SENT_RATE_PREFIX, - SENT_TRAFFIC_PREFIX, TRAFFIC_DATA_DIRECTION_RECEIVED, TRAFFIC_DATA_DIRECTION_SENT, ) @@ -43,16 +39,6 @@ def __init__( def unique_id(self) -> str: return self.mac - def get_stats(self): - data = { - RECEIVED_RATE_PREFIX: self.received.rate, - RECEIVED_TRAFFIC_PREFIX: self.received.total, - SENT_RATE_PREFIX: self.sent.rate, - SENT_TRAFFIC_PREFIX: self.sent.total, - } - - return data - @property def last_activity(self) -> int: received_activity = int(self.received.last_activity) diff --git a/custom_components/edgeos/models/edge_os_interface_data.py b/custom_components/edgeos/models/edge_os_interface_data.py index fe565ba..30f8ce7 100644 --- a/custom_components/edgeos/models/edge_os_interface_data.py +++ b/custom_components/edgeos/models/edge_os_interface_data.py @@ -19,17 +19,8 @@ INTERFACE_DATA_SPEED, INTERFACE_DATA_STP, INTERFACE_DATA_TYPE, - INTERFACE_DYNAMIC_SUPPORTED, - RECEIVED_DROPPED_PREFIX, - RECEIVED_ERRORS_PREFIX, - RECEIVED_PACKETS_PREFIX, - RECEIVED_RATE_PREFIX, - RECEIVED_TRAFFIC_PREFIX, - SENT_DROPPED_PREFIX, - SENT_ERRORS_PREFIX, - SENT_PACKETS_PREFIX, - SENT_RATE_PREFIX, - SENT_TRAFFIC_PREFIX, + SUPPORTED_DYNAMIC_INTERFACES, + SUPPORTED_INTERFACES, TRAFFIC_DATA_DIRECTION_RECEIVED, TRAFFIC_DATA_DIRECTION_SENT, ) @@ -113,37 +104,18 @@ def to_dict(self): return obj def _get_is_supported(self): - is_supported = self.interface_type in [ - InterfaceTypes.ETHERNET, - InterfaceTypes.BRIDGE, - ] + is_supported = self.interface_type in SUPPORTED_INTERFACES if self.interface_type == InterfaceTypes.DYNAMIC: prefixes = list(DynamicInterfaceTypes) for prefix in prefixes: if self.name.startswith(str(prefix)): - is_supported = prefix in INTERFACE_DYNAMIC_SUPPORTED + is_supported = prefix in SUPPORTED_DYNAMIC_INTERFACES break return is_supported - def get_stats(self): - data = { - RECEIVED_RATE_PREFIX: self.received.rate, - RECEIVED_TRAFFIC_PREFIX: self.received.total, - RECEIVED_DROPPED_PREFIX: self.received.dropped, - RECEIVED_ERRORS_PREFIX: self.received.errors, - RECEIVED_PACKETS_PREFIX: self.received.packets, - SENT_RATE_PREFIX: self.sent.rate, - SENT_TRAFFIC_PREFIX: self.sent.total, - SENT_DROPPED_PREFIX: self.sent.dropped, - SENT_ERRORS_PREFIX: self.sent.errors, - SENT_PACKETS_PREFIX: self.sent.packets, - } - - return data - def get_attributes(self): interface_attributes = self.to_dict()