mirror of
https://github.com/home-assistant/core
synced 2024-07-12 07:21:24 +02:00
Remove YAML import from UptimeRobot (#57761)
This commit is contained in:
parent
cb625d1c7a
commit
0e0430ba36
@ -1,43 +1,19 @@
|
||||
"""UptimeRobot binary_sensor platform."""
|
||||
from __future__ import annotations
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_CONNECTIVITY,
|
||||
PLATFORM_SCHEMA,
|
||||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import CONF_API_KEY
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import DOMAIN
|
||||
from .entity import UptimeRobotEntity
|
||||
|
||||
PLATFORM_SCHEMA = cv.deprecated(
|
||||
vol.All(PLATFORM_SCHEMA.extend({vol.Required(CONF_API_KEY): cv.string}))
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the UptimeRobot binary_sensor platform."""
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
|
@ -111,21 +111,3 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
return self.async_show_form(
|
||||
step_id="reauth_confirm", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
|
||||
)
|
||||
|
||||
async def async_step_import(self, import_config: ConfigType) -> FlowResult:
|
||||
"""Import a config entry from configuration.yaml."""
|
||||
for entry in self._async_current_entries():
|
||||
if entry.data[CONF_API_KEY] == import_config[CONF_API_KEY]:
|
||||
LOGGER.warning(
|
||||
"Already configured. This YAML configuration has already been imported. Please remove it"
|
||||
)
|
||||
return self.async_abort(reason="already_configured")
|
||||
|
||||
imported_config = {CONF_API_KEY: import_config[CONF_API_KEY]}
|
||||
|
||||
_, account = await self._validate_input(imported_config)
|
||||
if account:
|
||||
await self.async_set_unique_id(str(account.user_id))
|
||||
self._abort_if_unique_id_configured()
|
||||
return self.async_create_entry(title=account.email, data=imported_config)
|
||||
return self.async_abort(reason="unknown")
|
||||
|
@ -8,50 +8,20 @@ from homeassistant.components.binary_sensor import DEVICE_CLASS_CONNECTIVITY
|
||||
from homeassistant.components.uptimerobot.const import (
|
||||
ATTRIBUTION,
|
||||
COORDINATOR_UPDATE_INTERVAL,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.const import STATE_ON, STATE_UNAVAILABLE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt
|
||||
|
||||
from .common import (
|
||||
MOCK_UPTIMEROBOT_API_KEY,
|
||||
MOCK_UPTIMEROBOT_MONITOR,
|
||||
UPTIMEROBOT_TEST_ENTITY,
|
||||
MockApiResponseKey,
|
||||
mock_uptimerobot_api_response,
|
||||
setup_uptimerobot_integration,
|
||||
)
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
|
||||
async def test_config_import(hass: HomeAssistant) -> None:
|
||||
"""Test importing YAML configuration."""
|
||||
config = {
|
||||
"binary_sensor": {
|
||||
"platform": DOMAIN,
|
||||
"api_key": MOCK_UPTIMEROBOT_API_KEY,
|
||||
}
|
||||
}
|
||||
with patch(
|
||||
"pyuptimerobot.UptimeRobot.async_get_account_details",
|
||||
return_value=mock_uptimerobot_api_response(key=MockApiResponseKey.ACCOUNT),
|
||||
), patch(
|
||||
"pyuptimerobot.UptimeRobot.async_get_monitors",
|
||||
return_value=mock_uptimerobot_api_response(),
|
||||
):
|
||||
assert await async_setup_component(hass, "binary_sensor", config)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
config_entries = hass.config_entries.async_entries(DOMAIN)
|
||||
|
||||
assert len(config_entries) == 1
|
||||
config_entry = config_entries[0]
|
||||
assert config_entry.source == "import"
|
||||
|
||||
|
||||
async def test_presentation(hass: HomeAssistant) -> None:
|
||||
"""Test the presenstation of UptimeRobot binary_sensors."""
|
||||
await setup_uptimerobot_integration(hass)
|
||||
|
@ -102,66 +102,6 @@ async def test_form_api_error(hass: HomeAssistant, caplog: LogCaptureFixture) ->
|
||||
assert "test error from API." in caplog.text
|
||||
|
||||
|
||||
async def test_flow_import(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
"""Test an import flow."""
|
||||
with patch(
|
||||
"pyuptimerobot.UptimeRobot.async_get_account_details",
|
||||
return_value=mock_uptimerobot_api_response(key=MockApiResponseKey.ACCOUNT),
|
||||
), patch(
|
||||
"homeassistant.components.uptimerobot.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={"platform": DOMAIN, CONF_API_KEY: MOCK_UPTIMEROBOT_API_KEY},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["data"] == {CONF_API_KEY: MOCK_UPTIMEROBOT_API_KEY}
|
||||
|
||||
with patch(
|
||||
"pyuptimerobot.UptimeRobot.async_get_account_details",
|
||||
return_value=mock_uptimerobot_api_response(key=MockApiResponseKey.ACCOUNT),
|
||||
), patch(
|
||||
"homeassistant.components.uptimerobot.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={"platform": DOMAIN, CONF_API_KEY: MOCK_UPTIMEROBOT_API_KEY},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 0
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
with patch(
|
||||
"pyuptimerobot.UptimeRobot.async_get_account_details",
|
||||
return_value=mock_uptimerobot_api_response(
|
||||
key=MockApiResponseKey.ACCOUNT, data={}
|
||||
),
|
||||
), patch(
|
||||
"homeassistant.components.uptimerobot.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={"platform": DOMAIN, CONF_API_KEY: "12345"},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "unknown"
|
||||
|
||||
|
||||
async def test_user_unique_id_already_exists(
|
||||
hass: HomeAssistant,
|
||||
) -> None:
|
||||
|
Loading…
Reference in New Issue
Block a user