Simplify command_line sensor tests (#89576)
This commit is contained in:
parent
edb06c58fa
commit
234610b1cc
1 changed files with 10 additions and 17 deletions
|
@ -7,26 +7,19 @@ from unittest.mock import patch
|
|||
import pytest
|
||||
|
||||
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.helpers import entity_registry as er
|
||||
|
||||
|
||||
async def setup_test_entities(hass: HomeAssistant, config_dict: dict[str, Any]) -> None:
|
||||
"""Set up a test command line sensor entity."""
|
||||
hass.states.async_set("sensor.input_sensor", "sensor_value")
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SENSOR_DOMAIN,
|
||||
{
|
||||
DOMAIN: [
|
||||
{
|
||||
"platform": "template",
|
||||
"sensors": {
|
||||
"template_sensor": {
|
||||
"value_template": "template_value",
|
||||
}
|
||||
},
|
||||
},
|
||||
SENSOR_DOMAIN: [
|
||||
{"platform": "command_line", "name": "Test", **config_dict},
|
||||
]
|
||||
},
|
||||
|
@ -71,12 +64,12 @@ async def test_template_render(hass: HomeAssistant) -> None:
|
|||
await setup_test_entities(
|
||||
hass,
|
||||
{
|
||||
"command": "echo {{ states.sensor.template_sensor.state }}",
|
||||
"command": "echo {{ states.sensor.input_sensor.state }}",
|
||||
},
|
||||
)
|
||||
entity_state = hass.states.get("sensor.test")
|
||||
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:
|
||||
|
@ -89,12 +82,12 @@ async def test_template_render_with_quote(hass: HomeAssistant) -> None:
|
|||
await setup_test_entities(
|
||||
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(
|
||||
'echo "template_value" "3 4"',
|
||||
'echo "sensor_value" "3 4"',
|
||||
shell=True, # nosec # shell by design
|
||||
timeout=15,
|
||||
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."""
|
||||
assert await setup.async_setup_component(
|
||||
hass,
|
||||
DOMAIN,
|
||||
SENSOR_DOMAIN,
|
||||
{
|
||||
DOMAIN: [
|
||||
SENSOR_DOMAIN: [
|
||||
{
|
||||
"platform": "command_line",
|
||||
"unique_id": "unique",
|
||||
|
|
Loading…
Add table
Reference in a new issue