mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 00:37:13 +00:00
Remove deprecated yaml import from Canary (#143410)
This commit is contained in:
parent
08ae05cc76
commit
39807abc7d
@ -8,46 +8,18 @@ from typing import Final
|
||||
|
||||
from canary.api import Api
|
||||
from requests.exceptions import ConnectTimeout, HTTPError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_TIMEOUT, CONF_USERNAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
CONF_FFMPEG_ARGUMENTS,
|
||||
DEFAULT_FFMPEG_ARGUMENTS,
|
||||
DEFAULT_TIMEOUT,
|
||||
DOMAIN,
|
||||
)
|
||||
from .const import CONF_FFMPEG_ARGUMENTS, DEFAULT_FFMPEG_ARGUMENTS, DEFAULT_TIMEOUT
|
||||
from .coordinator import CanaryConfigEntry, CanaryDataUpdateCoordinator
|
||||
|
||||
_LOGGER: Final = logging.getLogger(__name__)
|
||||
|
||||
MIN_TIME_BETWEEN_UPDATES: Final = timedelta(seconds=30)
|
||||
|
||||
CONFIG_SCHEMA: Final = vol.Schema(
|
||||
vol.All(
|
||||
cv.deprecated(DOMAIN),
|
||||
{
|
||||
DOMAIN: vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(
|
||||
CONF_TIMEOUT, default=DEFAULT_TIMEOUT
|
||||
): cv.positive_int,
|
||||
}
|
||||
)
|
||||
},
|
||||
),
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
PLATFORMS: Final[list[Platform]] = [
|
||||
Platform.ALARM_CONTROL_PANEL,
|
||||
Platform.CAMERA,
|
||||
@ -55,37 +27,6 @@ PLATFORMS: Final[list[Platform]] = [
|
||||
]
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Canary integration."""
|
||||
if hass.config_entries.async_entries(DOMAIN):
|
||||
return True
|
||||
|
||||
ffmpeg_arguments = DEFAULT_FFMPEG_ARGUMENTS
|
||||
if CAMERA_DOMAIN in config:
|
||||
camera_config = next(
|
||||
(item for item in config[CAMERA_DOMAIN] if item["platform"] == DOMAIN),
|
||||
None,
|
||||
)
|
||||
|
||||
if camera_config:
|
||||
ffmpeg_arguments = camera_config.get(
|
||||
CONF_FFMPEG_ARGUMENTS, DEFAULT_FFMPEG_ARGUMENTS
|
||||
)
|
||||
|
||||
if DOMAIN in config:
|
||||
if ffmpeg_arguments != DEFAULT_FFMPEG_ARGUMENTS:
|
||||
config[DOMAIN][CONF_FFMPEG_ARGUMENTS] = ffmpeg_arguments
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data=config[DOMAIN],
|
||||
)
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: CanaryConfigEntry) -> bool:
|
||||
"""Set up Canary from a config entry."""
|
||||
if not entry.options:
|
||||
|
@ -54,10 +54,6 @@ class CanaryConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
"""Get the options flow for this handler."""
|
||||
return CanaryOptionsFlowHandler()
|
||||
|
||||
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
|
||||
"""Handle a flow initiated by configuration file."""
|
||||
return await self.async_step_user(import_data)
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
|
@ -37,13 +37,6 @@ YAML_CONFIG = {
|
||||
}
|
||||
|
||||
|
||||
def _patch_async_setup(return_value=True):
|
||||
return patch(
|
||||
"homeassistant.components.canary.async_setup",
|
||||
return_value=return_value,
|
||||
)
|
||||
|
||||
|
||||
def _patch_async_setup_entry(return_value=True):
|
||||
return patch(
|
||||
"homeassistant.components.canary.async_setup_entry",
|
||||
|
@ -8,7 +8,6 @@ from homeassistant.components.alarm_control_panel import (
|
||||
DOMAIN as ALARM_DOMAIN,
|
||||
AlarmControlPanelState,
|
||||
)
|
||||
from homeassistant.components.canary import DOMAIN
|
||||
from homeassistant.const import (
|
||||
SERVICE_ALARM_ARM_AWAY,
|
||||
SERVICE_ALARM_ARM_HOME,
|
||||
@ -19,9 +18,8 @@ from homeassistant.const import (
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity_component import async_update_entity
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import mock_device, mock_location, mock_mode
|
||||
from . import init_integration, mock_device, mock_location, mock_mode
|
||||
|
||||
|
||||
async def test_alarm_control_panel(
|
||||
@ -43,10 +41,8 @@ async def test_alarm_control_panel(
|
||||
instance = canary.return_value
|
||||
instance.get_locations.return_value = [mocked_location]
|
||||
|
||||
config = {DOMAIN: {"username": "test-username", "password": "test-password"}}
|
||||
with patch("homeassistant.components.canary.PLATFORMS", ["alarm_control_panel"]):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
await init_integration(hass)
|
||||
|
||||
entity_id = "alarm_control_panel.home"
|
||||
entity_entry = entity_registry.async_get(entity_id)
|
||||
@ -124,10 +120,8 @@ async def test_alarm_control_panel_services(hass: HomeAssistant, canary) -> None
|
||||
instance = canary.return_value
|
||||
instance.get_locations.return_value = [mocked_location]
|
||||
|
||||
config = {DOMAIN: {"username": "test-username", "password": "test-password"}}
|
||||
with patch("homeassistant.components.canary.PLATFORMS", ["alarm_control_panel"]):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
await init_integration(hass)
|
||||
|
||||
entity_id = "alarm_control_panel.home"
|
||||
|
||||
|
@ -15,7 +15,7 @@ from homeassistant.const import CONF_TIMEOUT
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from . import USER_INPUT, _patch_async_setup, _patch_async_setup_entry, init_integration
|
||||
from . import USER_INPUT, _patch_async_setup_entry, init_integration
|
||||
|
||||
|
||||
async def test_user_form(hass: HomeAssistant, canary_config_flow) -> None:
|
||||
@ -27,10 +27,7 @@ async def test_user_form(hass: HomeAssistant, canary_config_flow) -> None:
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] == {}
|
||||
|
||||
with (
|
||||
_patch_async_setup() as mock_setup,
|
||||
_patch_async_setup_entry() as mock_setup_entry,
|
||||
):
|
||||
with _patch_async_setup_entry() as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
USER_INPUT,
|
||||
@ -41,7 +38,6 @@ async def test_user_form(hass: HomeAssistant, canary_config_flow) -> None:
|
||||
assert result["title"] == "test-username"
|
||||
assert result["data"] == {**USER_INPUT, CONF_TIMEOUT: DEFAULT_TIMEOUT}
|
||||
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
@ -120,7 +116,7 @@ async def test_options_flow(hass: HomeAssistant, canary) -> None:
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "init"
|
||||
|
||||
with _patch_async_setup(), _patch_async_setup_entry():
|
||||
with _patch_async_setup_entry():
|
||||
result = await hass.config_entries.options.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_FFMPEG_ARGUMENTS: "-v", CONF_TIMEOUT: 7},
|
||||
|
@ -1,59 +1,12 @@
|
||||
"""The tests for the Canary component."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from requests import ConnectTimeout
|
||||
|
||||
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
|
||||
from homeassistant.components.canary.const import CONF_FFMPEG_ARGUMENTS, DOMAIN
|
||||
from homeassistant.components.canary.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_TIMEOUT, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import YAML_CONFIG, init_integration
|
||||
|
||||
|
||||
async def test_import_from_yaml(hass: HomeAssistant, canary) -> None:
|
||||
"""Test import from YAML."""
|
||||
with patch(
|
||||
"homeassistant.components.canary.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: YAML_CONFIG})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entries = hass.config_entries.async_entries(DOMAIN)
|
||||
assert len(entries) == 1
|
||||
|
||||
assert entries[0].data[CONF_USERNAME] == "test-username"
|
||||
assert entries[0].data[CONF_PASSWORD] == "test-password"
|
||||
assert entries[0].data[CONF_TIMEOUT] == 5
|
||||
|
||||
|
||||
async def test_import_from_yaml_ffmpeg(hass: HomeAssistant, canary) -> None:
|
||||
"""Test import from YAML with ffmpeg arguments."""
|
||||
with patch(
|
||||
"homeassistant.components.canary.async_setup_entry",
|
||||
return_value=True,
|
||||
):
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
DOMAIN,
|
||||
{
|
||||
DOMAIN: YAML_CONFIG,
|
||||
CAMERA_DOMAIN: [{"platform": DOMAIN, CONF_FFMPEG_ARGUMENTS: "-v"}],
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entries = hass.config_entries.async_entries(DOMAIN)
|
||||
assert len(entries) == 1
|
||||
|
||||
assert entries[0].data[CONF_USERNAME] == "test-username"
|
||||
assert entries[0].data[CONF_PASSWORD] == "test-password"
|
||||
assert entries[0].data[CONF_TIMEOUT] == 5
|
||||
assert entries[0].data.get(CONF_FFMPEG_ARGUMENTS) == "-v"
|
||||
from . import init_integration
|
||||
|
||||
|
||||
async def test_unload_entry(hass: HomeAssistant, canary) -> None:
|
||||
|
@ -20,10 +20,9 @@ from homeassistant.const import (
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.helpers.entity_component import async_update_entity
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from . import mock_device, mock_location, mock_reading
|
||||
from . import init_integration, mock_device, mock_location, mock_reading
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
@ -48,10 +47,8 @@ async def test_sensors_pro(
|
||||
mock_reading("air_quality", "0.59"),
|
||||
]
|
||||
|
||||
config = {DOMAIN: {"username": "test-username", "password": "test-password"}}
|
||||
with patch("homeassistant.components.canary.PLATFORMS", ["sensor"]):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
await init_integration(hass)
|
||||
|
||||
sensors = {
|
||||
"home_dining_room_temperature": (
|
||||
@ -112,10 +109,8 @@ async def test_sensors_attributes_pro(hass: HomeAssistant, canary) -> None:
|
||||
mock_reading("air_quality", "0.59"),
|
||||
]
|
||||
|
||||
config = {DOMAIN: {"username": "test-username", "password": "test-password"}}
|
||||
with patch("homeassistant.components.canary.PLATFORMS", ["sensor"]):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
await init_integration(hass)
|
||||
|
||||
entity_id = "sensor.home_dining_room_air_quality"
|
||||
state1 = hass.states.get(entity_id)
|
||||
@ -175,10 +170,8 @@ async def test_sensors_flex(
|
||||
mock_reading("wifi", "-57"),
|
||||
]
|
||||
|
||||
config = {DOMAIN: {"username": "test-username", "password": "test-password"}}
|
||||
with patch("homeassistant.components.canary.PLATFORMS", ["sensor"]):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
await init_integration(hass)
|
||||
|
||||
sensors = {
|
||||
"home_dining_room_battery": (
|
||||
|
Loading…
x
Reference in New Issue
Block a user