Skip to content

Commit

Permalink
Merge pull request #18 from matriphe/handle-attribute-error
Browse files Browse the repository at this point in the history
Handle `AttributeError`
  • Loading branch information
Andre0512 authored Aug 14, 2024
2 parents 7546fcb + 3300399 commit 3d3efbc
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions custom_components/speedport/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,39 @@ def source_type(self) -> SourceType:

@property
def hostname(self) -> str | None:
"""Return the hostname of device."""
return self._device.name
try:
"""Return the hostname of device."""
return self._device.name
except AttributeError:
"""The device is disconnected or unavailable in the router."""
return None

@property
def ip_address(self) -> str | None:
"""Return the primary ip address of the device."""
return self._device.ipv4
try:
"""Return the primary ip address of the device."""
return self._device.ipv4
except AttributeError:
"""The device is disconnected or unavailable in the router."""
return None

@property
def is_connected(self) -> bool:
"""Return device status."""
return self._device.connected
try:
"""Return device status."""
return self._device.connected
except AttributeError:
"""The device is disconnected or unavailable in the router."""
return False

@property
def mac_address(self) -> str:
"""Return mac_address."""
return self._device.mac
try:
"""Return mac_address."""
return self._device.mac
except AttributeError:
"""The device is disconnected or unavailable in the router."""
return ""

@property
def icon(self) -> str:
Expand Down Expand Up @@ -107,8 +123,12 @@ def extra_state_attributes(self) -> dict[str, str]:

@property
def name(self) -> str:
"""Return device name."""
return self._device.name
try:
"""Return device name."""
return self._device.name
except AttributeError:
"""The device is disconnected or unavailable in the router."""
return ""

@callback
def _handle_coordinator_update(self) -> None:
Expand Down

0 comments on commit 3d3efbc

Please sign in to comment.