Remove deprecated YAML configuration from PVOutput (#67162)
* Remove deprecated YAML configuration from PVOutput * Clean up platform schemapull/67166/head
parent
c9e46d360b
commit
6bd21f05dc
|
@ -7,7 +7,7 @@ from pvo import PVOutput, PVOutputAuthenticationError, PVOutputError
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow
|
||||
from homeassistant.const import CONF_API_KEY, CONF_NAME
|
||||
from homeassistant.const import CONF_API_KEY
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
@ -83,16 +83,6 @@ class PVOutputFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
|
||||
"""Handle a flow initialized by importing a config."""
|
||||
self.imported_name = config[CONF_NAME]
|
||||
return await self.async_step_user(
|
||||
user_input={
|
||||
CONF_SYSTEM_ID: config[CONF_SYSTEM_ID],
|
||||
CONF_API_KEY: config[CONF_API_KEY],
|
||||
}
|
||||
)
|
||||
|
||||
async def async_step_reauth(self, data: dict[str, Any]) -> FlowResult:
|
||||
"""Handle initiation of re-authentication with PVOutput."""
|
||||
self.reauth_entry = self.hass.config_entries.async_get_entry(
|
||||
|
|
|
@ -21,5 +21,3 @@ ATTR_POWER_CONSUMPTION = "power_consumption"
|
|||
ATTR_EFFICIENCY = "efficiency"
|
||||
|
||||
CONF_SYSTEM_ID = "system_id"
|
||||
|
||||
DEFAULT_NAME = "PVOutput"
|
||||
|
|
|
@ -5,21 +5,17 @@ from collections.abc import Callable
|
|||
from dataclasses import dataclass
|
||||
|
||||
from pvo import Status, System
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
PLATFORM_SCHEMA,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
ATTR_VOLTAGE,
|
||||
CONF_API_KEY,
|
||||
CONF_NAME,
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
ENERGY_WATT_HOUR,
|
||||
|
@ -28,10 +24,8 @@ from homeassistant.const import (
|
|||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import (
|
||||
|
@ -41,20 +35,10 @@ from .const import (
|
|||
ATTR_POWER_CONSUMPTION,
|
||||
ATTR_POWER_GENERATION,
|
||||
CONF_SYSTEM_ID,
|
||||
DEFAULT_NAME,
|
||||
DOMAIN,
|
||||
LOGGER,
|
||||
)
|
||||
from .coordinator import PVOutputDataUpdateCoordinator
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_API_KEY): cv.string,
|
||||
vol.Required(CONF_SYSTEM_ID): cv.string,
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class PVOutputSensorEntityDescriptionMixin:
|
||||
|
@ -129,32 +113,6 @@ SENSORS: tuple[PVOutputSensorEntityDescription, ...] = (
|
|||
)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the PVOutput sensor."""
|
||||
LOGGER.warning(
|
||||
"Configuration of the PVOutput platform in YAML is deprecated and will be "
|
||||
"removed in Home Assistant 2022.4; Your existing configuration "
|
||||
"has been imported into the UI automatically and can be safely removed "
|
||||
"from your configuration.yaml file"
|
||||
)
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={
|
||||
CONF_SYSTEM_ID: config[CONF_SYSTEM_ID],
|
||||
CONF_API_KEY: config[CONF_API_KEY],
|
||||
CONF_NAME: config[CONF_NAME],
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
|
|
|
@ -5,8 +5,8 @@ from unittest.mock import AsyncMock, MagicMock
|
|||
from pvo import PVOutputAuthenticationError, PVOutputConnectionError
|
||||
|
||||
from homeassistant.components.pvoutput.const import CONF_SYSTEM_ID, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_REAUTH, SOURCE_USER
|
||||
from homeassistant.const import CONF_API_KEY, CONF_NAME
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
|
||||
from homeassistant.const import CONF_API_KEY
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import (
|
||||
RESULT_TYPE_ABORT,
|
||||
|
@ -151,33 +151,6 @@ async def test_already_configured(
|
|||
assert result2.get("reason") == "already_configured"
|
||||
|
||||
|
||||
async def test_import_flow(
|
||||
hass: HomeAssistant,
|
||||
mock_pvoutput_config_flow: MagicMock,
|
||||
mock_setup_entry: AsyncMock,
|
||||
) -> None:
|
||||
"""Test the import configuration flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={
|
||||
CONF_SYSTEM_ID: 1337,
|
||||
CONF_API_KEY: "tadaaa",
|
||||
CONF_NAME: "Test",
|
||||
},
|
||||
)
|
||||
|
||||
assert result.get("type") == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result.get("title") == "Test"
|
||||
assert result.get("data") == {
|
||||
CONF_SYSTEM_ID: 1337,
|
||||
CONF_API_KEY: "tadaaa",
|
||||
}
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
assert len(mock_pvoutput_config_flow.system.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_reauth_flow(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
|
|
|
@ -8,12 +8,9 @@ from pvo import (
|
|||
)
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.pvoutput.const import CONF_SYSTEM_ID, DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.components.pvoutput.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||
from homeassistant.const import CONF_API_KEY
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
@ -82,29 +79,3 @@ async def test_config_entry_authentication_failed(
|
|||
assert "context" in flow
|
||||
assert flow["context"].get("source") == SOURCE_REAUTH
|
||||
assert flow["context"].get("entry_id") == mock_config_entry.entry_id
|
||||
|
||||
|
||||
async def test_import_config(
|
||||
hass: HomeAssistant,
|
||||
mock_pvoutput_config_flow: MagicMock,
|
||||
mock_pvoutput: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test PVOutput being set up from config via import."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
SENSOR_DOMAIN,
|
||||
{
|
||||
SENSOR_DOMAIN: {
|
||||
"platform": DOMAIN,
|
||||
CONF_SYSTEM_ID: 12345,
|
||||
CONF_API_KEY: "abcdefghijklmnopqrstuvwxyz",
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||
assert len(mock_pvoutput.status.mock_calls) == 1
|
||||
assert len(mock_pvoutput.system.mock_calls) == 1
|
||||
assert "the PVOutput platform in YAML is deprecated" in caplog.text
|
||||
|
|
Loading…
Reference in New Issue