mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Remove yaml import from hive (#132354)
* Raise issue on hive deprecated YAML configuration * Remove YAML import
This commit is contained in:
parent
e7f44048e9
commit
841773bb68
@ -10,65 +10,24 @@ from typing import Any, Concatenate
|
|||||||
from aiohttp.web_exceptions import HTTPException
|
from aiohttp.web_exceptions import HTTPException
|
||||||
from apyhiveapi import Auth, Hive
|
from apyhiveapi import Auth, Hive
|
||||||
from apyhiveapi.helper.hive_exceptions import HiveReauthRequired
|
from apyhiveapi.helper.hive_exceptions import HiveReauthRequired
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant import config_entries
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME
|
from homeassistant.const import CONF_SCAN_INTERVAL
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers import aiohttp_client, config_validation as cv
|
from homeassistant.helpers import aiohttp_client
|
||||||
from homeassistant.helpers.device_registry import DeviceEntry
|
from homeassistant.helpers.device_registry import DeviceEntry
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
from homeassistant.helpers.typing import ConfigType
|
|
||||||
|
|
||||||
from .const import DOMAIN, PLATFORM_LOOKUP, PLATFORMS
|
from .const import DOMAIN, PLATFORM_LOOKUP, PLATFORMS
|
||||||
from .entity import HiveEntity
|
from .entity import HiveEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
|
||||||
vol.All(
|
|
||||||
cv.deprecated(DOMAIN),
|
|
||||||
{
|
|
||||||
DOMAIN: vol.Schema(
|
|
||||||
{
|
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
|
||||||
vol.Required(CONF_USERNAME): cv.string,
|
|
||||||
vol.Optional(CONF_SCAN_INTERVAL, default=2): cv.positive_int,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
},
|
|
||||||
),
|
|
||||||
extra=vol.ALLOW_EXTRA,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|
||||||
"""Hive configuration setup."""
|
|
||||||
hass.data[DOMAIN] = {}
|
|
||||||
|
|
||||||
if DOMAIN not in config:
|
|
||||||
return True
|
|
||||||
|
|
||||||
conf = config[DOMAIN]
|
|
||||||
|
|
||||||
if not hass.config_entries.async_entries(DOMAIN):
|
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": config_entries.SOURCE_IMPORT},
|
|
||||||
data={
|
|
||||||
CONF_USERNAME: conf[CONF_USERNAME],
|
|
||||||
CONF_PASSWORD: conf[CONF_PASSWORD],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up Hive from a config entry."""
|
"""Set up Hive from a config entry."""
|
||||||
|
hass.data.setdefault(DOMAIN, {})
|
||||||
|
|
||||||
web_session = aiohttp_client.async_get_clientsession(hass)
|
web_session = aiohttp_client.async_get_clientsession(hass)
|
||||||
hive_config = dict(entry.data)
|
hive_config = dict(entry.data)
|
||||||
|
@ -163,10 +163,6 @@ class HiveFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
}
|
}
|
||||||
return await self.async_step_user(data)
|
return await self.async_step_user(data)
|
||||||
|
|
||||||
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
|
|
||||||
"""Import user."""
|
|
||||||
return await self.async_step_user(import_data)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@callback
|
@callback
|
||||||
def async_get_options_flow(
|
def async_get_options_flow(
|
||||||
|
@ -25,52 +25,6 @@ MFA_RESEND_CODE = "0000"
|
|||||||
MFA_INVALID_CODE = "HIVE"
|
MFA_INVALID_CODE = "HIVE"
|
||||||
|
|
||||||
|
|
||||||
async def test_import_flow(hass: HomeAssistant) -> None:
|
|
||||||
"""Check import flow."""
|
|
||||||
|
|
||||||
with (
|
|
||||||
patch(
|
|
||||||
"homeassistant.components.hive.config_flow.Auth.login",
|
|
||||||
return_value={
|
|
||||||
"ChallengeName": "SUCCESS",
|
|
||||||
"AuthenticationResult": {
|
|
||||||
"RefreshToken": "mock-refresh-token",
|
|
||||||
"AccessToken": "mock-access-token",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
patch(
|
|
||||||
"homeassistant.components.hive.async_setup", return_value=True
|
|
||||||
) as mock_setup,
|
|
||||||
patch(
|
|
||||||
"homeassistant.components.hive.async_setup_entry",
|
|
||||||
return_value=True,
|
|
||||||
) as mock_setup_entry,
|
|
||||||
):
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": config_entries.SOURCE_IMPORT},
|
|
||||||
data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
|
||||||
)
|
|
||||||
|
|
||||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
|
||||||
assert result["title"] == USERNAME
|
|
||||||
assert result["data"] == {
|
|
||||||
CONF_USERNAME: USERNAME,
|
|
||||||
CONF_PASSWORD: PASSWORD,
|
|
||||||
"tokens": {
|
|
||||||
"AuthenticationResult": {
|
|
||||||
"AccessToken": "mock-access-token",
|
|
||||||
"RefreshToken": "mock-refresh-token",
|
|
||||||
},
|
|
||||||
"ChallengeName": "SUCCESS",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
|
||||||
assert len(mock_setup.mock_calls) == 1
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
|
||||||
|
|
||||||
|
|
||||||
async def test_user_flow(hass: HomeAssistant) -> None:
|
async def test_user_flow(hass: HomeAssistant) -> None:
|
||||||
"""Test the user flow."""
|
"""Test the user flow."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
@ -91,9 +45,6 @@ async def test_user_flow(hass: HomeAssistant) -> None:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
patch(
|
|
||||||
"homeassistant.components.hive.async_setup", return_value=True
|
|
||||||
) as mock_setup,
|
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.components.hive.async_setup_entry",
|
"homeassistant.components.hive.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
@ -119,7 +70,6 @@ async def test_user_flow(hass: HomeAssistant) -> None:
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert len(mock_setup.mock_calls) == 1
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
|
|
||||||
@ -185,9 +135,6 @@ async def test_user_flow_2fa(hass: HomeAssistant) -> None:
|
|||||||
"mock-device-password",
|
"mock-device-password",
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
patch(
|
|
||||||
"homeassistant.components.hive.async_setup", return_value=True
|
|
||||||
) as mock_setup,
|
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.components.hive.async_setup_entry",
|
"homeassistant.components.hive.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
@ -220,7 +167,6 @@ async def test_user_flow_2fa(hass: HomeAssistant) -> None:
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
assert len(mock_setup.mock_calls) == 1
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
|
|
||||||
@ -462,9 +408,6 @@ async def test_user_flow_2fa_send_new_code(hass: HomeAssistant) -> None:
|
|||||||
"mock-device-password",
|
"mock-device-password",
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
patch(
|
|
||||||
"homeassistant.components.hive.async_setup", return_value=True
|
|
||||||
) as mock_setup,
|
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.components.hive.async_setup_entry",
|
"homeassistant.components.hive.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
@ -493,7 +436,6 @@ async def test_user_flow_2fa_send_new_code(hass: HomeAssistant) -> None:
|
|||||||
"mock-device-password",
|
"mock-device-password",
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
assert len(mock_setup.mock_calls) == 1
|
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user