mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Simplify command_line sensor tests (#89576)
This commit is contained in:
parent
edb06c58fa
commit
234610b1cc
@ -7,26 +7,19 @@ from unittest.mock import patch
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import setup
|
from homeassistant import setup
|
||||||
from homeassistant.components.sensor import DOMAIN
|
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
|
|
||||||
async def setup_test_entities(hass: HomeAssistant, config_dict: dict[str, Any]) -> None:
|
async def setup_test_entities(hass: HomeAssistant, config_dict: dict[str, Any]) -> None:
|
||||||
"""Set up a test command line sensor entity."""
|
"""Set up a test command line sensor entity."""
|
||||||
|
hass.states.async_set("sensor.input_sensor", "sensor_value")
|
||||||
assert await setup.async_setup_component(
|
assert await setup.async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
DOMAIN,
|
SENSOR_DOMAIN,
|
||||||
{
|
{
|
||||||
DOMAIN: [
|
SENSOR_DOMAIN: [
|
||||||
{
|
|
||||||
"platform": "template",
|
|
||||||
"sensors": {
|
|
||||||
"template_sensor": {
|
|
||||||
"value_template": "template_value",
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{"platform": "command_line", "name": "Test", **config_dict},
|
{"platform": "command_line", "name": "Test", **config_dict},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -71,12 +64,12 @@ async def test_template_render(hass: HomeAssistant) -> None:
|
|||||||
await setup_test_entities(
|
await setup_test_entities(
|
||||||
hass,
|
hass,
|
||||||
{
|
{
|
||||||
"command": "echo {{ states.sensor.template_sensor.state }}",
|
"command": "echo {{ states.sensor.input_sensor.state }}",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
entity_state = hass.states.get("sensor.test")
|
entity_state = hass.states.get("sensor.test")
|
||||||
assert entity_state
|
assert entity_state
|
||||||
assert entity_state.state == "template_value"
|
assert entity_state.state == "sensor_value"
|
||||||
|
|
||||||
|
|
||||||
async def test_template_render_with_quote(hass: HomeAssistant) -> None:
|
async def test_template_render_with_quote(hass: HomeAssistant) -> None:
|
||||||
@ -89,12 +82,12 @@ async def test_template_render_with_quote(hass: HomeAssistant) -> None:
|
|||||||
await setup_test_entities(
|
await setup_test_entities(
|
||||||
hass,
|
hass,
|
||||||
{
|
{
|
||||||
"command": 'echo "{{ states.sensor.template_sensor.state }}" "3 4"',
|
"command": 'echo "{{ states.sensor.input_sensor.state }}" "3 4"',
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
check_output.assert_called_once_with(
|
check_output.assert_called_once_with(
|
||||||
'echo "template_value" "3 4"',
|
'echo "sensor_value" "3 4"',
|
||||||
shell=True, # nosec # shell by design
|
shell=True, # nosec # shell by design
|
||||||
timeout=15,
|
timeout=15,
|
||||||
close_fds=False,
|
close_fds=False,
|
||||||
@ -266,9 +259,9 @@ async def test_unique_id(
|
|||||||
"""Test unique_id option and if it only creates one sensor per id."""
|
"""Test unique_id option and if it only creates one sensor per id."""
|
||||||
assert await setup.async_setup_component(
|
assert await setup.async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
DOMAIN,
|
SENSOR_DOMAIN,
|
||||||
{
|
{
|
||||||
DOMAIN: [
|
SENSOR_DOMAIN: [
|
||||||
{
|
{
|
||||||
"platform": "command_line",
|
"platform": "command_line",
|
||||||
"unique_id": "unique",
|
"unique_id": "unique",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user