Remove deprecated YAML configuration from Skybell (#76940)

This commit is contained in:
Robert Hillis 2022-08-19 04:56:01 -04:00 committed by GitHub
parent c3305caabe
commit cbeaea98d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 33 additions and 166 deletions

View File

@ -2,39 +2,22 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
import os
from aioskybell import Skybell from aioskybell import Skybell
from aioskybell.exceptions import SkybellAuthenticationException, SkybellException from aioskybell.exceptions import SkybellAuthenticationException, SkybellException
import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry from homeassistant.components.repairs.issue_handler import async_create_issue
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, CONF_USERNAME, Platform from homeassistant.components.repairs.models import IssueSeverity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
from .const import DEFAULT_CACHEDB, DOMAIN from .const import DOMAIN
from .coordinator import SkybellDataUpdateCoordinator from .coordinator import SkybellDataUpdateCoordinator
CONFIG_SCHEMA = vol.Schema(
vol.All(
# Deprecated in Home Assistant 2022.6
cv.deprecated(DOMAIN),
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
}
)
},
),
extra=vol.ALLOW_EXTRA,
)
PLATFORMS = [ PLATFORMS = [
Platform.BINARY_SENSOR, Platform.BINARY_SENSOR,
Platform.CAMERA, Platform.CAMERA,
@ -48,31 +31,17 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the SkyBell component.""" """Set up the SkyBell component."""
hass.data.setdefault(DOMAIN, {}) hass.data.setdefault(DOMAIN, {})
entry_config = {} if DOMAIN in config:
if DOMAIN not in config: async_create_issue(
return True hass,
for parameter, value in config[DOMAIN].items(): DOMAIN,
if parameter == CONF_USERNAME: "removed_yaml",
entry_config[CONF_EMAIL] = value breaks_in_ha_version="2022.9.0",
else: is_fixable=False,
entry_config[parameter] = value severity=IssueSeverity.WARNING,
hass.async_create_task( translation_key="removed_yaml",
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data=entry_config,
)
) )
# Clean up unused cache file since we are using an account specific name
# Remove with import
def clean_cache():
"""Clean old cache filename."""
if os.path.exists(hass.config.path(DEFAULT_CACHEDB)):
os.remove(hass.config.path(DEFAULT_CACHEDB))
await hass.async_add_executor_job(clean_cache)
return True return True

View File

@ -2,18 +2,14 @@
from __future__ import annotations from __future__ import annotations
from aioskybell.helpers import const as CONST from aioskybell.helpers import const as CONST
import voluptuous as vol
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
PLATFORM_SCHEMA,
BinarySensorDeviceClass, BinarySensorDeviceClass,
BinarySensorEntity, BinarySensorEntity,
BinarySensorEntityDescription, BinarySensorEntityDescription,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_ENTITY_NAMESPACE, CONF_MONITORED_CONDITIONS
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import DOMAIN from . import DOMAIN
@ -33,21 +29,11 @@ BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
), ),
) )
# Deprecated in Home Assistant 2022.6
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Optional(CONF_ENTITY_NAMESPACE, default=DOMAIN): cv.string,
vol.Required(CONF_MONITORED_CONDITIONS, default=[]): vol.All(
cv.ensure_list, [vol.In(BINARY_SENSOR_TYPES)]
),
}
)
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None: ) -> None:
"""Set up Skybell switch.""" """Set up Skybell binary sensor."""
async_add_entities( async_add_entities(
SkybellBinarySensor(coordinator, sensor) SkybellBinarySensor(coordinator, sensor)
for sensor in BINARY_SENSOR_TYPES for sensor in BINARY_SENSOR_TYPES

View File

@ -3,43 +3,19 @@ from __future__ import annotations
from aiohttp import web from aiohttp import web
from haffmpeg.camera import CameraMjpeg from haffmpeg.camera import CameraMjpeg
import voluptuous as vol
from homeassistant.components.camera import ( from homeassistant.components.camera import Camera, CameraEntityDescription
PLATFORM_SCHEMA,
Camera,
CameraEntityDescription,
)
from homeassistant.components.ffmpeg import get_ffmpeg_manager from homeassistant.components.ffmpeg import get_ffmpeg_manager
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_MONITORED_CONDITIONS
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_aiohttp_proxy_stream from homeassistant.helpers.aiohttp_client import async_aiohttp_proxy_stream
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import EntityDescription from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import ( from .const import DOMAIN
CONF_ACTIVITY_NAME,
CONF_AVATAR_NAME,
DOMAIN,
IMAGE_ACTIVITY,
IMAGE_AVATAR,
)
from .coordinator import SkybellDataUpdateCoordinator from .coordinator import SkybellDataUpdateCoordinator
from .entity import SkybellEntity from .entity import SkybellEntity
# Deprecated in Home Assistant 2022.6
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Optional(CONF_MONITORED_CONDITIONS, default=[IMAGE_AVATAR]): vol.All(
cv.ensure_list, [vol.In([IMAGE_AVATAR, IMAGE_ACTIVITY])]
),
vol.Optional(CONF_ACTIVITY_NAME): cv.string,
vol.Optional(CONF_AVATAR_NAME): cv.string,
}
)
CAMERA_TYPES: tuple[CameraEntityDescription, ...] = ( CAMERA_TYPES: tuple[CameraEntityDescription, ...] = (
CameraEntityDescription(key="activity", name="Last activity"), CameraEntityDescription(key="activity", name="Last activity"),
CameraEntityDescription(key="avatar", name="Camera"), CameraEntityDescription(key="avatar", name="Camera"),
@ -49,7 +25,7 @@ CAMERA_TYPES: tuple[CameraEntityDescription, ...] = (
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None: ) -> None:
"""Set up Skybell switch.""" """Set up Skybell camera."""
entities = [] entities = []
for description in CAMERA_TYPES: for description in CAMERA_TYPES:
for coordinator in hass.data[DOMAIN][entry.entry_id]: for coordinator in hass.data[DOMAIN][entry.entry_id]:

View File

@ -10,7 +10,6 @@ from homeassistant import config_entries
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
from homeassistant.data_entry_flow import FlowResult from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.typing import ConfigType
from .const import DOMAIN from .const import DOMAIN
@ -18,12 +17,6 @@ from .const import DOMAIN
class SkybellFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): class SkybellFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Skybell.""" """Handle a config flow for Skybell."""
async def async_step_import(self, user_input: ConfigType) -> FlowResult:
"""Import a config entry from configuration.yaml."""
if self._async_current_entries():
return self.async_abort(reason="already_configured")
return await self.async_step_user(user_input)
async def async_step_user( async def async_step_user(
self, user_input: dict[str, Any] | None = None self, user_input: dict[str, Any] | None = None
) -> FlowResult: ) -> FlowResult:

View File

@ -2,9 +2,6 @@
import logging import logging
from typing import Final from typing import Final
CONF_ACTIVITY_NAME = "activity_name"
CONF_AVATAR_NAME = "avatar_name"
DEFAULT_CACHEDB = "./skybell_cache.pickle"
DEFAULT_NAME = "SkyBell" DEFAULT_NAME = "SkyBell"
DOMAIN: Final = "skybell" DOMAIN: Final = "skybell"

View File

@ -4,7 +4,7 @@
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/skybell", "documentation": "https://www.home-assistant.io/integrations/skybell",
"requirements": ["aioskybell==22.7.0"], "requirements": ["aioskybell==22.7.0"],
"dependencies": ["ffmpeg"], "dependencies": ["ffmpeg", "repairs"],
"codeowners": ["@tkdrob"], "codeowners": ["@tkdrob"],
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"loggers": ["aioskybell"] "loggers": ["aioskybell"]

View File

@ -7,18 +7,14 @@ from typing import Any
from aioskybell import SkybellDevice from aioskybell import SkybellDevice
from aioskybell.helpers import const as CONST from aioskybell.helpers import const as CONST
import voluptuous as vol
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
PLATFORM_SCHEMA,
SensorDeviceClass, SensorDeviceClass,
SensorEntity, SensorEntity,
SensorEntityDescription, SensorEntityDescription,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_ENTITY_NAMESPACE, CONF_MONITORED_CONDITIONS
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -95,18 +91,6 @@ SENSOR_TYPES: tuple[SkybellSensorEntityDescription, ...] = (
), ),
) )
MONITORED_CONDITIONS = SENSOR_TYPES
# Deprecated in Home Assistant 2022.6
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Optional(CONF_ENTITY_NAMESPACE, default=DOMAIN): cv.string,
vol.Required(CONF_MONITORED_CONDITIONS, default=[]): vol.All(
cv.ensure_list, [vol.In(MONITORED_CONDITIONS)]
),
}
)
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback

