mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Rename rest_command request to response, add exc_info for exceptions (#28521)
* rename request to response, isort and black fixes * Log exception details * Add status code to success log, reformat log * new syntax for response * changed info to debug
This commit is contained in:
parent
0bd01ba495
commit
23737e0225
@ -4,17 +4,16 @@ import logging
|
|||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from aiohttp import hdrs
|
from aiohttp import hdrs
|
||||||
import async_timeout
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_TIMEOUT,
|
|
||||||
CONF_USERNAME,
|
|
||||||
CONF_PASSWORD,
|
|
||||||
CONF_URL,
|
|
||||||
CONF_PAYLOAD,
|
|
||||||
CONF_METHOD,
|
|
||||||
CONF_HEADERS,
|
CONF_HEADERS,
|
||||||
|
CONF_METHOD,
|
||||||
|
CONF_PASSWORD,
|
||||||
|
CONF_PAYLOAD,
|
||||||
|
CONF_TIMEOUT,
|
||||||
|
CONF_URL,
|
||||||
|
CONF_USERNAME,
|
||||||
CONF_VERIFY_SSL,
|
CONF_VERIFY_SSL,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
@ -96,21 +95,32 @@ async def async_setup(hass, config):
|
|||||||
|
|
||||||
request_url = template_url.async_render(variables=service.data)
|
request_url = template_url.async_render(variables=service.data)
|
||||||
try:
|
try:
|
||||||
with async_timeout.timeout(timeout):
|
async with getattr(websession, method)(
|
||||||
request = await getattr(websession, method)(
|
request_url,
|
||||||
request_url, data=payload, auth=auth, headers=headers
|
data=payload,
|
||||||
)
|
auth=auth,
|
||||||
|
headers=headers,
|
||||||
|
timeout=timeout,
|
||||||
|
) as response:
|
||||||
|
|
||||||
if request.status < 400:
|
if response.status < 400:
|
||||||
_LOGGER.info("Success call %s.", request.url)
|
_LOGGER.debug(
|
||||||
else:
|
"Success. Url: %s. Status code: %d.",
|
||||||
_LOGGER.warning("Error %d on call %s.", request.status, request.url)
|
response.url,
|
||||||
|
response.status,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
_LOGGER.warning(
|
||||||
|
"Error. Url: %s. Status code %d.",
|
||||||
|
response.url,
|
||||||
|
response.status,
|
||||||
|
)
|
||||||
|
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
_LOGGER.warning("Timeout call %s.", request.url)
|
_LOGGER.warning("Timeout call %s.", response.url, exc_info=1)
|
||||||
|
|
||||||
except aiohttp.ClientError:
|
except aiohttp.ClientError:
|
||||||
_LOGGER.error("Client error %s.", request_url)
|
_LOGGER.error("Client error %s.", request_url, exc_info=1)
|
||||||
|
|
||||||
# register services
|
# register services
|
||||||
hass.services.async_register(DOMAIN, name, async_service_handler)
|
hass.services.async_register(DOMAIN, name, async_service_handler)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user