diff --git a/CHANGELOG.md b/CHANGELOG.md index c982ee5..4089c38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.0.16 + +- Add interface line connected binary sensor + ## 2.0.15 - Fix unhandled WS session disconnection diff --git a/README.md b/README.md index e6d17c2..15e74e3 100644 --- a/README.md +++ b/README.md @@ -102,20 +102,22 @@ logger: ### Per interface -| Entity Name | Type | Description | Additional information | -|---------------------------------------------------------|--------|------------------------------------------------------------------------------|-----------------------------| -| {Router Name} {Interface Name} Status | Switch | Sets whether to interface is active or not | | -| {Router Name} {Interface Name} Monitored | Switch | Sets whether to monitor interface and create all the components below or not | | -| {Router Name} {Interface Name} Received Rate | Sensor | Received Rate per second | Statistics: Measurement | -| {Router Name} {Interface Name} Received Traffic | Sensor | Received total traffic | Statistics: Total Increment | -| {Router Name} {Interface Name} Received Dropped Packets | Sensor | Received packets lost | Statistics: Total Increment | -| {Router Name} {Interface Name} Received Errors | Sensor | Received errors | Statistics: Total Increment | -| {Router Name} {Interface Name} Received Packets | Sensor | Received packets | Statistics: Total Increment | -| {Router Name} {Interface Name} Sent Rate | Sensor | Sent Rate per second | Statistics: Measurement | -| {Router Name} {Interface Name} Sent Traffic | Sensor | Sent total traffic | Statistics: Total Increment | -| {Router Name} {Interface Name} Sent Dropped Packets | Sensor | Sent packets lost | Statistics: Total Increment | -| {Router Name} {Interface Name} Sent Errors | Sensor | Sent errors | Statistics: Total Increment | -| {Router Name} {Interface Name} Sent Packets | Sensor | Sent packets | Statistics: Total Increment | +| Entity Name | Type | Description | Additional information | +|---------------------------------------------------------|---------------|------------------------------------------------------------------------------|---------------------------------------------| +| {Router Name} {Interface Name} Status | Switch | Sets whether to interface is active or not | Available only if user level is `admin` | +| {Router Name} {Interface Name} Status | Binary Sensor | Indicates whether interface is active or not | Available only if user level is not `admin` | +| {Router Name} {Interface Name} Connected | Binary Sensor | Indicates whether interface's port is connected or not | | +| {Router Name} {Interface Name} Monitored | Switch | Sets whether to monitor interface and create all the components below or not | | +| {Router Name} {Interface Name} Received Rate | Sensor | Received Rate per second | Statistics: Measurement | +| {Router Name} {Interface Name} Received Traffic | Sensor | Received total traffic | Statistics: Total Increment | +| {Router Name} {Interface Name} Received Dropped Packets | Sensor | Received packets lost | Statistics: Total Increment | +| {Router Name} {Interface Name} Received Errors | Sensor | Received errors | Statistics: Total Increment | +| {Router Name} {Interface Name} Received Packets | Sensor | Received packets | Statistics: Total Increment | +| {Router Name} {Interface Name} Sent Rate | Sensor | Sent Rate per second | Statistics: Measurement | +| {Router Name} {Interface Name} Sent Traffic | Sensor | Sent total traffic | Statistics: Total Increment | +| {Router Name} {Interface Name} Sent Dropped Packets | Sensor | Sent packets lost | Statistics: Total Increment | +| {Router Name} {Interface Name} Sent Errors | Sensor | Sent errors | Statistics: Total Increment | +| {Router Name} {Interface Name} Sent Packets | Sensor | Sent packets | Statistics: Total Increment | _Unit of measurement for `Traffic` and `Rate` are according to the unit settings of the integration_ diff --git a/custom_components/edgeos/component/managers/home_assistant.py b/custom_components/edgeos/component/managers/home_assistant.py index 3277f0f..1a2e369 100644 --- a/custom_components/edgeos/component/managers/home_assistant.py +++ b/custom_components/edgeos/component/managers/home_assistant.py @@ -255,6 +255,8 @@ def load_entities(self): else: self._load_interface_status_binary_sensor(interface_item) + self._load_interface_connected_binary_sensor(interface_item) + self._load_interface_received_rate_sensor(interface_item) self._load_interface_received_traffic_sensor(interface_item) self._load_interface_received_dropped_sensor(interface_item) @@ -481,9 +483,6 @@ def _extract_interface(self, name: str, interface_type: str, data: dict, is_spec interface.promiscuous = data.get(INTERFACE_DATA_PROMISCUOUS) interface.stp = data.get(INTERFACE_DATA_STP, FALSE_STR).lower() == TRUE_STR - if is_special: - interface.up = True - self._interfaces[interface.unique_id] = interface except Exception as ex: @@ -1292,6 +1291,38 @@ def _load_interface_status_binary_sensor(self, interface: EdgeOSInterfaceData): ex, f"Failed to load binary sensor for {entity_name}" ) + def _load_interface_connected_binary_sensor(self, interface: EdgeOSInterfaceData): + interface_name = self._get_interface_name(interface) + entity_name = f"{interface_name} Connected" + + try: + state = STATE_ON if interface.l1up else STATE_OFF + + attributes = { + ATTR_FRIENDLY_NAME: entity_name, + ADDRESS_LIST: interface.address + } + + unique_id = EntityData.generate_unique_id(DOMAIN_BINARY_SENSOR, entity_name) + + entity_description = BinarySensorEntityDescription( + key=unique_id, + name=entity_name, + device_class=BinarySensorDeviceClass.CONNECTIVITY + ) + + self.entity_manager.set_entity(DOMAIN_BINARY_SENSOR, + self.entry_id, + state, + attributes, + interface_name, + entity_description) + + except Exception as ex: + self.log_exception( + ex, f"Failed to load binary sensor for {entity_name}" + ) + def _load_interface_monitor_switch(self, interface: EdgeOSInterfaceData): interface_name = self._get_interface_name(interface) entity_name = f"{interface_name} Monitored" diff --git a/custom_components/edgeos/manifest.json b/custom_components/edgeos/manifest.json index ddb337f..e2f639f 100644 --- a/custom_components/edgeos/manifest.json +++ b/custom_components/edgeos/manifest.json @@ -7,6 +7,6 @@ "codeowners": ["@elad-bar"], "requirements": ["aiohttp"], "config_flow": true, - "version": "2.0.15", + "version": "2.0.16", "iot_class": "local_polling" } diff --git a/info.md b/info.md index e6d17c2..15e74e3 100644 --- a/info.md +++ b/info.md @@ -102,20 +102,22 @@ logger: ### Per interface -| Entity Name | Type | Description | Additional information | -|---------------------------------------------------------|--------|------------------------------------------------------------------------------|-----------------------------| -| {Router Name} {Interface Name} Status | Switch | Sets whether to interface is active or not | | -| {Router Name} {Interface Name} Monitored | Switch | Sets whether to monitor interface and create all the components below or not | | -| {Router Name} {Interface Name} Received Rate | Sensor | Received Rate per second | Statistics: Measurement | -| {Router Name} {Interface Name} Received Traffic | Sensor | Received total traffic | Statistics: Total Increment | -| {Router Name} {Interface Name} Received Dropped Packets | Sensor | Received packets lost | Statistics: Total Increment | -| {Router Name} {Interface Name} Received Errors | Sensor | Received errors | Statistics: Total Increment | -| {Router Name} {Interface Name} Received Packets | Sensor | Received packets | Statistics: Total Increment | -| {Router Name} {Interface Name} Sent Rate | Sensor | Sent Rate per second | Statistics: Measurement | -| {Router Name} {Interface Name} Sent Traffic | Sensor | Sent total traffic | Statistics: Total Increment | -| {Router Name} {Interface Name} Sent Dropped Packets | Sensor | Sent packets lost | Statistics: Total Increment | -| {Router Name} {Interface Name} Sent Errors | Sensor | Sent errors | Statistics: Total Increment | -| {Router Name} {Interface Name} Sent Packets | Sensor | Sent packets | Statistics: Total Increment | +| Entity Name | Type | Description | Additional information | +|---------------------------------------------------------|---------------|------------------------------------------------------------------------------|---------------------------------------------| +| {Router Name} {Interface Name} Status | Switch | Sets whether to interface is active or not | Available only if user level is `admin` | +| {Router Name} {Interface Name} Status | Binary Sensor | Indicates whether interface is active or not | Available only if user level is not `admin` | +| {Router Name} {Interface Name} Connected | Binary Sensor | Indicates whether interface's port is connected or not | | +| {Router Name} {Interface Name} Monitored | Switch | Sets whether to monitor interface and create all the components below or not | | +| {Router Name} {Interface Name} Received Rate | Sensor | Received Rate per second | Statistics: Measurement | +| {Router Name} {Interface Name} Received Traffic | Sensor | Received total traffic | Statistics: Total Increment | +| {Router Name} {Interface Name} Received Dropped Packets | Sensor | Received packets lost | Statistics: Total Increment | +| {Router Name} {Interface Name} Received Errors | Sensor | Received errors | Statistics: Total Increment | +| {Router Name} {Interface Name} Received Packets | Sensor | Received packets | Statistics: Total Increment | +| {Router Name} {Interface Name} Sent Rate | Sensor | Sent Rate per second | Statistics: Measurement | +| {Router Name} {Interface Name} Sent Traffic | Sensor | Sent total traffic | Statistics: Total Increment | +| {Router Name} {Interface Name} Sent Dropped Packets | Sensor | Sent packets lost | Statistics: Total Increment | +| {Router Name} {Interface Name} Sent Errors | Sensor | Sent errors | Statistics: Total Increment | +| {Router Name} {Interface Name} Sent Packets | Sensor | Sent packets | Statistics: Total Increment | _Unit of measurement for `Traffic` and `Rate` are according to the unit settings of the integration_