View File

@ -17,5 +17,11 @@
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]", "already_configured": "[%key:common::config_flow::abort::already_configured_account%]",
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]" "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
} }
},
"issues": {
"removed_yaml": {
"title": "The Skybell YAML configuration has been removed",
"description": "Configuring Skybell using YAML has been removed.\n\nYour existing YAML configuration is not used by Home Assistant.\n\nRemove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
}
} }
} }

View File

@ -3,17 +3,9 @@ from __future__ import annotations
from typing import Any, cast from typing import Any, cast
import voluptuous as vol from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
from homeassistant.components.switch import (
PLATFORM_SCHEMA,
SwitchEntity,
SwitchEntityDescription,
)
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_ENTITY_NAMESPACE, CONF_MONITORED_CONDITIONS
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN from .const import DOMAIN
@ -34,16 +26,6 @@ SWITCH_TYPES: tuple[SwitchEntityDescription, ...] = (
), ),
) )
# Deprecated in Home Assistant 2022.6
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Optional(CONF_ENTITY_NAMESPACE, default=DOMAIN): cv.string,
vol.Required(CONF_MONITORED_CONDITIONS, default=[]): vol.All(
cv.ensure_list, [vol.In(SWITCH_TYPES)]
),
}
)
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback

View File

@ -17,5 +17,11 @@
} }
} }
} }
},
"issues": {
"removed_yaml": {
"title": "The Skybell YAML configuration has been removed",
"description": "Configuring Skybell using YAML has been removed.\n\nYour existing YAML configuration is not used by Home Assistant.\n\nRemove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
}
} }
} }

