Skip to content

Commit

Permalink
set device tracker name and add hostname to attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
elad-bar committed May 2, 2024
1 parent d34b53d commit 5e77b5a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions custom_components/edgeos/common/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
ATTR_ACTIONS = "actions"
ATTR_IS_ON = "is_on"
ATTR_LAST_ACTIVITY = "last activity"
ATTR_HOSTNAME = "hostname"

ACTION_ENTITY_TURN_ON = "turn_on"
ACTION_ENTITY_TURN_OFF = "turn_off"
Expand Down
2 changes: 0 additions & 2 deletions custom_components/edgeos/data_processors/system_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ def get(self) -> EdgeOSSystemData:
def get_device_info(self, item_id: str | None = None) -> DeviceInfo:
name = self._system.hostname.upper()

_LOGGER.error(self._system)

device_info = DeviceInfo(
identifiers={(DEFAULT_NAME, name)},
name=name,
Expand Down
9 changes: 8 additions & 1 deletion custom_components/edgeos/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from homeassistant.core import HomeAssistant

from .common.base_entity import IntegrationBaseEntity, async_setup_base_entry
from .common.consts import ATTR_ATTRIBUTES, ATTR_IS_ON
from .common.consts import ATTR_ATTRIBUTES, ATTR_HOSTNAME, ATTR_IS_ON
from .common.entity_descriptions import IntegrationDeviceTrackerEntityDescription
from .common.enums import DeviceTypes
from .managers.coordinator import Coordinator
Expand Down Expand Up @@ -51,12 +51,18 @@ def __init__(
self._attr_mac_address: str | None = None
self._attr_source_type: SourceType | str | None = SourceType.ROUTER
self._attr_is_connected: bool = False
self._attr_hostname: str | None = None

@property
def ip_address(self) -> str | None:
"""Return the primary ip address of the device."""
return self._attr_ip_address

@property
def hostname(self) -> str | None:
"""Return the hostname of the device."""
return self._attr_hostname

@property
def mac_address(self) -> str | None:
"""Return the mac address of the device."""
Expand All @@ -82,6 +88,7 @@ def update_component(self, data):
self._attr_is_connected = is_connected
self._attr_ip_address = attributes.get(ATTR_IP)
self._attr_mac_address = attributes.get(ATTR_MAC)
self._attr_hostname = attributes.get(ATTR_HOSTNAME)

self._attr_extra_state_attributes = {
attribute: attributes[attribute]
Expand Down
2 changes: 2 additions & 0 deletions custom_components/edgeos/managers/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
API_RECONNECT_INTERVAL,
ATTR_ACTIONS,
ATTR_ATTRIBUTES,
ATTR_HOSTNAME,
ATTR_IS_ON,
ATTR_LAST_ACTIVITY,
DOMAIN,
Expand Down Expand Up @@ -734,6 +735,7 @@ def _get_device_tracker_data(
ATTR_LAST_ACTIVITY: last_activity,
ATTR_IP: device.ip,
ATTR_MAC: device.mac,
ATTR_HOSTNAME: device.hostname,
},
}

Expand Down
5 changes: 5 additions & 0 deletions custom_components/edgeos/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
"name": "Connected"
}
},
"device_tracker": {
"device_tracker": {
"name": "Status"
}
},
"number": {
"consider_away_interval": {
"name": "Consider Away Interval"
Expand Down
5 changes: 5 additions & 0 deletions custom_components/edgeos/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"name": "Connected"
}
},
"device_tracker": {
"device_tracker": {
"name": "Status"
}
},
"number": {
"consider_away_interval": {
"name": "Consider Away Interval"
Expand Down
5 changes: 5 additions & 0 deletions custom_components/edgeos/translations/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"name": "Tilkoblet"
}
},
"device_tracker": {
"device_tracker": {
"name": "Status"
}
},
"number": {
"consider_away_interval": {
"name": "Vurder bort intervall"
Expand Down
5 changes: 5 additions & 0 deletions custom_components/edgeos/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"name": "Conectada Conectado"
}
},
"device_tracker": {
"device_tracker": {
"name": "Status"
}
},
"number": {
"consider_away_interval": {
"name": "Considere o intervalo fora"
Expand Down

0 comments on commit 5e77b5a

Please sign in to comment.