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

Reintroduce ability to get IP addresses without scope #751

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions matter_server/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,14 @@ async def ping_node(self, node_id: int) -> NodePingResult:
async def get_node_ip_addresses(
self, node_id: int, prefer_cache: bool = True, scoped: bool = False
) -> list[str]:
"""Return the currently known (scoped) IP-adress(es)."""
"""Return the currently known (scoped) IP-address(es)."""
if TYPE_CHECKING:
assert self.server_info is not None
if self.server_info.schema_version >= 8:
return cast(
list[str],
await self.send_command(
APICommand.GET_NODE_IP_ADRESSES,
APICommand.GET_NODE_IP_ADDRESSES,
require_schema=8,
node_id=node_id,
prefer_cache=prefer_cache,
Expand Down
2 changes: 1 addition & 1 deletion matter_server/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class APICommand(str, Enum):
READ_ATTRIBUTE = "read_attribute"
WRITE_ATTRIBUTE = "write_attribute"
PING_NODE = "ping_node"
GET_NODE_IP_ADRESSES = "get_node_ip_addresses"
GET_NODE_IP_ADDRESSES = "get_node_ip_addresses"
IMPORT_TEST_NODE = "import_test_node"


Expand Down
25 changes: 15 additions & 10 deletions matter_server/server/device_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,9 +784,7 @@ async def _do_ping(ip_address: str) -> None:
node_logger.debug("Pinging address %s", ip_address)
result[ip_address] = await ping_ip(ip_address, timeout, attempts=attempts)

ip_addresses = await self.get_node_ip_addresses(
node_id, prefer_cache=False, scoped=True
)
ip_addresses = await self._get_node_ip_addresses(node_id, prefer_cache=False)
tasks = [_do_ping(x) for x in ip_addresses]
# TODO: replace this gather with a taskgroup once we bump our py version
await asyncio.gather(*tasks)
Expand All @@ -806,14 +804,10 @@ async def _do_ping(ip_address: str) -> None:

return result

@api_command(APICommand.GET_NODE_IP_ADRESSES)
async def get_node_ip_addresses(
self,
node_id: int,
prefer_cache: bool = False,
scoped: bool = False,
async def _get_node_ip_addresses(
self, node_id: int, prefer_cache: bool = False
) -> list[str]:
"""Return the currently known (scoped) IP-address(es)."""
"""Get the IP addresses of a node."""
cached_info = self._last_known_ip_addresses.get(node_id, [])
if prefer_cache and cached_info:
return cached_info
Expand All @@ -839,6 +833,17 @@ async def get_node_ip_addresses(
self._last_known_ip_addresses[node_id] = ip_addresses
return ip_addresses

@api_command(APICommand.GET_NODE_IP_ADDRESSES)
async def get_node_ip_addresses(
self,
node_id: int,
prefer_cache: bool = False,
scoped: bool = False,
) -> list[str]:
"""Return the currently known (scoped) IP-address(es)."""
ip_addresses = await self._get_node_ip_addresses(node_id, prefer_cache)
return ip_addresses if scoped else [x.split("%")[0] for x in ip_addresses]

@api_command(APICommand.IMPORT_TEST_NODE)
async def import_test_node(self, dump: str) -> None:
"""Import test node(s) from a HA or Matter server diagnostics dump."""
Expand Down