Skip to content

Commit

Permalink
refactor: use http.HTTPStatus instead of const.HTTP_* (#87)
Browse files Browse the repository at this point in the history
Addressing future HA change: home-assistant/core#58380
  • Loading branch information
scop authored Oct 26, 2021
1 parent 705ba93 commit 25466ce
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions custom_components/tesla_custom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import asyncio
from collections import defaultdict
from datetime import timedelta
from http import HTTPStatus
import logging

import async_timeout
Expand All @@ -12,7 +13,6 @@
CONF_TOKEN,
CONF_USERNAME,
EVENT_HOMEASSISTANT_CLOSE,
HTTP_UNAUTHORIZED,
)
from homeassistant.core import callback
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
Expand Down Expand Up @@ -169,7 +169,7 @@ async def async_setup_entry(hass, config_entry):
raise ConfigEntryNotReady from ex
except TeslaException as ex:
await async_client.aclose()
if ex.code == HTTP_UNAUTHORIZED:
if ex.code == HTTPStatus.UNAUTHORIZED:
raise ConfigEntryAuthFailed from ex
if ex.message in [
"VEHICLE_UNAVAILABLE",
Expand Down
4 changes: 2 additions & 2 deletions custom_components/tesla_custom/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tesla Config Flow."""
from http import HTTPStatus
import logging

from homeassistant import config_entries, core, exceptions
Expand All @@ -7,7 +8,6 @@
CONF_SCAN_INTERVAL,
CONF_TOKEN,
CONF_USERNAME,
HTTP_UNAUTHORIZED,
)
from homeassistant.core import callback
from homeassistant.helpers import config_validation as cv
Expand Down Expand Up @@ -167,7 +167,7 @@ async def validate_input(hass: core.HomeAssistant, data):
_LOGGER.error("Authentication error: %s %s", ex.message, ex)
raise InvalidAuth() from ex
except TeslaException as ex:
if ex.code == HTTP_UNAUTHORIZED or isinstance(ex, IncompleteCredentials):
if ex.code == HTTPStatus.UNAUTHORIZED or isinstance(ex, IncompleteCredentials):
_LOGGER.error("Invalid credentials: %s", ex.message)
raise InvalidAuth() from ex
_LOGGER.error("Unable to communicate with Tesla API: %s", ex.message)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test the Tesla config flow."""
import datetime
from http import HTTPStatus
from unittest.mock import patch

from homeassistant import config_entries, data_entry_flow, setup
Expand All @@ -8,7 +9,6 @@
CONF_SCAN_INTERVAL,
CONF_TOKEN,
CONF_USERNAME,
HTTP_NOT_FOUND,
)
from pytest_homeassistant_custom_component.common import MockConfigEntry
from teslajsonpy.exceptions import IncompleteCredentials, TeslaException
Expand Down Expand Up @@ -114,7 +114,7 @@ async def test_form_cannot_connect(hass):

with patch(
"custom_components.tesla_custom.config_flow.TeslaAPI.connect",
side_effect=TeslaException(code=HTTP_NOT_FOUND),
side_effect=TeslaException(code=HTTPStatus.NOT_FOUND),
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
Expand Down

0 comments on commit 25466ce

Please sign in to comment.