Guard for no discovery info in command_line (#123717)

This commit is contained in:
G Johansson 2024-08-12 21:35:02 +02:00 committed by GitHub
parent d1dff95ac8
commit 178cb0659a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 100 additions and 2 deletions

View File

@ -40,6 +40,8 @@ async def async_setup_platform(
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Set up the Command line Binary Sensor.""" """Set up the Command line Binary Sensor."""
if not discovery_info:
return
discovery_info = cast(DiscoveryInfoType, discovery_info) discovery_info = cast(DiscoveryInfoType, discovery_info)
binary_sensor_config = discovery_info binary_sensor_config = discovery_info

View File

@ -37,6 +37,8 @@ async def async_setup_platform(
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Set up cover controlled by shell commands.""" """Set up cover controlled by shell commands."""
if not discovery_info:
return
covers = [] covers = []
discovery_info = cast(DiscoveryInfoType, discovery_info) discovery_info = cast(DiscoveryInfoType, discovery_info)

View File

@ -21,8 +21,10 @@ def get_service(
hass: HomeAssistant, hass: HomeAssistant,
config: ConfigType, config: ConfigType,
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> CommandLineNotificationService: ) -> CommandLineNotificationService | None:
"""Get the Command Line notification service.""" """Get the Command Line notification service."""
if not discovery_info:
return None
discovery_info = cast(DiscoveryInfoType, discovery_info) discovery_info = cast(DiscoveryInfoType, discovery_info)
notify_config = discovery_info notify_config = discovery_info

View File

@ -48,6 +48,8 @@ async def async_setup_platform(
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Set up the Command Sensor.""" """Set up the Command Sensor."""
if not discovery_info:
return
discovery_info = cast(DiscoveryInfoType, discovery_info) discovery_info = cast(DiscoveryInfoType, discovery_info)
sensor_config = discovery_info sensor_config = discovery_info

View File

@ -36,9 +36,9 @@ async def async_setup_platform(
discovery_info: DiscoveryInfoType | None = None, discovery_info: DiscoveryInfoType | None = None,
) -> None: ) -> None:
"""Find and return switches controlled by shell commands.""" """Find and return switches controlled by shell commands."""
if not discovery_info: if not discovery_info:
return return
switches = [] switches = []
discovery_info = cast(DiscoveryInfoType, discovery_info) discovery_info = cast(DiscoveryInfoType, discovery_info)
entities: dict[str, dict[str, Any]] = { entities: dict[str, dict[str, Any]] = {

View File

@ -56,6 +56,24 @@ async def test_setup_integration_yaml(
assert entity_state.name == "Test" assert entity_state.name == "Test"
async def test_setup_platform_yaml(hass: HomeAssistant) -> None:
"""Test setting up the platform with platform yaml."""
await setup.async_setup_component(
hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "command_line",
"command": "echo 1",
"payload_on": "1",
"payload_off": "0",
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 0
@pytest.mark.parametrize( @pytest.mark.parametrize(
"get_config", "get_config",
[ [

View File

@ -36,6 +36,24 @@ from . import mock_asyncio_subprocess_run
from tests.common import async_fire_time_changed from tests.common import async_fire_time_changed
async def test_setup_platform_yaml(hass: HomeAssistant) -> None:
"""Test setting up the platform with platform yaml."""
await setup.async_setup_component(
hass,
"cover",
{
"cover": {
"platform": "command_line",
"command": "echo 1",
"payload_on": "1",
"payload_off": "0",
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 0
async def test_no_poll_when_cover_has_no_command_state(hass: HomeAssistant) -> None: 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.""" """Test that the cover does not polls when there's no state command."""

View File

@ -16,6 +16,24 @@ from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
async def test_setup_platform_yaml(hass: HomeAssistant) -> None:
"""Test setting up the platform with platform yaml."""
await setup.async_setup_component(
hass,
"notify",
{
"notify": {
"platform": "command_line",
"command": "echo 1",
"payload_on": "1",
"payload_off": "0",
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 0
@pytest.mark.parametrize( @pytest.mark.parametrize(
"get_config", "get_config",
[ [

View File

@ -27,6 +27,24 @@ from . import mock_asyncio_subprocess_run
from tests.common import async_fire_time_changed from tests.common import async_fire_time_changed
async def test_setup_platform_yaml(hass: HomeAssistant) -> None:
"""Test setting up the platform with platform yaml."""
await setup.async_setup_component(
hass,
"sensor",
{
"sensor": {
"platform": "command_line",
"command": "echo 1",
"payload_on": "1",
"payload_off": "0",
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 0
@pytest.mark.parametrize( @pytest.mark.parametrize(
"get_config", "get_config",
[ [

View File

@ -37,6 +37,24 @@ from . import mock_asyncio_subprocess_run
from tests.common import async_fire_time_changed from tests.common import async_fire_time_changed
async def test_setup_platform_yaml(hass: HomeAssistant) -> None:
"""Test setting up the platform with platform yaml."""
await setup.async_setup_component(
hass,
"switch",
{
"switch": {
"platform": "command_line",
"command": "echo 1",
"payload_on": "1",
"payload_off": "0",
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 0
async def test_state_integration_yaml(hass: HomeAssistant) -> None: async def test_state_integration_yaml(hass: HomeAssistant) -> None:
"""Test with none state.""" """Test with none state."""
with tempfile.TemporaryDirectory() as tempdirname: with tempfile.TemporaryDirectory() as tempdirname: