mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Guard for no discovery info in command_line (#123717)
This commit is contained in:
parent
d1dff95ac8
commit
178cb0659a
@ -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
|
||||||
|
@ -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)
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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]] = {
|
||||||
|
@ -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",
|
||||||
[
|
[
|
||||||
|
@ -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."""
|
||||||
|
|
||||||
|
@ -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",
|
||||||
[
|
[
|
||||||
|
@ -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",
|
||||||
[
|
[
|
||||||
|
@ -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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user