From 1aa7c87151613ee74ebfeed3f9f17ecac3a1832f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Tue, 21 Sep 2021 20:51:12 +0300 Subject: [PATCH] Remove redundant aiohttp response status=200 kwargs (#56417) * Remove redundant aiohttp response status=200 kwargs * Remove some more in h.c.auth * Restore explicit status=HTTP_OK for auth and webhook per review request --- homeassistant/components/doorbird/__init__.py | 5 ++--- homeassistant/components/geofency/__init__.py | 3 +-- homeassistant/components/gpslogger/__init__.py | 3 +-- homeassistant/components/locative/__init__.py | 8 +++----- homeassistant/components/plaato/__init__.py | 3 +-- .../components/rss_feed_template/__init__.py | 5 +---- homeassistant/components/traccar/__init__.py | 11 +++-------- tests/components/api/test_init.py | 2 +- tests/components/http/test_auth.py | 2 +- tests/components/http/test_cors.py | 2 +- 10 files changed, 15 insertions(+), 29 deletions(-) diff --git a/homeassistant/components/doorbird/__init__.py b/homeassistant/components/doorbird/__init__.py index 4e4b1cb6ae9..f1addbf477b 100644 --- a/homeassistant/components/doorbird/__init__.py +++ b/homeassistant/components/doorbird/__init__.py @@ -15,7 +15,6 @@ from homeassistant.const import ( CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME, - HTTP_OK, HTTP_UNAUTHORIZED, ) from homeassistant.core import HomeAssistant, callback @@ -345,7 +344,7 @@ class DoorBirdRequestView(HomeAssistantView): hass.bus.async_fire(RESET_DEVICE_FAVORITES, {"token": token}) message = f"HTTP Favorites cleared for {device.slug}" - return web.Response(status=HTTP_OK, text=message) + return web.Response(text=message) event_data[ATTR_ENTITY_ID] = hass.data[DOMAIN][ DOOR_STATION_EVENT_ENTITY_IDS @@ -353,4 +352,4 @@ class DoorBirdRequestView(HomeAssistantView): hass.bus.async_fire(f"{DOMAIN}_{event}", event_data) - return web.Response(status=HTTP_OK, text="OK") + return web.Response(text="OK") diff --git a/homeassistant/components/geofency/__init__.py b/homeassistant/components/geofency/__init__.py index 1cbaea23733..6d604ec6e30 100644 --- a/homeassistant/components/geofency/__init__.py +++ b/homeassistant/components/geofency/__init__.py @@ -8,7 +8,6 @@ from homeassistant.const import ( ATTR_LONGITUDE, ATTR_NAME, CONF_WEBHOOK_ID, - HTTP_OK, HTTP_UNPROCESSABLE_ENTITY, STATE_NOT_HOME, ) @@ -129,7 +128,7 @@ def _set_location(hass, data, location_name): data, ) - return web.Response(text=f"Setting location for {device}", status=HTTP_OK) + return web.Response(text=f"Setting location for {device}") async def async_setup_entry(hass, entry): diff --git a/homeassistant/components/gpslogger/__init__.py b/homeassistant/components/gpslogger/__init__.py index 0ec8e658867..0c475872093 100644 --- a/homeassistant/components/gpslogger/__init__.py +++ b/homeassistant/components/gpslogger/__init__.py @@ -10,7 +10,6 @@ from homeassistant.const import ( ATTR_LATITUDE, ATTR_LONGITUDE, CONF_WEBHOOK_ID, - HTTP_OK, HTTP_UNPROCESSABLE_ENTITY, ) from homeassistant.helpers import config_entry_flow @@ -91,7 +90,7 @@ async def handle_webhook(hass, webhook_id, request): attrs, ) - return web.Response(text=f"Setting location for {device}", status=HTTP_OK) + return web.Response(text=f"Setting location for {device}") async def async_setup_entry(hass, entry): diff --git a/homeassistant/components/locative/__init__.py b/homeassistant/components/locative/__init__.py index 97df92a9f89..52cfc7900ba 100644 --- a/homeassistant/components/locative/__init__.py +++ b/homeassistant/components/locative/__init__.py @@ -12,7 +12,6 @@ from homeassistant.const import ( ATTR_LATITUDE, ATTR_LONGITUDE, CONF_WEBHOOK_ID, - HTTP_OK, HTTP_UNPROCESSABLE_ENTITY, STATE_NOT_HOME, ) @@ -78,7 +77,7 @@ async def handle_webhook(hass, webhook_id, request): if direction == "enter": async_dispatcher_send(hass, TRACKER_UPDATE, device, gps_location, location_name) - return web.Response(text=f"Setting location to {location_name}", status=HTTP_OK) + return web.Response(text=f"Setting location to {location_name}") if direction == "exit": current_state = hass.states.get(f"{DEVICE_TRACKER}.{device}") @@ -88,7 +87,7 @@ async def handle_webhook(hass, webhook_id, request): async_dispatcher_send( hass, TRACKER_UPDATE, device, gps_location, location_name ) - return web.Response(text="Setting location to not home", status=HTTP_OK) + return web.Response(text="Setting location to not home") # Ignore the message if it is telling us to exit a zone that we # aren't currently in. This occurs when a zone is entered @@ -96,13 +95,12 @@ async def handle_webhook(hass, webhook_id, request): # be sent first, then the exit message will be sent second. return web.Response( text=f"Ignoring exit from {location_name} (already in {current_state})", - status=HTTP_OK, ) if direction == "test": # In the app, a test message can be sent. Just return something to # the user to let them know that it works. - return web.Response(text="Received test message.", status=HTTP_OK) + return web.Response(text="Received test message.") _LOGGER.error("Received unidentified message from Locative: %s", direction) return web.Response( diff --git a/homeassistant/components/plaato/__init__.py b/homeassistant/components/plaato/__init__.py index c214061c416..333ee6b6e95 100644 --- a/homeassistant/components/plaato/__init__.py +++ b/homeassistant/components/plaato/__init__.py @@ -29,7 +29,6 @@ from homeassistant.const import ( CONF_SCAN_INTERVAL, CONF_TOKEN, CONF_WEBHOOK_ID, - HTTP_OK, TEMP_CELSIUS, TEMP_FAHRENHEIT, VOLUME_GALLONS, @@ -199,7 +198,7 @@ async def handle_webhook(hass, webhook_id, request): async_dispatcher_send(hass, SENSOR_UPDATE, *(device_id, sensor_data)) - return web.Response(text=f"Saving status for {device_id}", status=HTTP_OK) + return web.Response(text=f"Saving status for {device_id}") def _device_id(data): diff --git a/homeassistant/components/rss_feed_template/__init__.py b/homeassistant/components/rss_feed_template/__init__.py index 4ea9c27b82e..222b533235d 100644 --- a/homeassistant/components/rss_feed_template/__init__.py +++ b/homeassistant/components/rss_feed_template/__init__.py @@ -5,7 +5,6 @@ from aiohttp import web import voluptuous as vol from homeassistant.components.http import HomeAssistantView -from homeassistant.const import HTTP_OK import homeassistant.helpers.config_validation as cv CONTENT_TYPE_XML = "text/xml" @@ -101,6 +100,4 @@ class RssView(HomeAssistantView): response += "\n" - return web.Response( - body=response, content_type=CONTENT_TYPE_XML, status=HTTP_OK - ) + return web.Response(body=response, content_type=CONTENT_TYPE_XML) diff --git a/homeassistant/components/traccar/__init__.py b/homeassistant/components/traccar/__init__.py index 439bdc6f09e..916b0f71169 100644 --- a/homeassistant/components/traccar/__init__.py +++ b/homeassistant/components/traccar/__init__.py @@ -3,12 +3,7 @@ from aiohttp import web import voluptuous as vol from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER -from homeassistant.const import ( - ATTR_ID, - CONF_WEBHOOK_ID, - HTTP_OK, - HTTP_UNPROCESSABLE_ENTITY, -) +from homeassistant.const import ATTR_ID, CONF_WEBHOOK_ID, HTTP_UNPROCESSABLE_ENTITY from homeassistant.helpers import config_entry_flow import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_send @@ -31,7 +26,7 @@ PLATFORMS = [DEVICE_TRACKER] TRACKER_UPDATE = f"{DOMAIN}_tracker_update" -DEFAULT_ACCURACY = HTTP_OK +DEFAULT_ACCURACY = 200 DEFAULT_BATTERY = -1 @@ -87,7 +82,7 @@ async def handle_webhook(hass, webhook_id, request): attrs, ) - return web.Response(text=f"Setting location for {device}", status=HTTP_OK) + return web.Response(text=f"Setting location for {device}") async def async_setup_entry(hass, entry): diff --git a/tests/components/api/test_init.py b/tests/components/api/test_init.py index 6d5d2608f06..400755c39cd 100644 --- a/tests/components/api/test_init.py +++ b/tests/components/api/test_init.py @@ -395,7 +395,7 @@ async def test_api_error_log( assert resp.status == 401 with patch( - "aiohttp.web.FileResponse", return_value=web.Response(status=200, text="Hello") + "aiohttp.web.FileResponse", return_value=web.Response(text="Hello") ) as mock_file: resp = await client.get( const.URL_API_ERROR_LOG, diff --git a/tests/components/http/test_auth.py b/tests/components/http/test_auth.py index 6bd1d622b12..71d848d12ab 100644 --- a/tests/components/http/test_auth.py +++ b/tests/components/http/test_auth.py @@ -36,7 +36,7 @@ async def mock_handler(request): user = request.get("hass_user") user_id = user.id if user else None - return web.json_response(status=200, data={"user_id": user_id}) + return web.json_response(data={"user_id": user_id}) async def get_legacy_user(auth): diff --git a/tests/components/http/test_cors.py b/tests/components/http/test_cors.py index 04447191fd5..d03b40b2df3 100644 --- a/tests/components/http/test_cors.py +++ b/tests/components/http/test_cors.py @@ -44,7 +44,7 @@ async def test_cors_middleware_loaded_from_config(hass): async def mock_handler(request): """Return if request was authenticated.""" - return web.Response(status=200) + return web.Response() @pytest.fixture