diff --git a/tests/components/rest/test_sensor.py b/tests/components/rest/test_sensor.py index a288159c9d4..5dcaed6985d 100644 --- a/tests/components/rest/test_sensor.py +++ b/tests/components/rest/test_sensor.py @@ -182,7 +182,9 @@ async def test_setup_duplicate_resource_template(hass: HomeAssistant) -> None: @respx.mock async def test_setup_get(hass: HomeAssistant) -> None: """Test setup with valid configuration.""" - respx.get("http://localhost").respond(status_code=HTTPStatus.OK, json={}) + respx.get("http://localhost").respond( + status_code=HTTPStatus.OK, json={"key": "123"} + ) assert await async_setup_component( hass, "sensor", @@ -210,7 +212,7 @@ async def test_setup_get(hass: HomeAssistant) -> None: await hass.async_block_till_done() assert len(hass.states.async_all("sensor")) == 1 - assert hass.states.get("sensor.foo").state == "" + assert hass.states.get("sensor.foo").state == "123" await hass.services.async_call( "homeassistant", SERVICE_UPDATE_ENTITY, @@ -219,7 +221,7 @@ async def test_setup_get(hass: HomeAssistant) -> None: ) await hass.async_block_till_done() state = hass.states.get("sensor.foo") - assert state.state == "" + assert state.state == "123" assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTemperature.CELSIUS assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.TEMPERATURE assert state.attributes[ATTR_STATE_CLASS] is SensorStateClass.MEASUREMENT @@ -325,7 +327,9 @@ async def test_setup_get_templated_headers_params(hass: HomeAssistant) -> None: @respx.mock async def test_setup_get_digest_auth(hass: HomeAssistant) -> None: """Test setup with valid configuration.""" - respx.get("http://localhost").respond(status_code=HTTPStatus.OK, json={}) + respx.get("http://localhost").respond( + status_code=HTTPStatus.OK, json={"key": "123"} + ) assert await async_setup_component( hass, "sensor", @@ -354,7 +358,9 @@ async def test_setup_get_digest_auth(hass: HomeAssistant) -> None: @respx.mock async def test_setup_post(hass: HomeAssistant) -> None: """Test setup with valid configuration.""" - respx.post("http://localhost").respond(status_code=HTTPStatus.OK, json={}) + respx.post("http://localhost").respond( + status_code=HTTPStatus.OK, json={"key": "123"} + ) assert await async_setup_component( hass, "sensor", @@ -386,7 +392,7 @@ async def test_setup_get_xml(hass: HomeAssistant) -> None: respx.get("http://localhost").respond( status_code=HTTPStatus.OK, headers={"content-type": "text/xml"}, - content="abc", + content="123", ) assert await async_setup_component( hass, @@ -408,7 +414,7 @@ async def test_setup_get_xml(hass: HomeAssistant) -> None: assert len(hass.states.async_all("sensor")) == 1 state = hass.states.get("sensor.foo") - assert state.state == "abc" + assert state.state == "123" assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfInformation.MEGABYTES @@ -438,7 +444,7 @@ async def test_update_with_json_attrs(hass: HomeAssistant) -> None: respx.get("http://localhost").respond( status_code=HTTPStatus.OK, - json={"key": "some_json_value"}, + json={"key": "123", "other_key": "some_json_value"}, ) assert await async_setup_component( hass, @@ -449,7 +455,7 @@ async def test_update_with_json_attrs(hass: HomeAssistant) -> None: "resource": "http://localhost", "method": "GET", "value_template": "{{ value_json.key }}", - "json_attributes": ["key"], + "json_attributes": ["other_key"], "name": "foo", "unit_of_measurement": UnitOfInformation.MEGABYTES, "verify_ssl": "true", @@ -461,8 +467,8 @@ async def test_update_with_json_attrs(hass: HomeAssistant) -> None: assert len(hass.states.async_all("sensor")) == 1 state = hass.states.get("sensor.foo") - assert state.state == "some_json_value" - assert state.attributes["key"] == "some_json_value" + assert state.state == "123" + assert state.attributes["other_key"] == "some_json_value" @respx.mock @@ -483,7 +489,6 @@ async def test_update_with_no_template(hass: HomeAssistant) -> None: "method": "GET", "json_attributes": ["key"], "name": "foo", - "unit_of_measurement": UnitOfInformation.MEGABYTES, "verify_ssl": "true", "timeout": 30, "headers": {"Accept": "text/xml"}, @@ -556,7 +561,6 @@ async def test_update_with_json_attrs_not_dict( "value_template": "{{ value_json.key }}", "json_attributes": ["key"], "name": "foo", - "unit_of_measurement": UnitOfInformation.MEGABYTES, "verify_ssl": "true", "timeout": 30, "headers": {"Accept": "text/xml"}, @@ -568,7 +572,7 @@ async def test_update_with_json_attrs_not_dict( state = hass.states.get("sensor.foo") assert state.state == "" - assert state.attributes == {"unit_of_measurement": "MB", "friendly_name": "foo"} + assert state.attributes == {"friendly_name": "foo"} assert "not a dictionary or list" in caplog.text @@ -618,7 +622,7 @@ async def test_update_with_json_attrs_with_json_attrs_path(hass: HomeAssistant) status_code=HTTPStatus.OK, json={ "toplevel": { - "master_value": "master", + "master_value": "123", "second_level": { "some_json_key": "some_json_value", "some_json_key2": "some_json_value2", @@ -649,7 +653,7 @@ async def test_update_with_json_attrs_with_json_attrs_path(hass: HomeAssistant) assert len(hass.states.async_all("sensor")) == 1 state = hass.states.get("sensor.foo") - assert state.state == "master" + assert state.state == "123" assert state.attributes["some_json_key"] == "some_json_value" assert state.attributes["some_json_key2"] == "some_json_value2" @@ -663,7 +667,7 @@ async def test_update_with_xml_convert_json_attrs_with_json_attrs_path( respx.get("http://localhost").respond( status_code=HTTPStatus.OK, headers={"content-type": "text/xml"}, - content="mastersome_json_valuesome_json_value2", + content="123some_json_valuesome_json_value2", ) assert await async_setup_component( hass, @@ -687,7 +691,7 @@ async def test_update_with_xml_convert_json_attrs_with_json_attrs_path( assert len(hass.states.async_all("sensor")) == 1 state = hass.states.get("sensor.foo") - assert state.state == "master" + assert state.state == "123" assert state.attributes["some_json_key"] == "some_json_value" assert state.attributes["some_json_key2"] == "some_json_value2" @@ -701,7 +705,7 @@ async def test_update_with_xml_convert_json_attrs_with_jsonattr_template( respx.get("http://localhost").respond( status_code=HTTPStatus.OK, headers={"content-type": "text/xml"}, - content='01255648alexander000bogus000000000upupupup000x0XF0x0XF 0', + content='01255648alexander000123000000000upupupup000x0XF0x0XF 0', ) assert await async_setup_component( hass, @@ -725,7 +729,7 @@ async def test_update_with_xml_convert_json_attrs_with_jsonattr_template( assert len(hass.states.async_all("sensor")) == 1 state = hass.states.get("sensor.foo") - assert state.state == "bogus" + assert state.state == "123" assert state.attributes["led0"] == "0" assert state.attributes["led1"] == "0" assert state.attributes["temp0"] == "0x0XF0x0XF" @@ -906,7 +910,7 @@ async def test_entity_config(hass: HomeAssistant) -> None: }, } - respx.get("http://localhost") % HTTPStatus.OK + respx.get("http://localhost").respond(status_code=HTTPStatus.OK, text="123") assert await async_setup_component(hass, DOMAIN, config) await hass.async_block_till_done() @@ -914,7 +918,7 @@ async def test_entity_config(hass: HomeAssistant) -> None: assert entity_registry.async_get("sensor.rest_sensor").unique_id == "very_unique" state = hass.states.get("sensor.rest_sensor") - assert state.state == "" + assert state.state == "123" assert state.attributes == { "device_class": "temperature", "entity_picture": "blabla.png",