Add ClimaCell v4 API support (#47575)

* Add ClimaCell v4 API support

* fix tests

* use constants

* fix logic and update tests

* revert accidental changes and enable hourly and nowcast forecast entities in test

* use variable instead of accessing dictionary multiple times

* only grab necessary fields

* add _translate_condition method ot base class

* bump pyclimacell again to fix bug

* switch typehints back to new format

* more typehint fixes

* fix tests

* revert merge conflict change

* handle 'migration' in async_setup_entry so we don't have to bump config entry versions

* parametrize timestep test
This commit is contained in:
Raman Gupta 2021-04-05 13:39:39 -04:00 committed by GitHub
parent 0f757c3db2
commit d0b3f76a6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 5973 additions and 219 deletions

View file

@ -21,7 +21,13 @@ from homeassistant.components.climacell.const import (
DOMAIN,
)
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
from homeassistant.const import (
CONF_API_KEY,
CONF_API_VERSION,
CONF_LATITUDE,
CONF_LONGITUDE,
CONF_NAME,
)
from homeassistant.helpers.typing import HomeAssistantType
from .const import API_KEY, MIN_CONFIG
@ -48,6 +54,32 @@ async def test_user_flow_minimum_fields(hass: HomeAssistantType) -> None:
assert result["title"] == DEFAULT_NAME
assert result["data"][CONF_NAME] == DEFAULT_NAME
assert result["data"][CONF_API_KEY] == API_KEY
assert result["data"][CONF_API_VERSION] == 4
assert result["data"][CONF_LATITUDE] == hass.config.latitude
assert result["data"][CONF_LONGITUDE] == hass.config.longitude
async def test_user_flow_v3(hass: HomeAssistantType) -> None:
"""Test user config flow with v3 API."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user"
data = _get_config_schema(hass, MIN_CONFIG)(MIN_CONFIG)
data[CONF_API_VERSION] = 3
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input=data,
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == DEFAULT_NAME
assert result["data"][CONF_NAME] == DEFAULT_NAME
assert result["data"][CONF_API_KEY] == API_KEY
assert result["data"][CONF_API_VERSION] == 3
assert result["data"][CONF_LATITUDE] == hass.config.latitude
assert result["data"][CONF_LONGITUDE] == hass.config.longitude
@ -60,6 +92,7 @@ async def test_user_flow_same_unique_ids(hass: HomeAssistantType) -> None:
data=user_input,
source=SOURCE_USER,
unique_id=_get_unique_id(hass, user_input),
version=2,
).add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
@ -75,7 +108,7 @@ async def test_user_flow_same_unique_ids(hass: HomeAssistantType) -> None:
async def test_user_flow_cannot_connect(hass: HomeAssistantType) -> None:
"""Test user config flow when ClimaCell can't connect."""
with patch(
"homeassistant.components.climacell.config_flow.ClimaCell.realtime",
"homeassistant.components.climacell.config_flow.ClimaCellV4.realtime",
side_effect=CantConnectException,
):
result = await hass.config_entries.flow.async_init(
@ -91,7 +124,7 @@ async def test_user_flow_cannot_connect(hass: HomeAssistantType) -> None:
async def test_user_flow_invalid_api(hass: HomeAssistantType) -> None:
"""Test user config flow when API key is invalid."""
with patch(
"homeassistant.components.climacell.config_flow.ClimaCell.realtime",
"homeassistant.components.climacell.config_flow.ClimaCellV4.realtime",
side_effect=InvalidAPIKeyException,
):
result = await hass.config_entries.flow.async_init(
@ -107,7 +140,7 @@ async def test_user_flow_invalid_api(hass: HomeAssistantType) -> None:
async def test_user_flow_rate_limited(hass: HomeAssistantType) -> None:
"""Test user config flow when API key is rate limited."""
with patch(
"homeassistant.components.climacell.config_flow.ClimaCell.realtime",
"homeassistant.components.climacell.config_flow.ClimaCellV4.realtime",
side_effect=RateLimitedException,
):
result = await hass.config_entries.flow.async_init(
@ -123,7 +156,7 @@ async def test_user_flow_rate_limited(hass: HomeAssistantType) -> None:
async def test_user_flow_unknown_exception(hass: HomeAssistantType) -> None:
"""Test user config flow when unknown error occurs."""
with patch(
"homeassistant.components.climacell.config_flow.ClimaCell.realtime",
"homeassistant.components.climacell.config_flow.ClimaCellV4.realtime",
side_effect=UnknownException,
):
result = await hass.config_entries.flow.async_init(
@ -144,6 +177,7 @@ async def test_options_flow(hass: HomeAssistantType) -> None:
data=user_config,
source=SOURCE_USER,
unique_id=_get_unique_id(hass, user_config),
version=1,
)
entry.add_to_hass(hass)