From 2d3318e76770f9db623f7b7ffb4a37eadc71ad46 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Sat, 4 Nov 2023 16:17:31 +0100 Subject: [PATCH] Remove platform YAML from Command line (#103202) --- .../components/command_line/binary_sensor.py | 39 +--------- .../components/command_line/cover.py | 58 ++------------ .../components/command_line/notify.py | 40 ++-------- .../components/command_line/sensor.py | 45 ++--------- .../components/command_line/strings.json | 6 -- .../components/command_line/switch.py | 65 ++-------------- .../command_line/test_binary_sensor.py | 29 ------- tests/components/command_line/test_cover.py | 69 ---------------- tests/components/command_line/test_notify.py | 20 ----- tests/components/command_line/test_sensor.py | 30 ------- tests/components/command_line/test_switch.py | 78 +++---------------- 11 files changed, 36 insertions(+), 443 deletions(-) diff --git a/homeassistant/components/command_line/binary_sensor.py b/homeassistant/components/command_line/binary_sensor.py index 3ccd0bd1503..f559812207f 100644 --- a/homeassistant/components/command_line/binary_sensor.py +++ b/homeassistant/components/command_line/binary_sensor.py @@ -3,13 +3,9 @@ from __future__ import annotations import asyncio from datetime import timedelta - -import voluptuous as vol +from typing import cast from homeassistant.components.binary_sensor import ( - DEVICE_CLASSES_SCHEMA, - DOMAIN as BINARY_SENSOR_DOMAIN, - PLATFORM_SCHEMA, BinarySensorDeviceClass, BinarySensorEntity, ) @@ -25,16 +21,14 @@ from homeassistant.const import ( CONF_VALUE_TEMPLATE, ) from homeassistant.core import HomeAssistant -import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.event import async_track_time_interval -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.template import Template from homeassistant.helpers.trigger_template_entity import ManualTriggerEntity from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.util import dt as dt_util -from .const import CONF_COMMAND_TIMEOUT, DEFAULT_TIMEOUT, DOMAIN, LOGGER +from .const import CONF_COMMAND_TIMEOUT, LOGGER from .sensor import CommandSensorData DEFAULT_NAME = "Binary Command Sensor" @@ -44,20 +38,6 @@ DEFAULT_PAYLOAD_OFF = "OFF" SCAN_INTERVAL = timedelta(seconds=60) -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_COMMAND): cv.string, - vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, - vol.Optional(CONF_PAYLOAD_OFF, default=DEFAULT_PAYLOAD_OFF): cv.string, - vol.Optional(CONF_PAYLOAD_ON, default=DEFAULT_PAYLOAD_ON): cv.string, - vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA, - vol.Optional(CONF_VALUE_TEMPLATE): cv.template, - vol.Optional(CONF_COMMAND_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int, - vol.Optional(CONF_UNIQUE_ID): cv.string, - } -) - - async def async_setup_platform( hass: HomeAssistant, config: ConfigType, @@ -66,19 +46,8 @@ async def async_setup_platform( ) -> None: """Set up the Command line Binary Sensor.""" - if binary_sensor_config := config: - async_create_issue( - hass, - DOMAIN, - "deprecated_yaml_binary_sensor", - breaks_in_ha_version="2023.12.0", - is_fixable=False, - severity=IssueSeverity.WARNING, - translation_key="deprecated_platform_yaml", - translation_placeholders={"platform": BINARY_SENSOR_DOMAIN}, - ) - if discovery_info: - binary_sensor_config = discovery_info + discovery_info = cast(DiscoveryInfoType, discovery_info) + binary_sensor_config = discovery_info name: str = binary_sensor_config.get(CONF_NAME, DEFAULT_NAME) command: str = binary_sensor_config[CONF_COMMAND] diff --git a/homeassistant/components/command_line/cover.py b/homeassistant/components/command_line/cover.py index 2aa67cec641..6b413712ed7 100644 --- a/homeassistant/components/command_line/cover.py +++ b/homeassistant/components/command_line/cover.py @@ -3,59 +3,32 @@ from __future__ import annotations import asyncio from datetime import timedelta -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, cast -import voluptuous as vol - -from homeassistant.components.cover import ( - DOMAIN as COVER_DOMAIN, - PLATFORM_SCHEMA, - CoverEntity, -) +from homeassistant.components.cover import CoverEntity from homeassistant.const import ( CONF_COMMAND_CLOSE, CONF_COMMAND_OPEN, CONF_COMMAND_STATE, CONF_COMMAND_STOP, - CONF_COVERS, - CONF_FRIENDLY_NAME, CONF_NAME, CONF_SCAN_INTERVAL, CONF_UNIQUE_ID, CONF_VALUE_TEMPLATE, ) from homeassistant.core import HomeAssistant -import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.event import async_track_time_interval -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.template import Template from homeassistant.helpers.trigger_template_entity import ManualTriggerEntity from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.util import dt as dt_util, slugify -from .const import CONF_COMMAND_TIMEOUT, DEFAULT_TIMEOUT, DOMAIN, LOGGER +from .const import CONF_COMMAND_TIMEOUT, LOGGER from .utils import call_shell_with_timeout, check_output_or_log SCAN_INTERVAL = timedelta(seconds=15) -COVER_SCHEMA = vol.Schema( - { - vol.Optional(CONF_COMMAND_CLOSE, default="true"): cv.string, - vol.Optional(CONF_COMMAND_OPEN, default="true"): cv.string, - vol.Optional(CONF_COMMAND_STATE): cv.string, - vol.Optional(CONF_COMMAND_STOP, default="true"): cv.string, - vol.Optional(CONF_FRIENDLY_NAME): cv.string, - vol.Optional(CONF_VALUE_TEMPLATE): cv.template, - vol.Optional(CONF_COMMAND_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int, - vol.Optional(CONF_UNIQUE_ID): cv.string, - } -) - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - {vol.Required(CONF_COVERS): cv.schema_with_slug_keys(COVER_SCHEMA)} -) - async def async_setup_platform( hass: HomeAssistant, @@ -66,31 +39,14 @@ async def async_setup_platform( """Set up cover controlled by shell commands.""" covers = [] - if discovery_info: - entities: dict[str, Any] = {slugify(discovery_info[CONF_NAME]): discovery_info} - else: - async_create_issue( - hass, - DOMAIN, - "deprecated_yaml_cover", - breaks_in_ha_version="2023.12.0", - is_fixable=False, - severity=IssueSeverity.WARNING, - translation_key="deprecated_platform_yaml", - translation_placeholders={"platform": COVER_DOMAIN}, - ) - entities = config.get(CONF_COVERS, {}) + discovery_info = cast(DiscoveryInfoType, discovery_info) + entities: dict[str, Any] = {slugify(discovery_info[CONF_NAME]): discovery_info} for device_name, device_config in entities.items(): value_template: Template | None = device_config.get(CONF_VALUE_TEMPLATE) if value_template is not None: value_template.hass = hass - if name := device_config.get( - CONF_FRIENDLY_NAME - ): # Backward compatibility. Can be removed after deprecation - device_config[CONF_NAME] = name - trigger_entity_config = { CONF_UNIQUE_ID: device_config.get(CONF_UNIQUE_ID), CONF_NAME: Template(device_config.get(CONF_NAME, device_name), hass), @@ -109,10 +65,6 @@ async def async_setup_platform( ) ) - if not covers: - LOGGER.error("No covers added") - return - async_add_entities(covers) diff --git a/homeassistant/components/command_line/notify.py b/homeassistant/components/command_line/notify.py index d00926eb0ee..f61e9959af9 100644 --- a/homeassistant/components/command_line/notify.py +++ b/homeassistant/components/command_line/notify.py @@ -3,34 +3,18 @@ from __future__ import annotations import logging import subprocess -from typing import Any +from typing import Any, cast -import voluptuous as vol - -from homeassistant.components.notify import ( - DOMAIN as NOTIFY_DOMAIN, - PLATFORM_SCHEMA, - BaseNotificationService, -) -from homeassistant.const import CONF_COMMAND, CONF_NAME +from homeassistant.components.notify import BaseNotificationService +from homeassistant.const import CONF_COMMAND from homeassistant.core import HomeAssistant -import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.issue_registry import IssueSeverity, create_issue from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.util.process import kill_subprocess -from .const import CONF_COMMAND_TIMEOUT, DEFAULT_TIMEOUT, DOMAIN +from .const import CONF_COMMAND_TIMEOUT _LOGGER = logging.getLogger(__name__) -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_COMMAND): cv.string, - vol.Optional(CONF_NAME): cv.string, - vol.Optional(CONF_COMMAND_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int, - } -) - def get_service( hass: HomeAssistant, @@ -38,19 +22,9 @@ def get_service( discovery_info: DiscoveryInfoType | None = None, ) -> CommandLineNotificationService: """Get the Command Line notification service.""" - if notify_config := config: - create_issue( - hass, - DOMAIN, - "deprecated_yaml_notify", - breaks_in_ha_version="2023.12.0", - is_fixable=False, - severity=IssueSeverity.WARNING, - translation_key="deprecated_platform_yaml", - translation_placeholders={"platform": NOTIFY_DOMAIN}, - ) - if discovery_info: - notify_config = discovery_info + + discovery_info = cast(DiscoveryInfoType, discovery_info) + notify_config = discovery_info command: str = notify_config[CONF_COMMAND] timeout: int = notify_config[CONF_COMMAND_TIMEOUT] diff --git a/homeassistant/components/command_line/sensor.py b/homeassistant/components/command_line/sensor.py index a617d348c8d..99390e77357 100644 --- a/homeassistant/components/command_line/sensor.py +++ b/homeassistant/components/command_line/sensor.py @@ -7,16 +7,7 @@ from datetime import timedelta import json from typing import Any, cast -import voluptuous as vol - -from homeassistant.components.sensor import ( - CONF_STATE_CLASS, - DEVICE_CLASSES_SCHEMA, - DOMAIN as SENSOR_DOMAIN, - PLATFORM_SCHEMA, - STATE_CLASSES_SCHEMA, - SensorDeviceClass, -) +from homeassistant.components.sensor import CONF_STATE_CLASS, SensorDeviceClass from homeassistant.components.sensor.helpers import async_parse_date_datetime from homeassistant.const import ( CONF_COMMAND, @@ -30,10 +21,8 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import TemplateError -import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.event import async_track_time_interval -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.template import Template from homeassistant.helpers.trigger_template_entity import ( CONF_AVAILABILITY, @@ -43,7 +32,7 @@ from homeassistant.helpers.trigger_template_entity import ( from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.util import dt as dt_util -from .const import CONF_COMMAND_TIMEOUT, DEFAULT_TIMEOUT, DOMAIN, LOGGER +from .const import CONF_COMMAND_TIMEOUT, LOGGER from .utils import check_output_or_log CONF_JSON_ATTRIBUTES = "json_attributes" @@ -62,20 +51,6 @@ TRIGGER_ENTITY_OPTIONS = ( SCAN_INTERVAL = timedelta(seconds=60) -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_COMMAND): cv.string, - vol.Optional(CONF_COMMAND_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int, - vol.Optional(CONF_JSON_ATTRIBUTES): cv.ensure_list_csv, - vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, - vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string, - vol.Optional(CONF_VALUE_TEMPLATE): cv.template, - vol.Optional(CONF_UNIQUE_ID): cv.string, - vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA, - vol.Optional(CONF_STATE_CLASS): STATE_CLASSES_SCHEMA, - } -) - async def async_setup_platform( hass: HomeAssistant, @@ -84,19 +59,9 @@ async def async_setup_platform( discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the Command Sensor.""" - if sensor_config := config: - async_create_issue( - hass, - DOMAIN, - "deprecated_yaml_sensor", - breaks_in_ha_version="2023.12.0", - is_fixable=False, - severity=IssueSeverity.WARNING, - translation_key="deprecated_platform_yaml", - translation_placeholders={"platform": SENSOR_DOMAIN}, - ) - if discovery_info: - sensor_config = discovery_info + + discovery_info = cast(DiscoveryInfoType, discovery_info) + sensor_config = discovery_info name: str = sensor_config[CONF_NAME] command: str = sensor_config[CONF_COMMAND] diff --git a/homeassistant/components/command_line/strings.json b/homeassistant/components/command_line/strings.json index 9fc0de2ab28..377ed7927aa 100644 --- a/homeassistant/components/command_line/strings.json +++ b/homeassistant/components/command_line/strings.json @@ -1,10 +1,4 @@ { - "issues": { - "deprecated_platform_yaml": { - "title": "Command Line YAML configuration has moved", - "description": "Configuring Command Line `{platform}` using YAML has moved.\n\nConsult the documentation to move your YAML configuration to integration key and restart Home Assistant to fix this issue." - } - }, "services": { "reload": { "name": "[%key:common::action::reload%]", diff --git a/homeassistant/components/command_line/switch.py b/homeassistant/components/command_line/switch.py index 004a65643bb..8d30de310ef 100644 --- a/homeassistant/components/command_line/switch.py +++ b/homeassistant/components/command_line/switch.py @@ -3,61 +3,32 @@ from __future__ import annotations import asyncio from datetime import timedelta -from typing import TYPE_CHECKING, Any +from typing import TYPE_CHECKING, Any, cast -import voluptuous as vol - -from homeassistant.components.switch import ( - DOMAIN as SWITCH_DOMAIN, - ENTITY_ID_FORMAT, - PLATFORM_SCHEMA, - SwitchEntity, -) +from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchEntity from homeassistant.const import ( CONF_COMMAND_OFF, CONF_COMMAND_ON, CONF_COMMAND_STATE, - CONF_FRIENDLY_NAME, CONF_ICON, - CONF_ICON_TEMPLATE, CONF_NAME, CONF_SCAN_INTERVAL, - CONF_SWITCHES, CONF_UNIQUE_ID, CONF_VALUE_TEMPLATE, ) from homeassistant.core import HomeAssistant -import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.event import async_track_time_interval -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.template import Template from homeassistant.helpers.trigger_template_entity import ManualTriggerEntity from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.util import dt as dt_util, slugify -from .const import CONF_COMMAND_TIMEOUT, DEFAULT_TIMEOUT, DOMAIN, LOGGER +from .const import CONF_COMMAND_TIMEOUT, LOGGER from .utils import call_shell_with_timeout, check_output_or_log SCAN_INTERVAL = timedelta(seconds=30) -SWITCH_SCHEMA = vol.Schema( - { - vol.Optional(CONF_COMMAND_OFF, default="true"): cv.string, - vol.Optional(CONF_COMMAND_ON, default="true"): cv.string, - vol.Optional(CONF_COMMAND_STATE): cv.string, - vol.Optional(CONF_FRIENDLY_NAME): cv.string, - vol.Optional(CONF_VALUE_TEMPLATE): cv.template, - vol.Optional(CONF_ICON_TEMPLATE): cv.template, - vol.Optional(CONF_COMMAND_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int, - vol.Optional(CONF_UNIQUE_ID): cv.string, - } -) - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - {vol.Required(CONF_SWITCHES): cv.schema_with_slug_keys(SWITCH_SCHEMA)} -) - async def async_setup_platform( hass: HomeAssistant, @@ -67,34 +38,12 @@ async def async_setup_platform( ) -> None: """Find and return switches controlled by shell commands.""" - if discovery_info: - entities: dict[str, Any] = {slugify(discovery_info[CONF_NAME]): discovery_info} - else: - async_create_issue( - hass, - DOMAIN, - "deprecated_yaml_switch", - breaks_in_ha_version="2023.12.0", - is_fixable=False, - severity=IssueSeverity.WARNING, - translation_key="deprecated_platform_yaml", - translation_placeholders={"platform": SWITCH_DOMAIN}, - ) - entities = config.get(CONF_SWITCHES, {}) + discovery_info = cast(DiscoveryInfoType, discovery_info) + entities: dict[str, Any] = {slugify(discovery_info[CONF_NAME]): discovery_info} switches = [] for object_id, device_config in entities.items(): - if name := device_config.get( - CONF_FRIENDLY_NAME - ): # Backward compatibility. Can be removed after deprecation - device_config[CONF_NAME] = name - - if icon := device_config.get( - CONF_ICON_TEMPLATE - ): # Backward compatibility. Can be removed after deprecation - device_config[CONF_ICON] = icon - trigger_entity_config = { CONF_UNIQUE_ID: device_config.get(CONF_UNIQUE_ID), CONF_NAME: Template(device_config.get(CONF_NAME, object_id), hass), @@ -119,10 +68,6 @@ async def async_setup_platform( ) ) - if not switches: - LOGGER.error("No switches added") - return - async_add_entities(switches) diff --git a/tests/components/command_line/test_binary_sensor.py b/tests/components/command_line/test_binary_sensor.py index 360c78dd5a7..eaa7061551a 100644 --- a/tests/components/command_line/test_binary_sensor.py +++ b/tests/components/command_line/test_binary_sensor.py @@ -9,7 +9,6 @@ from unittest.mock import patch import pytest from homeassistant import setup -from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN from homeassistant.components.command_line.binary_sensor import CommandBinarySensor from homeassistant.components.command_line.const import DOMAIN from homeassistant.components.homeassistant import ( @@ -19,39 +18,11 @@ from homeassistant.components.homeassistant import ( from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er -import homeassistant.helpers.issue_registry as ir from homeassistant.util import dt as dt_util from tests.common import async_fire_time_changed -async def test_setup_platform_yaml(hass: HomeAssistant) -> None: - """Test sensor setup.""" - assert await setup.async_setup_component( - hass, - BINARY_SENSOR_DOMAIN, - { - BINARY_SENSOR_DOMAIN: { - "platform": "command_line", - "name": "Test", - "command": "echo 1", - "payload_on": "1", - "payload_off": "0", - } - }, - ) - await hass.async_block_till_done() - - entity_state = hass.states.get("binary_sensor.test") - assert entity_state - assert entity_state.state == STATE_ON - assert entity_state.name == "Test" - - issue_registry = ir.async_get(hass) - issue = issue_registry.async_get_issue(DOMAIN, "deprecated_yaml_binary_sensor") - assert issue.translation_key == "deprecated_platform_yaml" - - @pytest.mark.parametrize( "get_config", [ diff --git a/tests/components/command_line/test_cover.py b/tests/components/command_line/test_cover.py index 64fa2a60719..e6e428388f4 100644 --- a/tests/components/command_line/test_cover.py +++ b/tests/components/command_line/test_cover.py @@ -25,80 +25,11 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er -import homeassistant.helpers.issue_registry as ir import homeassistant.util.dt as dt_util from tests.common import async_fire_time_changed -async def test_no_covers_platform_yaml( - caplog: pytest.LogCaptureFixture, hass: HomeAssistant -) -> None: - """Test that the cover does not polls when there's no state command.""" - - with patch( - "homeassistant.components.command_line.utils.subprocess.check_output", - return_value=b"50\n", - ): - assert await setup.async_setup_component( - hass, - COVER_DOMAIN, - { - COVER_DOMAIN: [ - {"platform": "command_line", "covers": {}}, - ] - }, - ) - await hass.async_block_till_done() - assert "No covers added" in caplog.text - - issue_registry = ir.async_get(hass) - issue = issue_registry.async_get_issue(DOMAIN, "deprecated_yaml_cover") - assert issue.translation_key == "deprecated_platform_yaml" - - -async def test_state_value_platform_yaml(hass: HomeAssistant) -> None: - """Test with state value.""" - with tempfile.TemporaryDirectory() as tempdirname: - path = os.path.join(tempdirname, "cover_status") - assert await setup.async_setup_component( - hass, - COVER_DOMAIN, - { - COVER_DOMAIN: [ - { - "platform": "command_line", - "covers": { - "test": { - "command_state": f"cat {path}", - "command_open": f"echo 1 > {path}", - "command_close": f"echo 1 > {path}", - "command_stop": f"echo 0 > {path}", - "value_template": "{{ value }}", - "friendly_name": "Test", - }, - }, - }, - ] - }, - ) - await hass.async_block_till_done() - - entity_state = hass.states.get("cover.test") - assert entity_state - assert entity_state.state == "unknown" - - await hass.services.async_call( - COVER_DOMAIN, - SERVICE_OPEN_COVER, - {ATTR_ENTITY_ID: "cover.test"}, - blocking=True, - ) - entity_state = hass.states.get("cover.test") - assert entity_state - assert entity_state.state == "open" - - async def test_no_poll_when_cover_has_no_command_state(hass: HomeAssistant) -> None: """Test that the cover does not polls when there's no state command.""" diff --git a/tests/components/command_line/test_notify.py b/tests/components/command_line/test_notify.py index a17b1ec33e1..96ad5ce2ee8 100644 --- a/tests/components/command_line/test_notify.py +++ b/tests/components/command_line/test_notify.py @@ -12,26 +12,6 @@ from homeassistant import setup from homeassistant.components.command_line import DOMAIN from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN from homeassistant.core import HomeAssistant -import homeassistant.helpers.issue_registry as ir - - -async def test_setup_platform_yaml(hass: HomeAssistant) -> None: - """Test sensor setup.""" - assert await setup.async_setup_component( - hass, - NOTIFY_DOMAIN, - { - NOTIFY_DOMAIN: [ - {"platform": "command_line", "name": "Test1", "command": "exit 0"}, - ] - }, - ) - await hass.async_block_till_done() - assert hass.services.has_service(NOTIFY_DOMAIN, "test1") - - issue_registry = ir.async_get(hass) - issue = issue_registry.async_get_issue(DOMAIN, "deprecated_yaml_notify") - assert issue.translation_key == "deprecated_platform_yaml" @pytest.mark.parametrize( diff --git a/tests/components/command_line/test_sensor.py b/tests/components/command_line/test_sensor.py index 388d0345cad..9f28b8cc6d0 100644 --- a/tests/components/command_line/test_sensor.py +++ b/tests/components/command_line/test_sensor.py @@ -16,44 +16,14 @@ from homeassistant.components.homeassistant import ( DOMAIN as HA_DOMAIN, SERVICE_UPDATE_ENTITY, ) -from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er -import homeassistant.helpers.issue_registry as ir from homeassistant.util import dt as dt_util from tests.common import async_fire_time_changed -async def test_setup_platform_yaml(hass: HomeAssistant) -> None: - """Test sensor setup.""" - assert await setup.async_setup_component( - hass, - SENSOR_DOMAIN, - { - SENSOR_DOMAIN: [ - { - "platform": "command_line", - "name": "Test", - "command": "echo 5", - "unit_of_measurement": "in", - }, - ] - }, - ) - await hass.async_block_till_done() - entity_state = hass.states.get("sensor.test") - assert entity_state - assert entity_state.state == "5" - assert entity_state.name == "Test" - assert entity_state.attributes["unit_of_measurement"] == "in" - - issue_registry = ir.async_get(hass) - issue = issue_registry.async_get_issue(DOMAIN, "deprecated_yaml_sensor") - assert issue.translation_key == "deprecated_platform_yaml" - - @pytest.mark.parametrize( "get_config", [ diff --git a/tests/components/command_line/test_switch.py b/tests/components/command_line/test_switch.py index 09e8c47d708..f1f4096fa91 100644 --- a/tests/components/command_line/test_switch.py +++ b/tests/components/command_line/test_switch.py @@ -28,34 +28,27 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er -import homeassistant.helpers.issue_registry as ir import homeassistant.util.dt as dt_util from tests.common import async_fire_time_changed -async def test_state_platform_yaml(hass: HomeAssistant) -> None: +async def test_state_integration_yaml(hass: HomeAssistant) -> None: """Test with none state.""" with tempfile.TemporaryDirectory() as tempdirname: path = os.path.join(tempdirname, "switch_status") - assert await setup.async_setup_component( + await setup.async_setup_component( hass, - SWITCH_DOMAIN, + DOMAIN, { - SWITCH_DOMAIN: [ + "command_line": [ { - "platform": "command_line", - "switches": { - "test": { - "command_on": f"echo 1 > {path}", - "command_off": f"echo 0 > {path}", - "friendly_name": "Test", - "icon_template": ( - '{% if value=="1" %} mdi:on {% else %} mdi:off {% endif %}' - ), - } - }, - }, + "switch": { + "command_on": f"echo 1 > {path}", + "command_off": f"echo 0 > {path}", + "name": "Test", + } + } ] }, ) @@ -87,36 +80,6 @@ async def test_state_platform_yaml(hass: HomeAssistant) -> None: assert entity_state assert entity_state.state == STATE_OFF - issue_registry = ir.async_get(hass) - issue = issue_registry.async_get_issue(DOMAIN, "deprecated_yaml_switch") - assert issue.translation_key == "deprecated_platform_yaml" - - -async def test_state_integration_yaml(hass: HomeAssistant) -> None: - """Test with none state.""" - with tempfile.TemporaryDirectory() as tempdirname: - path = os.path.join(tempdirname, "switch_status") - await setup.async_setup_component( - hass, - DOMAIN, - { - "command_line": [ - { - "switch": { - "command_on": f"echo 1 > {path}", - "command_off": f"echo 0 > {path}", - "name": "Test", - } - } - ] - }, - ) - await hass.async_block_till_done() - - entity_state = hass.states.get("switch.test") - assert entity_state - assert entity_state.state == STATE_OFF - async def test_state_value(hass: HomeAssistant) -> None: """Test with state value.""" @@ -487,27 +450,6 @@ async def test_switch_command_state_value_exceptions( assert "Error trying to exec command" in caplog.text -async def test_no_switches_platform_yaml( - caplog: pytest.LogCaptureFixture, hass: HomeAssistant -) -> None: - """Test with no switches.""" - - assert await setup.async_setup_component( - hass, - SWITCH_DOMAIN, - { - SWITCH_DOMAIN: [ - { - "platform": "command_line", - "switches": {}, - }, - ] - }, - ) - await hass.async_block_till_done() - assert "No switches" in caplog.text - - async def test_unique_id( hass: HomeAssistant, entity_registry: er.EntityRegistry ) -> None: