Skip to content

Commit

Permalink
fix: create correct url when using ipv6 (#753)
Browse files Browse the repository at this point in the history
* fix: create correct url when using ipv6

* fix: reorder import

* fix: perform type check with isinstance
  • Loading branch information
skgsergio authored Sep 6, 2023
1 parent 4425700 commit cfa0eb1
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions custom_components/google_home/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import asyncio
from http import HTTPStatus
import ipaddress
import logging
from typing import Literal, cast

Expand Down Expand Up @@ -125,6 +126,8 @@ def _get_android_id() -> str:
def create_url(ip_address: str, port: int, api_endpoint: str) -> str:
"""Creates url to endpoint.
Note: port argument is unused because all request must be done to 8443"""
if isinstance(ipaddress.ip_address(ip_address), ipaddress.IPv6Address):
ip_address = f"[{ip_address}]"
return f"https://{ip_address}:{port}/{api_endpoint}"

async def update_google_devices_information(self) -> list[GoogleHomeDevice]:
Expand Down

0 comments on commit cfa0eb1

Please sign in to comment.