Remove deprecated YAML configuration from CPU Speed (#67166)
This commit is contained in:
parent
85b87ffb8b
commit
14059c5aa9
4 changed files with 4 additions and 82 deletions
|
@ -6,7 +6,6 @@ from typing import Any
|
|||
from cpuinfo import cpuinfo
|
||||
|
||||
from homeassistant.config_entries import ConfigFlow
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
|
||||
from .const import DOMAIN
|
||||
|
@ -36,8 +35,3 @@ class CPUSpeedFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||
title=self._imported_name or "CPU Speed",
|
||||
data={},
|
||||
)
|
||||
|
||||
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
|
||||
"""Handle a flow initialized by importing a config."""
|
||||
self._imported_name = config.get(CONF_NAME)
|
||||
return await self.async_step_user(user_input={})
|
||||
|
|
|
@ -2,17 +2,12 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from cpuinfo import cpuinfo
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import CONF_NAME, FREQUENCY_GIGAHERTZ
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import FREQUENCY_GIGAHERTZ
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from .const import DOMAIN, LOGGER
|
||||
|
||||
ATTR_BRAND = "brand"
|
||||
ATTR_HZ = "ghz_advertised"
|
||||
|
@ -21,34 +16,6 @@ ATTR_ARCH = "arch"
|
|||
HZ_ACTUAL = "hz_actual"
|
||||
HZ_ADVERTISED = "hz_advertised"
|
||||
|
||||
DEFAULT_NAME = "CPU speed"
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the CPU speed sensor."""
|
||||
LOGGER.warning(
|
||||
"Configuration of the CPU Speed 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_NAME: config[CONF_NAME]},
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
from homeassistant.components.cpuspeed.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import (
|
||||
RESULT_TYPE_ABORT,
|
||||
|
@ -62,26 +61,6 @@ async def test_already_configured(
|
|||
assert len(mock_cpuinfo_config_flow.mock_calls) == 0
|
||||
|
||||
|
||||
async def test_import_flow(
|
||||
hass: HomeAssistant,
|
||||
mock_cpuinfo_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_NAME: "Frenck's CPU"},
|
||||
)
|
||||
|
||||
assert result.get("type") == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result.get("title") == "Frenck's CPU"
|
||||
assert result.get("data") == {}
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
assert len(mock_cpuinfo_config_flow.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_not_compatible(
|
||||
hass: HomeAssistant,
|
||||
mock_cpuinfo_config_flow: MagicMock,
|
||||
|
|
|
@ -4,10 +4,8 @@ from unittest.mock import MagicMock
|
|||
import pytest
|
||||
|
||||
from homeassistant.components.cpuspeed.const import DOMAIN
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
@ -48,19 +46,3 @@ async def test_config_entry_not_compatible(
|
|||
assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR
|
||||
assert len(mock_cpuinfo.mock_calls) == 1
|
||||
assert "is not compatible with your system" in caplog.text
|
||||
|
||||
|
||||
async def test_import_config(
|
||||
hass: HomeAssistant,
|
||||
mock_cpuinfo: MagicMock,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test the CPU Speed being set up from config via import."""
|
||||
assert await async_setup_component(
|
||||
hass, SENSOR_DOMAIN, {SENSOR_DOMAIN: {"platform": DOMAIN}}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||
assert len(mock_cpuinfo.mock_calls) == 3
|
||||
assert "the CPU Speed platform in YAML is deprecated" in caplog.text
|
||||
|
|
Loading…
Add table
Reference in a new issue