Add resource_template to rest binary_sensor (#30703)

This commit is contained in:
Hedgehog57 authored and GitHub committed 2020-06-23 15:08:55 -07:00
1 parent 152a80abed
commit fd1edf1bb6
2 files changed
+104 -9

No files matched your search

+52 -2
View File
@@ -88,6 +88,42 @@ class TestRestBinarySensorSetup(unittest.TestCase):
self.hass.block_till_done()
assert 1 == mock_req.call_count
@requests_mock.Mocker()
def test_setup_minimum_resource_template(self, mock_req):
"""Test setup with minimum configuration (resource_template)."""
mock_req.get("http://localhost", status_code=200)
with assert_setup_component(1, "binary_sensor"):
assert setup_component(
self.hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "rest",
"resource_template": "http://localhost",
}
},
)
self.hass.block_till_done()
assert mock_req.call_count == 1
@requests_mock.Mocker()
def test_setup_duplicate_resource(self, mock_req):
"""Test setup with duplicate resources."""
mock_req.get("http://localhost", status_code=200)
with assert_setup_component(0, "binary_sensor"):
assert setup_component(
self.hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "rest",
"resource": "http://localhost",
"resource_template": "http://localhost",
}
},
)
self.hass.block_till_done()
@requests_mock.Mocker()
def test_setup_get(self, mock_req):
"""Test setup with valid configuration."""
@@ -155,9 +191,17 @@ class TestRestBinarySensor(unittest.TestCase):
self.name = "foo"
self.device_class = "light"
self.value_template = template.Template("{{ value_json.key }}", self.hass)
self.force_update = False
self.resource_template = None
self.binary_sensor = rest.RestBinarySensor(
self.hass, self.rest, self.name, self.device_class, self.value_template
self.hass,
self.rest,
self.name,
self.device_class,
self.value_template,
self.force_update,
self.resource_template,
)
self.addCleanup(self.hass.stop)
@@ -210,7 +254,13 @@ class TestRestBinarySensor(unittest.TestCase):
"rest.RestData.update", side_effect=self.update_side_effect("true")
)
self.binary_sensor = rest.RestBinarySensor(
self.hass, self.rest, self.name, self.device_class, None
self.hass,
self.rest,
self.name,
self.device_class,
None,
self.force_update,
self.resource_template,
)
self.binary_sensor.update()
assert STATE_ON == self.binary_sensor.state