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
This commit is contained in:
Ville Skyttä 2021-09-21 20:51:12 +03:00 committed by GitHub
parent 26e9590927
commit 1aa7c87151
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 15 additions and 29 deletions

View file

@ -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")

View file

@ -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):

View file

@ -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):

View file

@ -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(

View file

@ -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):

View file

@ -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 += "</rss>\n"
return web.Response(
body=response, content_type=CONTENT_TYPE_XML, status=HTTP_OK
)
return web.Response(body=response, content_type=CONTENT_TYPE_XML)

View file

@ -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):

View file

@ -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,

View file

@ -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):

View file

@ -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