Remove config import from surepetcare (#107971)

Co-authored-by: jbouwh <jan@jbsoft.nl>
pull/108164/head
G Johansson 2024-01-16 20:57:23 +01:00 committed by GitHub
parent ddaf194f91
commit 639f06843b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 49 additions and 123 deletions

View File

@ -9,25 +9,12 @@ from surepy.enums import EntityType, Location, LockState
from surepy.exceptions import SurePetcareAuthenticationError, SurePetcareError
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_PASSWORD,
CONF_SCAN_INTERVAL,
CONF_TOKEN,
CONF_USERNAME,
Platform,
)
from homeassistant.core import (
DOMAIN as HOMEASSISTANT_DOMAIN,
HomeAssistant,
ServiceCall,
)
from homeassistant.const import CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME, Platform
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from .const import (
@ -35,9 +22,6 @@ from .const import (
ATTR_LOCATION,
ATTR_LOCK_STATE,
ATTR_PET_NAME,
CONF_FEEDERS,
CONF_FLAPS,
CONF_PETS,
DOMAIN,
SERVICE_SET_LOCK_STATE,
SERVICE_SET_PET_LOCATION,
@ -49,66 +33,6 @@ _LOGGER = logging.getLogger(__name__)
PLATFORMS = [Platform.BINARY_SENSOR, Platform.LOCK, Platform.SENSOR]
SCAN_INTERVAL = timedelta(minutes=3)
CONFIG_SCHEMA = vol.Schema(
vol.All(
cv.deprecated(DOMAIN),
{
DOMAIN: vol.Schema(
vol.All(
{
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_FEEDERS): vol.All(
cv.ensure_list, [cv.positive_int]
),
vol.Optional(CONF_FLAPS): vol.All(
cv.ensure_list, [cv.positive_int]
),
vol.Optional(CONF_PETS): vol.All(
cv.ensure_list, [cv.positive_int]
),
vol.Optional(CONF_SCAN_INTERVAL): cv.time_period,
},
cv.deprecated(CONF_FEEDERS),
cv.deprecated(CONF_FLAPS),
cv.deprecated(CONF_PETS),
cv.deprecated(CONF_SCAN_INTERVAL),
)
)
},
),
extra=vol.ALLOW_EXTRA,
)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Sure Petcare integration."""
if DOMAIN not in config:
return True
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data=config[DOMAIN],
)
)
async_create_issue(
hass,
HOMEASSISTANT_DOMAIN,
f"deprecated_yaml_{DOMAIN}",
breaks_in_ha_version="2024.2.0",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml",
translation_placeholders={
"domain": DOMAIN,
"integration_title": "Sure Petcare",
},
)
return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Sure Petcare from a config entry."""

View File

@ -51,10 +51,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Initialize."""
self._username: str | None = None
async def async_step_import(self, import_info: dict[str, Any] | None) -> FlowResult:
"""Set the config entry up from yaml."""
return await self.async_step_user(import_info)
async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:

View File

@ -1,6 +1,4 @@
"""Tests for Sure Petcare integration."""
from homeassistant.components.surepetcare.const import DOMAIN
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
HOUSEHOLD_ID = 987654321
HUB_ID = 123456789
@ -82,13 +80,3 @@ MOCK_API_DATA = {
"devices": [MOCK_HUB, MOCK_CAT_FLAP, MOCK_PET_FLAP, MOCK_FEEDER, MOCK_FELAQUA],
"pets": [MOCK_PET],
}
MOCK_CONFIG = {
DOMAIN: {
CONF_USERNAME: "test-username",
CONF_PASSWORD: "test-password",
"feeders": [12345],
"flaps": [13579, 13576],
"pets": [24680],
},
}

View File

@ -4,8 +4,14 @@ from unittest.mock import patch
import pytest
from surepy import MESTART_RESOURCE
from homeassistant.components.surepetcare.const import DOMAIN
from homeassistant.const import CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME
from homeassistant.core import HomeAssistant
from . import MOCK_API_DATA
from tests.common import MockConfigEntry
async def _mock_call(method, resource):
if method == "GET" and resource == MESTART_RESOURCE:
@ -21,3 +27,20 @@ async def surepetcare():
client.call = _mock_call
client.get_token.return_value = "token"
yield client
@pytest.fixture
async def mock_config_entry_setup(hass: HomeAssistant) -> MockConfigEntry:
"""Help setting up a mocked config entry."""
data = {
CONF_USERNAME: "test-username",
CONF_PASSWORD: "test-password",
CONF_TOKEN: "token",
"feeders": [12345],
"flaps": [13579, 13576],
"pets": [24680],
}
entry = MockConfigEntry(domain=DOMAIN, data=data)
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
return entry

View File

@ -1,10 +1,10 @@
"""The tests for the Sure Petcare binary sensor platform."""
from homeassistant.components.surepetcare.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.setup import async_setup_component
from . import HOUSEHOLD_ID, HUB_ID, MOCK_CONFIG
from . import HOUSEHOLD_ID, HUB_ID
from tests.common import MockConfigEntry
EXPECTED_ENTITY_IDS = {
"binary_sensor.pet_flap_connectivity": f"{HOUSEHOLD_ID}-13576-connectivity",
@ -15,11 +15,10 @@ EXPECTED_ENTITY_IDS = {
}
async def test_binary_sensors(hass: HomeAssistant, surepetcare) -> None:
async def test_binary_sensors(
hass: HomeAssistant, surepetcare, mock_config_entry_setup: MockConfigEntry
) -> None:
"""Test the generation of unique ids."""
assert await async_setup_component(hass, DOMAIN, MOCK_CONFIG)
await hass.async_block_till_done()
entity_registry = er.async_get(hass)
state_entity_ids = hass.states.async_entity_ids()

View File

@ -2,12 +2,12 @@
import pytest
from surepy.exceptions import SurePetcareError
from homeassistant.components.surepetcare.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.setup import async_setup_component
from . import HOUSEHOLD_ID, MOCK_CAT_FLAP, MOCK_CONFIG, MOCK_PET_FLAP
from . import HOUSEHOLD_ID, MOCK_CAT_FLAP, MOCK_PET_FLAP
from tests.common import MockConfigEntry
EXPECTED_ENTITY_IDS = {
"lock.cat_flap_locked_in": f"{HOUSEHOLD_ID}-{MOCK_CAT_FLAP['id']}-locked_in",
@ -19,11 +19,10 @@ EXPECTED_ENTITY_IDS = {
}
async def test_locks(hass: HomeAssistant, surepetcare) -> None:
async def test_locks(
hass: HomeAssistant, surepetcare, mock_config_entry_setup: MockConfigEntry
) -> None:
"""Test the generation of unique ids."""
assert await async_setup_component(hass, DOMAIN, MOCK_CONFIG)
await hass.async_block_till_done()
entity_registry = er.async_get(hass)
state_entity_ids = hass.states.async_entity_ids()
@ -78,11 +77,10 @@ async def test_locks(hass: HomeAssistant, surepetcare) -> None:
assert surepetcare.unlock.call_count == 1
async def test_lock_failing(hass: HomeAssistant, surepetcare) -> None:
async def test_lock_failing(
hass: HomeAssistant, surepetcare, mock_config_entry_setup: MockConfigEntry
) -> None:
"""Test handling of lock failing."""
assert await async_setup_component(hass, DOMAIN, MOCK_CONFIG)
await hass.async_block_till_done()
surepetcare.lock_in.side_effect = SurePetcareError
surepetcare.lock_out.side_effect = SurePetcareError
surepetcare.lock.side_effect = SurePetcareError
@ -96,11 +94,10 @@ async def test_lock_failing(hass: HomeAssistant, surepetcare) -> None:
assert state.state == "unlocked"
async def test_unlock_failing(hass: HomeAssistant, surepetcare) -> None:
async def test_unlock_failing(
hass: HomeAssistant, surepetcare, mock_config_entry_setup: MockConfigEntry
) -> None:
"""Test handling of unlock failing."""
assert await async_setup_component(hass, DOMAIN, MOCK_CONFIG)
await hass.async_block_till_done()
entity_id = list(EXPECTED_ENTITY_IDS)[0]
await hass.services.async_call(

View File

@ -1,10 +1,10 @@
"""Test the surepetcare sensor platform."""
from homeassistant.components.surepetcare.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from homeassistant.setup import async_setup_component
from . import HOUSEHOLD_ID, MOCK_CONFIG, MOCK_FELAQUA
from . import HOUSEHOLD_ID, MOCK_FELAQUA
from tests.common import MockConfigEntry
EXPECTED_ENTITY_IDS = {
"sensor.pet_flap_battery_level": f"{HOUSEHOLD_ID}-13576-battery",
@ -14,11 +14,10 @@ EXPECTED_ENTITY_IDS = {
}
async def test_sensors(hass: HomeAssistant, surepetcare) -> None:
async def test_sensors(
hass: HomeAssistant, surepetcare, mock_config_entry_setup: MockConfigEntry
) -> None:
"""Test the generation of unique ids."""
assert await async_setup_component(hass, DOMAIN, MOCK_CONFIG)
await hass.async_block_till_done()
entity_registry = er.async_get(hass)
state_entity_ids = hass.states.async_entity_ids()