2016-03-09 09:25:50 +00:00
|
|
|
"""The test for the Template sensor platform."""
|
2018-10-11 09:38:35 +00:00
|
|
|
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
2018-10-10 11:49:15 +00:00
|
|
|
from homeassistant.setup import setup_component, async_setup_component
|
2016-01-21 18:31:44 +00:00
|
|
|
|
2017-10-19 08:56:25 +00:00
|
|
|
from tests.common import get_test_home_assistant, assert_setup_component
|
2016-02-14 23:08:23 +00:00
|
|
|
|
2016-01-21 18:31:44 +00:00
|
|
|
|
2016-01-22 09:37:20 +00:00
|
|
|
class TestTemplateSensor:
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test the Template sensor."""
|
2016-01-21 18:31:44 +00:00
|
|
|
|
2016-10-08 18:27:35 +00:00
|
|
|
hass = None
|
|
|
|
# pylint: disable=invalid-name
|
|
|
|
|
2016-01-21 18:31:44 +00:00
|
|
|
def setup_method(self, method):
|
2018-08-19 20:29:08 +00:00
|
|
|
"""Set up things to be run when tests are started."""
|
2016-02-14 23:08:23 +00:00
|
|
|
self.hass = get_test_home_assistant()
|
2016-01-21 18:31:44 +00:00
|
|
|
|
|
|
|
def teardown_method(self, method):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Stop everything that was started."""
|
2016-01-21 18:31:44 +00:00
|
|
|
self.hass.stop()
|
|
|
|
|
2016-01-22 09:37:20 +00:00
|
|
|
def test_template(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test template."""
|
2016-10-08 18:27:35 +00:00
|
|
|
with assert_setup_component(1):
|
2019-07-31 19:25:30 +00:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"sensor",
|
|
|
|
{
|
|
|
|
"sensor": {
|
|
|
|
"platform": "template",
|
|
|
|
"sensors": {
|
|
|
|
"test_template_sensor": {
|
|
|
|
"value_template": "It {{ states.sensor.test_state.state }}."
|
|
|
|
}
|
|
|
|
},
|
2016-01-21 18:31:44 +00:00
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
},
|
|
|
|
)
|
2016-01-21 18:31:44 +00:00
|
|
|
|
2017-03-02 05:38:19 +00:00
|
|
|
self.hass.start()
|
2017-03-02 13:09:53 +00:00
|
|
|
self.hass.block_till_done()
|
2017-03-02 05:38:19 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
state = self.hass.states.get("sensor.test_template_sensor")
|
|
|
|
assert state.state == "It ."
|
2016-01-21 18:31:44 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass.states.set("sensor.test_state", "Works")
|
2016-09-13 02:16:14 +00:00
|
|
|
self.hass.block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
state = self.hass.states.get("sensor.test_template_sensor")
|
|
|
|
assert state.state == "It Works."
|
2016-01-22 09:37:20 +00:00
|
|
|
|
2017-02-07 09:51:44 +00:00
|
|
|
def test_icon_template(self):
|
|
|
|
"""Test icon template."""
|
|
|
|
with assert_setup_component(1):
|
2019-07-31 19:25:30 +00:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"sensor",
|
|
|
|
{
|
|
|
|
"sensor": {
|
|
|
|
"platform": "template",
|
|
|
|
"sensors": {
|
|
|
|
"test_template_sensor": {
|
|
|
|
"value_template": "{{ states.sensor.test_state.state }}",
|
|
|
|
"icon_template": "{% if states.sensor.test_state.state == "
|
2017-02-07 09:51:44 +00:00
|
|
|
"'Works' %}"
|
|
|
|
"mdi:check"
|
2019-07-31 19:25:30 +00:00
|
|
|
"{% endif %}",
|
|
|
|
}
|
|
|
|
},
|
2017-02-07 09:51:44 +00:00
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
},
|
|
|
|
)
|
2017-02-07 09:51:44 +00:00
|
|
|
|
2017-03-02 05:38:19 +00:00
|
|
|
self.hass.start()
|
2017-03-02 13:09:53 +00:00
|
|
|
self.hass.block_till_done()
|
2017-03-02 05:38:19 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
state = self.hass.states.get("sensor.test_template_sensor")
|
|
|
|
assert state.attributes.get("icon") == ""
|
2017-02-07 09:51:44 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass.states.set("sensor.test_state", "Works")
|
2017-02-07 09:51:44 +00:00
|
|
|
self.hass.block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
state = self.hass.states.get("sensor.test_template_sensor")
|
|
|
|
assert state.attributes["icon"] == "mdi:check"
|
2017-02-07 09:51:44 +00:00
|
|
|
|
2017-10-30 16:28:37 +00:00
|
|
|
def test_entity_picture_template(self):
|
|
|
|
"""Test entity_picture template."""
|
|
|
|
with assert_setup_component(1):
|
2019-07-31 19:25:30 +00:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"sensor",
|
|
|
|
{
|
|
|
|
"sensor": {
|
|
|
|
"platform": "template",
|
|
|
|
"sensors": {
|
|
|
|
"test_template_sensor": {
|
|
|
|
"value_template": "{{ states.sensor.test_state.state }}",
|
|
|
|
"entity_picture_template": "{% if states.sensor.test_state.state == "
|
2017-10-30 16:28:37 +00:00
|
|
|
"'Works' %}"
|
|
|
|
"/local/sensor.png"
|
2019-07-31 19:25:30 +00:00
|
|
|
"{% endif %}",
|
|
|
|
}
|
|
|
|
},
|
2017-10-30 16:28:37 +00:00
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
},
|
|
|
|
)
|
2017-10-30 16:28:37 +00:00
|
|
|
|
|
|
|
self.hass.start()
|
|
|
|
self.hass.block_till_done()
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
state = self.hass.states.get("sensor.test_template_sensor")
|
|
|
|
assert state.attributes.get("entity_picture") == ""
|
2017-10-30 16:28:37 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass.states.set("sensor.test_state", "Works")
|
2017-10-30 16:28:37 +00:00
|
|
|
self.hass.block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
state = self.hass.states.get("sensor.test_template_sensor")
|
|
|
|
assert state.attributes["entity_picture"] == "/local/sensor.png"
|
2017-10-30 16:28:37 +00:00
|
|
|
|
2018-02-11 20:12:30 +00:00
|
|
|
def test_friendly_name_template(self):
|
|
|
|
"""Test friendly_name template."""
|
|
|
|
with assert_setup_component(1):
|
2019-07-31 19:25:30 +00:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"sensor",
|
|
|
|
{
|
|
|
|
"sensor": {
|
|
|
|
"platform": "template",
|
|
|
|
"sensors": {
|
|
|
|
"test_template_sensor": {
|
|
|
|
"value_template": "{{ states.sensor.test_state.state }}",
|
|
|
|
"friendly_name_template": "It {{ states.sensor.test_state.state }}.",
|
|
|
|
}
|
|
|
|
},
|
2018-02-11 20:12:30 +00:00
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
},
|
|
|
|
)
|
2018-02-11 20:12:30 +00:00
|
|
|
|
|
|
|
self.hass.start()
|
|
|
|
self.hass.block_till_done()
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
state = self.hass.states.get("sensor.test_template_sensor")
|
|
|
|
assert state.attributes.get("friendly_name") == "It ."
|
2018-02-11 20:12:30 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass.states.set("sensor.test_state", "Works")
|
2018-02-11 20:12:30 +00:00
|
|
|
self.hass.block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
state = self.hass.states.get("sensor.test_template_sensor")
|
|
|
|
assert state.attributes["friendly_name"] == "It Works."
|
2018-02-11 20:12:30 +00:00
|
|
|
|
2018-03-11 04:45:32 +00:00
|
|
|
def test_friendly_name_template_with_unknown_state(self):
|
|
|
|
"""Test friendly_name template with an unknown value_template."""
|
|
|
|
with assert_setup_component(1):
|
2019-07-31 19:25:30 +00:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"sensor",
|
|
|
|
{
|
|
|
|
"sensor": {
|
|
|
|
"platform": "template",
|
|
|
|
"sensors": {
|
|
|
|
"test_template_sensor": {
|
|
|
|
"value_template": "{{ states.fourohfour.state }}",
|
|
|
|
"friendly_name_template": "It {{ states.sensor.test_state.state }}.",
|
|
|
|
}
|
|
|
|
},
|
2018-03-11 04:45:32 +00:00
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
},
|
|
|
|
)
|
2018-03-11 04:45:32 +00:00
|
|
|
|
|
|
|
self.hass.start()
|
|
|
|
self.hass.block_till_done()
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
state = self.hass.states.get("sensor.test_template_sensor")
|
|
|
|
assert state.attributes["friendly_name"] == "It ."
|
2018-03-11 04:45:32 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass.states.set("sensor.test_state", "Works")
|
2018-03-11 04:45:32 +00:00
|
|
|
self.hass.block_till_done()
|
2019-07-31 19:25:30 +00:00
|
|
|
state = self.hass.states.get("sensor.test_template_sensor")
|
|
|
|
assert state.attributes["friendly_name"] == "It Works."
|
2018-03-11 04:45:32 +00:00
|
|
|
|
2016-01-22 09:37:20 +00:00
|
|
|
def test_template_syntax_error(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test templating syntax error."""
|
2016-10-08 18:27:35 +00:00
|
|
|
with assert_setup_component(0):
|
2019-07-31 19:25:30 +00:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"sensor",
|
|
|
|
{
|
|
|
|
"sensor": {
|
|
|
|
"platform": "template",
|
|
|
|
"sensors": {
|
|
|
|
"test_template_sensor": {
|
|
|
|
"value_template": "{% if rubbish %}"
|
|
|
|
}
|
|
|
|
},
|
2016-01-22 09:37:20 +00:00
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
},
|
|
|
|
)
|
2017-03-02 05:38:19 +00:00
|
|
|
|
|
|
|
self.hass.start()
|
2017-03-02 13:09:53 +00:00
|
|
|
self.hass.block_till_done()
|
2016-08-22 08:11:16 +00:00
|
|
|
assert self.hass.states.all() == []
|
2016-02-01 18:18:51 +00:00
|
|
|
|
2016-02-02 14:15:06 +00:00
|
|
|
def test_template_attribute_missing(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test missing attribute template."""
|
2016-10-08 18:27:35 +00:00
|
|
|
with assert_setup_component(1):
|
2019-07-31 19:25:30 +00:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"sensor",
|
|
|
|
{
|
|
|
|
"sensor": {
|
|
|
|
"platform": "template",
|
|
|
|
"sensors": {
|
|
|
|
"test_template_sensor": {
|
|
|
|
"value_template": "It {{ states.sensor.test_state"
|
|
|
|
".attributes.missing }}."
|
|
|
|
}
|
|
|
|
},
|
2016-02-02 14:15:06 +00:00
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
},
|
|
|
|
)
|
2016-02-02 14:15:06 +00:00
|
|
|
|
2017-03-02 05:38:19 +00:00
|
|
|
self.hass.start()
|
2017-03-02 13:09:53 +00:00
|
|
|
self.hass.block_till_done()
|
2017-03-02 05:38:19 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
state = self.hass.states.get("sensor.test_template_sensor")
|
|
|
|
assert state.state == "unknown"
|
2016-02-02 14:15:06 +00:00
|
|
|
|
2016-02-01 18:18:51 +00:00
|
|
|
def test_invalid_name_does_not_create(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test invalid name."""
|
2016-10-08 18:27:35 +00:00
|
|
|
with assert_setup_component(0):
|
2019-07-31 19:25:30 +00:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"sensor",
|
|
|
|
{
|
|
|
|
"sensor": {
|
|
|
|
"platform": "template",
|
|
|
|
"sensors": {
|
|
|
|
"test INVALID sensor": {
|
|
|
|
"value_template": "{{ states.sensor.test_state.state }}"
|
|
|
|
}
|
|
|
|
},
|
2016-02-01 18:18:51 +00:00
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
},
|
|
|
|
)
|
2017-03-02 05:38:19 +00:00
|
|
|
|
|
|
|
self.hass.start()
|
2017-03-02 13:09:53 +00:00
|
|
|
self.hass.block_till_done()
|
|
|
|
|
2016-02-01 18:18:51 +00:00
|
|
|
assert self.hass.states.all() == []
|
|
|
|
|
2016-02-01 18:30:39 +00:00
|
|
|
def test_invalid_sensor_does_not_create(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test invalid sensor."""
|
2016-10-08 18:27:35 +00:00
|
|
|
with assert_setup_component(0):
|
2019-07-31 19:25:30 +00:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"sensor",
|
|
|
|
{
|
|
|
|
"sensor": {
|
|
|
|
"platform": "template",
|
|
|
|
"sensors": {"test_template_sensor": "invalid"},
|
2016-10-08 18:27:35 +00:00
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
},
|
|
|
|
)
|
2017-03-02 05:38:19 +00:00
|
|
|
|
|
|
|
self.hass.start()
|
2017-03-02 13:09:53 +00:00
|
|
|
|
2016-02-01 18:18:51 +00:00
|
|
|
assert self.hass.states.all() == []
|
|
|
|
|
2016-02-01 18:30:39 +00:00
|
|
|
def test_no_sensors_does_not_create(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test no sensors."""
|
2016-10-08 18:27:35 +00:00
|
|
|
with assert_setup_component(0):
|
2019-07-31 19:25:30 +00:00
|
|
|
assert setup_component(
|
|
|
|
self.hass, "sensor", {"sensor": {"platform": "template"}}
|
|
|
|
)
|
2017-03-02 05:38:19 +00:00
|
|
|
|
|
|
|
self.hass.start()
|
2017-03-02 13:09:53 +00:00
|
|
|
self.hass.block_till_done()
|
|
|
|
|
2016-02-01 18:30:39 +00:00
|
|
|
assert self.hass.states.all() == []
|
|
|
|
|
2016-02-01 18:18:51 +00:00
|
|
|
def test_missing_template_does_not_create(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test missing template."""
|
2016-10-08 18:27:35 +00:00
|
|
|
with assert_setup_component(0):
|
2019-07-31 19:25:30 +00:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"sensor",
|
|
|
|
{
|
|
|
|
"sensor": {
|
|
|
|
"platform": "template",
|
|
|
|
"sensors": {
|
|
|
|
"test_template_sensor": {
|
|
|
|
"not_value_template": "{{ states.sensor.test_state.state }}"
|
|
|
|
}
|
|
|
|
},
|
2016-02-01 18:18:51 +00:00
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
},
|
|
|
|
)
|
2017-03-02 05:38:19 +00:00
|
|
|
|
|
|
|
self.hass.start()
|
2017-03-02 13:09:53 +00:00
|
|
|
self.hass.block_till_done()
|
|
|
|
|
2016-02-01 18:18:51 +00:00
|
|
|
assert self.hass.states.all() == []
|
2018-05-01 18:32:44 +00:00
|
|
|
|
|
|
|
def test_setup_invalid_device_class(self):
|
2018-05-13 09:06:15 +00:00
|
|
|
"""Test setup with invalid device_class."""
|
2018-05-01 18:32:44 +00:00
|
|
|
with assert_setup_component(0):
|
2019-07-31 19:25:30 +00:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"sensor",
|
|
|
|
{
|
|
|
|
"sensor": {
|
|
|
|
"platform": "template",
|
|
|
|
"sensors": {
|
|
|
|
"test": {
|
|
|
|
"value_template": "{{ states.sensor.test_sensor.state }}",
|
|
|
|
"device_class": "foobarnotreal",
|
|
|
|
}
|
2018-05-01 18:32:44 +00:00
|
|
|
},
|
2019-07-31 19:25:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2018-05-01 18:32:44 +00:00
|
|
|
|
|
|
|
def test_setup_valid_device_class(self):
|
2018-05-13 09:06:15 +00:00
|
|
|
"""Test setup with valid device_class."""
|
2018-05-01 18:32:44 +00:00
|
|
|
with assert_setup_component(1):
|
2019-07-31 19:25:30 +00:00
|
|
|
assert setup_component(
|
|
|
|
self.hass,
|
|
|
|
"sensor",
|
|
|
|
{
|
|
|
|
"sensor": {
|
|
|
|
"platform": "template",
|
|
|
|
"sensors": {
|
|
|
|
"test1": {
|
|
|
|
"value_template": "{{ states.sensor.test_sensor.state }}",
|
|
|
|
"device_class": "temperature",
|
|
|
|
},
|
|
|
|
"test2": {
|
|
|
|
"value_template": "{{ states.sensor.test_sensor.state }}"
|
|
|
|
},
|
2018-10-10 11:49:15 +00:00
|
|
|
},
|
2018-05-01 18:32:44 +00:00
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
},
|
|
|
|
)
|
2018-05-01 18:32:44 +00:00
|
|
|
self.hass.block_till_done()
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
state = self.hass.states.get("sensor.test1")
|
|
|
|
assert state.attributes["device_class"] == "temperature"
|
|
|
|
state = self.hass.states.get("sensor.test2")
|
|
|
|
assert "device_class" not in state.attributes
|
2018-10-10 11:49:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_no_template_match_all(hass, caplog):
|
|
|
|
"""Test that we do not allow sensors that match on all."""
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.states.async_set("sensor.test_sensor", "startup")
|
|
|
|
|
|
|
|
await async_setup_component(
|
|
|
|
hass,
|
|
|
|
"sensor",
|
|
|
|
{
|
|
|
|
"sensor": {
|
|
|
|
"platform": "template",
|
|
|
|
"sensors": {
|
|
|
|
"invalid_state": {"value_template": "{{ 1 + 1 }}"},
|
|
|
|
"invalid_icon": {
|
|
|
|
"value_template": "{{ states.sensor.test_sensor.state }}",
|
|
|
|
"icon_template": "{{ 1 + 1 }}",
|
|
|
|
},
|
|
|
|
"invalid_entity_picture": {
|
|
|
|
"value_template": "{{ states.sensor.test_sensor.state }}",
|
|
|
|
"entity_picture_template": "{{ 1 + 1 }}",
|
|
|
|
},
|
|
|
|
"invalid_friendly_name": {
|
|
|
|
"value_template": "{{ states.sensor.test_sensor.state }}",
|
|
|
|
"friendly_name_template": "{{ 1 + 1 }}",
|
|
|
|
},
|
2018-10-10 11:49:15 +00:00
|
|
|
},
|
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
},
|
|
|
|
)
|
2018-10-10 11:49:15 +00:00
|
|
|
await hass.async_block_till_done()
|
2018-10-11 09:38:35 +00:00
|
|
|
assert len(hass.states.async_all()) == 5
|
2019-07-31 19:25:30 +00:00
|
|
|
assert (
|
|
|
|
"Template sensor invalid_state has no entity ids "
|
|
|
|
"configured to track nor were we able to extract the entities to "
|
|
|
|
"track from the value template"
|
|
|
|
) in caplog.text
|
|
|
|
assert (
|
|
|
|
"Template sensor invalid_icon has no entity ids "
|
|
|
|
"configured to track nor were we able to extract the entities to "
|
|
|
|
"track from the icon template"
|
|
|
|
) in caplog.text
|
|
|
|
assert (
|
|
|
|
"Template sensor invalid_entity_picture has no entity ids "
|
|
|
|
"configured to track nor were we able to extract the entities to "
|
|
|
|
"track from the entity_picture template"
|
|
|
|
) in caplog.text
|
|
|
|
assert (
|
|
|
|
"Template sensor invalid_friendly_name has no entity ids "
|
|
|
|
"configured to track nor were we able to extract the entities to "
|
|
|
|
"track from the friendly_name template"
|
|
|
|
) in caplog.text
|
|
|
|
|
|
|
|
assert hass.states.get("sensor.invalid_state").state == "unknown"
|
|
|
|
assert hass.states.get("sensor.invalid_icon").state == "unknown"
|
|
|
|
assert hass.states.get("sensor.invalid_entity_picture").state == "unknown"
|
|
|
|
assert hass.states.get("sensor.invalid_friendly_name").state == "unknown"
|
2018-10-10 11:49:15 +00:00
|
|
|
|
2018-10-11 09:38:35 +00:00
|
|
|
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert hass.states.get("sensor.invalid_state").state == "2"
|
|
|
|
assert hass.states.get("sensor.invalid_icon").state == "startup"
|
|
|
|
assert hass.states.get("sensor.invalid_entity_picture").state == "startup"
|
|
|
|
assert hass.states.get("sensor.invalid_friendly_name").state == "startup"
|
2018-10-11 09:38:35 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
hass.states.async_set("sensor.test_sensor", "hello")
|
2018-10-10 11:49:15 +00:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert hass.states.get("sensor.invalid_state").state == "2"
|
|
|
|
assert hass.states.get("sensor.invalid_icon").state == "startup"
|
|
|
|
assert hass.states.get("sensor.invalid_entity_picture").state == "startup"
|
|
|
|
assert hass.states.get("sensor.invalid_friendly_name").state == "startup"
|
2018-10-10 11:49:15 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
await hass.helpers.entity_component.async_update_entity("sensor.invalid_state")
|
|
|
|
await hass.helpers.entity_component.async_update_entity("sensor.invalid_icon")
|
2018-10-10 11:49:15 +00:00
|
|
|
await hass.helpers.entity_component.async_update_entity(
|
2019-07-31 19:25:30 +00:00
|
|
|
"sensor.invalid_entity_picture"
|
|
|
|
)
|
2018-10-10 11:49:15 +00:00
|
|
|
await hass.helpers.entity_component.async_update_entity(
|
2019-07-31 19:25:30 +00:00
|
|
|
"sensor.invalid_friendly_name"
|
|
|
|
)
|
2018-10-10 11:49:15 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert hass.states.get("sensor.invalid_state").state == "2"
|
|
|
|
assert hass.states.get("sensor.invalid_icon").state == "hello"
|
|
|
|
assert hass.states.get("sensor.invalid_entity_picture").state == "hello"
|
|
|
|
assert hass.states.get("sensor.invalid_friendly_name").state == "hello"
|