Skip to content

Commit

Permalink
More consistent logging in newer classes (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Feb 7, 2025
1 parent 8b3b880 commit 3e726fa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions hass_nabucasa/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async def upload(
metadata: dict[str, Any] | None = None,
) -> None:
"""Upload a file."""
_LOGGER.debug("Uploading file %s", filename)
_LOGGER.debug("Uploading %s file with name %s", storage_type, filename)
try:
details: FilesHandlerUploadDetails = await self._call_cloud_api(
path="/files/upload_details",
Expand Down Expand Up @@ -126,7 +126,7 @@ async def download(
filename: str,
) -> StreamReader:
"""Download a file."""
_LOGGER.debug("Downloading file %s", filename)
_LOGGER.debug("Downloading %s file with name %s", storage_type, filename)
try:
details: FilesHandlerDownloadDetails = await self._call_cloud_api(
path=f"/files/download_details/{storage_type}/{filename}",
Expand All @@ -153,7 +153,7 @@ async def download(
raise FilesError(err, orig_exc=err) from err
except ClientResponseError as err:
raise FilesError(
f"Failed to upload: ({err.status}) {err.message}",
f"Failed to download: ({err.status}) {err.message}",
orig_exc=err,
) from err

Expand Down
4 changes: 4 additions & 0 deletions hass_nabucasa/instance_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

from __future__ import annotations

import logging
from typing import TYPE_CHECKING, Literal, TypedDict

from aiohttp import hdrs

from .api import ApiBase, CloudApiError

_LOGGER = logging.getLogger(__name__)


class InstanceApiError(CloudApiError):
"""Exception raised when handling instance API."""
Expand Down Expand Up @@ -48,6 +51,7 @@ def hostname(self) -> str:

async def connection(self) -> InstanceConnection:
"""Get the connection details."""
_LOGGER.debug("Getting instance connection details")
try:
details: InstanceConnection = await self._call_cloud_api(
path="/instance/connection",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ async def test_upload(
metadata={"awesome": True},
)

assert "Uploading file lorem.ipsum" in caplog.text
assert "Uploading test file with name lorem.ipsum" in caplog.text
assert "Response for get from example.com/files/upload_details (200)" in caplog.text
assert "Response for put from files.api.fakeurl (200)" in caplog.text

Expand Down Expand Up @@ -387,7 +387,7 @@ async def test_downlaod(
storage_type="test",
filename="lorem.ipsum",
)
assert "Downloading file lorem.ipsum" in caplog.text
assert "Downloading test file with name lorem.ipsum" in caplog.text
assert len(aioclient_mock.mock_calls) == 2
assert (
"Response for get from example.com/files/download_details/test/lorem.ipsum "
Expand Down

0 comments on commit 3e726fa

Please sign in to comment.