View File

@ -4,7 +4,7 @@ from unittest.mock import patch
from aioskybell import exceptions from aioskybell import exceptions
from homeassistant.components.skybell.const import DOMAIN from homeassistant.components.skybell.const import DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER from homeassistant.config_entries import SOURCE_USER
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType from homeassistant.data_entry_flow import FlowResultType
@ -99,35 +99,3 @@ async def test_flow_user_unknown_error(hass: HomeAssistant) -> None:
assert result["type"] == FlowResultType.FORM assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user" assert result["step_id"] == "user"
assert result["errors"] == {"base": "unknown"} assert result["errors"] == {"base": "unknown"}
async def test_flow_import(hass: HomeAssistant) -> None:
"""Test import step."""
with _patch_skybell(), _patch_skybell_devices(), _patch_setup_entry(), _patch_setup():
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}
)
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input=CONF_CONFIG_FLOW,
)
assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == "user"
assert result["data"] == CONF_CONFIG_FLOW
async def test_flow_import_already_configured(hass: HomeAssistant) -> None:
"""Test import step already configured."""
entry = MockConfigEntry(
domain=DOMAIN, unique_id="123456789012345678901234", data=CONF_CONFIG_FLOW
)
entry.add_to_hass(hass)
with _patch_skybell():
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
)
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "already_configured"