Remove deprecated yaml config from Efergy (#61520)
This commit is contained in:
parent
78d028a013
commit
dfc93f6ab8
5 changed files with 6 additions and 97 deletions
|
@ -11,9 +11,8 @@ from homeassistant import config_entries
|
|||
from homeassistant.const import CONF_API_KEY
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import CONF_APPTOKEN, DEFAULT_NAME, DOMAIN
|
||||
from .const import DEFAULT_NAME, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -56,16 +55,6 @@ class EfergyFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_import(self, import_config: ConfigType) -> FlowResult:
|
||||
"""Import a config entry from configuration.yaml."""
|
||||
for entry in self._async_current_entries():
|
||||
if entry.data[CONF_API_KEY] == import_config[CONF_APPTOKEN]:
|
||||
_part = import_config[CONF_APPTOKEN][0:4]
|
||||
_msg = f"Efergy yaml config with partial key {_part} has been imported. Please remove it"
|
||||
_LOGGER.warning(_msg)
|
||||
return self.async_abort(reason="already_configured")
|
||||
return await self.async_step_user({CONF_API_KEY: import_config[CONF_APPTOKEN]})
|
||||
|
||||
async def async_step_reauth(self, config: dict[str, Any]) -> FlowResult:
|
||||
"""Handle a reauthorization flow request."""
|
||||
return await self.async_step_user()
|
||||
|
|
|
@ -3,7 +3,6 @@ from datetime import timedelta
|
|||
|
||||
ATTRIBUTION = "Data provided by Efergy"
|
||||
|
||||
CONF_APPTOKEN = "app_token"
|
||||
CONF_CURRENT_VALUES = "current_values"
|
||||
|
||||
DATA_KEY_API = "api"
|
||||
|
|
|
@ -5,31 +5,20 @@ import logging
|
|||
from re import sub
|
||||
|
||||
from pyefergy import Efergy, exceptions
|
||||
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.const import (
|
||||
CONF_CURRENCY,
|
||||
CONF_MONITORED_VARIABLES,
|
||||
CONF_TYPE,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
POWER_WATT,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_platform
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import EfergyEntity
|
||||
from .const import CONF_APPTOKEN, CONF_CURRENT_VALUES, DATA_KEY_API, DOMAIN
|
||||
from .const import CONF_CURRENT_VALUES, DATA_KEY_API, DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -113,42 +102,6 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||
),
|
||||
)
|
||||
|
||||
TYPES_SCHEMA = vol.In(
|
||||
["current_values", "instant_readings", "amount", "budget", "cost"]
|
||||
)
|
||||
|
||||
|
||||
SENSORS_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_TYPE): TYPES_SCHEMA,
|
||||
vol.Optional(CONF_CURRENCY, default=""): cv.string,
|
||||
vol.Optional("period", default="year"): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
# Deprecated in Home Assistant 2021.11
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_APPTOKEN): cv.string,
|
||||
vol.Optional("utc_offset", default="0"): cv.string,
|
||||
vol.Required(CONF_MONITORED_VARIABLES): [SENSORS_SCHEMA],
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Efergy sensor from yaml."""
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
|
|
|
@ -17,7 +17,6 @@ MULTI_SENSOR_TOKEN = "9r6QGF7dpZfO3fqPTBl1fyRmjV1cGoLT"
|
|||
|
||||
CONF_DATA = {CONF_API_KEY: TOKEN}
|
||||
HID = "12345678901234567890123456789012"
|
||||
IMPORT_DATA = {"platform": "efergy", "app_token": TOKEN}
|
||||
|
||||
BASE_URL = "https://engage.efergy.com/mobile_proxy/"
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from unittest.mock import patch
|
|||
from pyefergy import exceptions
|
||||
|
||||
from homeassistant.components.efergy.const import DEFAULT_NAME, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_REAUTH, SOURCE_USER
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, SOURCE_USER
|
||||
from homeassistant.const import CONF_API_KEY, CONF_SOURCE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import (
|
||||
|
@ -13,14 +13,7 @@ from homeassistant.data_entry_flow import (
|
|||
RESULT_TYPE_FORM,
|
||||
)
|
||||
|
||||
from . import (
|
||||
CONF_DATA,
|
||||
HID,
|
||||
IMPORT_DATA,
|
||||
_patch_efergy,
|
||||
_patch_efergy_status,
|
||||
create_entry,
|
||||
)
|
||||
from . import CONF_DATA, HID, _patch_efergy, _patch_efergy_status, create_entry
|
||||
|
||||
|
||||
def _patch_setup():
|
||||
|
@ -83,30 +76,6 @@ async def test_flow_user_unknown(hass: HomeAssistant):
|
|||
assert result["errors"]["base"] == "unknown"
|
||||
|
||||
|
||||
async def test_flow_import(hass: HomeAssistant):
|
||||
"""Test import step."""
|
||||
with _patch_efergy(), _patch_setup():
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={CONF_SOURCE: SOURCE_IMPORT}, data=IMPORT_DATA
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == DEFAULT_NAME
|
||||
assert result["data"] == CONF_DATA
|
||||
assert result["result"].unique_id == HID
|
||||
|
||||
|
||||
async def test_flow_import_already_configured(hass: HomeAssistant):
|
||||
"""Test import step already configured."""
|
||||
create_entry(hass)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={CONF_SOURCE: SOURCE_IMPORT}, data=IMPORT_DATA
|
||||
)
|
||||
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_flow_reauth(hass: HomeAssistant):
|
||||
"""Test reauth step."""
|
||||
entry = create_entry(hass)
|
||||
|
|
Loading…
Add table
Reference in a new issue