Remove deprecated YAML configuration from Sensibo (#69028)
parent
666cbebd28
commit
b45399b164
|
@ -3,10 +3,7 @@ from __future__ import annotations
|
|||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.climate import (
|
||||
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
|
||||
ClimateEntity,
|
||||
)
|
||||
from homeassistant.components.climate import ClimateEntity
|
||||
from homeassistant.components.climate.const import (
|
||||
HVAC_MODE_COOL,
|
||||
HVAC_MODE_DRY,
|
||||
|
@ -18,36 +15,26 @@ from homeassistant.components.climate.const import (
|
|||
SUPPORT_SWING_MODE,
|
||||
SUPPORT_TARGET_TEMPERATURE,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_STATE,
|
||||
ATTR_TEMPERATURE,
|
||||
CONF_API_KEY,
|
||||
CONF_ID,
|
||||
PRECISION_TENTHS,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers import entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util.temperature import convert as convert_temperature
|
||||
|
||||
from .const import ALL, DOMAIN, LOGGER
|
||||
from .const import DOMAIN
|
||||
from .coordinator import SensiboDataUpdateCoordinator
|
||||
from .entity import SensiboDeviceBaseEntity
|
||||
|
||||
SERVICE_ASSUME_STATE = "assume_state"
|
||||
|
||||
PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_API_KEY): cv.string,
|
||||
vol.Optional(CONF_ID, default=ALL): vol.All(cv.ensure_list, [cv.string]),
|
||||
}
|
||||
)
|
||||
|
||||
FIELD_TO_FLAG = {
|
||||
"fanLevel": SUPPORT_FAN_MODE,
|
||||
"swing": SUPPORT_SWING_MODE,
|
||||
|
@ -74,25 +61,6 @@ AC_STATE_TO_DATA = {
|
|||
}
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up Sensibo devices."""
|
||||
LOGGER.warning(
|
||||
"Loading Sensibo via platform setup is deprecated; Please remove it from your configuration"
|
||||
)
|
||||
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
|
||||
) -> None:
|
||||
|
|
|
@ -75,11 +75,6 @@ class SensiboConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_import(self, config: dict) -> FlowResult:
|
||||
"""Import a configuration from config.yaml."""
|
||||
|
||||
return await self.async_step_user(user_input=config)
|
||||
|
||||
async def async_step_user(self, user_input=None) -> FlowResult:
|
||||
"""Handle the initial step."""
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ PLATFORMS = [
|
|||
Platform.SELECT,
|
||||
Platform.SENSOR,
|
||||
]
|
||||
ALL = ["all"]
|
||||
DEFAULT_NAME = "Sensibo"
|
||||
TIMEOUT = 8
|
||||
|
||||
|
|
|
@ -60,70 +60,6 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_import_flow_success(hass: HomeAssistant) -> None:
|
||||
"""Test a successful import of yaml."""
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices",
|
||||
return_value={"result": [{"id": "xyzxyz"}, {"id": "abcabc"}]},
|
||||
), patch(
|
||||
"homeassistant.components.sensibo.util.SensiboClient.async_get_me",
|
||||
return_value={"result": {"username": "username"}},
|
||||
), patch(
|
||||
"homeassistant.components.sensibo.async_setup_entry",
|
||||
return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result2 = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={
|
||||
CONF_API_KEY: "1234567890",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result2["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result2["title"] == "Sensibo"
|
||||
assert result2["data"] == {
|
||||
"api_key": "1234567890",
|
||||
}
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_import_flow_already_exist(hass: HomeAssistant) -> None:
|
||||
"""Test import of yaml already exist."""
|
||||
|
||||
MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_API_KEY: "1234567890",
|
||||
},
|
||||
unique_id="username",
|
||||
).add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.sensibo.async_setup_entry",
|
||||
return_value=True,
|
||||
), patch(
|
||||
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices",
|
||||
return_value={"result": [{"id": "xyzxyz"}, {"id": "abcabc"}]},
|
||||
), patch(
|
||||
"homeassistant.components.sensibo.util.SensiboClient.async_get_me",
|
||||
return_value={"result": {"username": "username"}},
|
||||
):
|
||||
result3 = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={
|
||||
CONF_API_KEY: "1234567890",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result3["type"] == RESULT_TYPE_ABORT
|
||||
assert result3["reason"] == "already_configured"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"error_message, p_error",
|
||||
[
|
||||
|
|
Loading…
Reference in New Issue