From 3e726fadc8ef47f00fc213b286c14eff2dd0cb21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Fri, 7 Feb 2025 05:13:30 +0100 Subject: [PATCH] More consistent logging in newer classes (#801) --- hass_nabucasa/files.py | 6 +++--- hass_nabucasa/instance_api.py | 4 ++++ tests/test_files.py | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/hass_nabucasa/files.py b/hass_nabucasa/files.py index 7ef4bc43f..ff904e30a 100644 --- a/hass_nabucasa/files.py +++ b/hass_nabucasa/files.py @@ -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", @@ -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}", @@ -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 diff --git a/hass_nabucasa/instance_api.py b/hass_nabucasa/instance_api.py index c49f838a8..fad7d25a4 100644 --- a/hass_nabucasa/instance_api.py +++ b/hass_nabucasa/instance_api.py @@ -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.""" @@ -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", diff --git a/tests/test_files.py b/tests/test_files.py index 26ac44906..d7cf438d1 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -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 @@ -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 "