Skip to content

Commit

Permalink
Add interface line connected binary sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
elad-bar committed Oct 28, 2022
1 parent 4547ba3 commit 75959b2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 32 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.16

- Add interface line connected binary sensor

## 2.0.15

- Fix unhandled WS session disconnection
Expand Down
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down
37 changes: 34 additions & 3 deletions custom_components/edgeos/component/managers/home_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/edgeos/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"codeowners": ["@elad-bar"],
"requirements": ["aiohttp"],
"config_flow": true,
"version": "2.0.15",
"version": "2.0.16",
"iot_class": "local_polling"
}
30 changes: 16 additions & 14 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down

0 comments on commit 75959b2

Please sign in to comment.