mirror of
https://github.com/home-assistant/core
synced 2024-10-04 07:58:43 +02:00
Add icon to command_line cover config (#114645)
* Add icon to command_line cover config * Remove unwanted #noqa tag * Remove redundancy from new test name * Apply requested changes
This commit is contained in:
parent
6638d1c8e8
commit
ef7836be73
@ -102,6 +102,7 @@ COVER_SCHEMA = vol.Schema(
|
||||
vol.Optional(CONF_COMMAND_STATE): cv.string,
|
||||
vol.Optional(CONF_COMMAND_STOP, default="true"): cv.string,
|
||||
vol.Required(CONF_NAME): cv.string,
|
||||
vol.Optional(CONF_ICON): cv.template,
|
||||
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,
|
||||
|
@ -12,6 +12,7 @@ from homeassistant.const import (
|
||||
CONF_COMMAND_OPEN,
|
||||
CONF_COMMAND_STATE,
|
||||
CONF_COMMAND_STOP,
|
||||
CONF_ICON,
|
||||
CONF_NAME,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_UNIQUE_ID,
|
||||
@ -54,6 +55,7 @@ async def async_setup_platform(
|
||||
trigger_entity_config = {
|
||||
CONF_UNIQUE_ID: device_config.get(CONF_UNIQUE_ID),
|
||||
CONF_NAME: Template(device_config.get(CONF_NAME, device_name), hass),
|
||||
CONF_ICON: device_config.get(CONF_ICON),
|
||||
CONF_AVAILABILITY: device_config.get(CONF_AVAILABILITY),
|
||||
}
|
||||
|
||||
|
@ -383,3 +383,48 @@ async def test_availability(
|
||||
entity_state = hass.states.get("cover.test")
|
||||
assert entity_state
|
||||
assert entity_state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_icon_template(hass: HomeAssistant) -> None:
|
||||
"""Test with state value."""
|
||||
with tempfile.TemporaryDirectory() as tempdirname:
|
||||
path = os.path.join(tempdirname, "cover_status_icon")
|
||||
await setup.async_setup_component(
|
||||
hass,
|
||||
DOMAIN,
|
||||
{
|
||||
"command_line": [
|
||||
{
|
||||
"cover": {
|
||||
"command_state": f"cat {path}",
|
||||
"command_open": f"echo 100 > {path}",
|
||||
"command_close": f"echo 0 > {path}",
|
||||
"command_stop": f"echo 0 > {path}",
|
||||
"name": "Test",
|
||||
"icon": "{% if this.state=='open' %} mdi:open {% else %} mdi:closed {% endif %}",
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
SERVICE_CLOSE_COVER,
|
||||
{ATTR_ENTITY_ID: "cover.test"},
|
||||
blocking=True,
|
||||
)
|
||||
entity_state = hass.states.get("cover.test")
|
||||
assert entity_state
|
||||
assert entity_state.attributes.get("icon") == "mdi:closed"
|
||||
|
||||
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.attributes.get("icon") == "mdi:open"
|
||||
|
Loading…
Reference in New Issue
Block a user