diff --git a/homeassistant_api/_async/asyncclient.py b/homeassistant_api/_async/asyncclient.py index 452d9507..ca5d8182 100644 --- a/homeassistant_api/_async/asyncclient.py +++ b/homeassistant_api/_async/asyncclient.py @@ -197,7 +197,7 @@ async def async_trigger_service( ) -> List[State]: """Tells Home Assistant to trigger a service, returns stats changed while being called""" data = await self.async_request( - join("services", domain + "/" + service), + f"services/{domain}/{service}", method="POST", json=service_data, ) diff --git a/homeassistant_api/rawapi.py b/homeassistant_api/rawapi.py index 68f707f5..688cbb0b 100644 --- a/homeassistant_api/rawapi.py +++ b/homeassistant_api/rawapi.py @@ -1,9 +1,9 @@ """Module for parent RawWrapper class""" -import os import re from datetime import datetime from typing import Dict, Optional, Tuple, Union +from urllib.parse import urljoin as join from .const import DATE_FMT from .models import Entity @@ -42,7 +42,7 @@ def __init__( def endpoint(self, path: str) -> str: """Joins the api base url with a local path to an absolute url""" - return os.path.join(self.api_url, path) + return join(self.api_url, path) @property def _headers(self) -> Dict[str, str]: @@ -122,7 +122,7 @@ def prepare_get_entity_histories_params( if start_timestamp is not None: if isinstance(start_timestamp, datetime): formatted_timestamp = start_timestamp.strftime(DATE_FMT) - url = os.path.join("history/period", formatted_timestamp) + url = join("history/period", formatted_timestamp) else: raise TypeError(f"timestamp needs to be of type {datetime!r}") else: @@ -148,7 +148,7 @@ def prepare_get_logbook_entry_params( if start_timestamp is not None: if isinstance(start_timestamp, datetime): formatted_timestamp = start_timestamp.strftime(DATE_FMT) - url = os.path.join("logbook", formatted_timestamp) + url = join("logbook", formatted_timestamp) else: url = "logbook" return params, url