Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle AttributeError #18

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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