From 02e2e4d0395d6000211c5142e1437dd18f803bad Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 28 Mar 2023 16:29:24 +0200 Subject: [PATCH] Add rest encoding test (#90404) * Add rest encoding test * docstring --- tests/components/rest/test_sensor.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/components/rest/test_sensor.py b/tests/components/rest/test_sensor.py index 46a972628e5..5ae8530c295 100644 --- a/tests/components/rest/test_sensor.py +++ b/tests/components/rest/test_sensor.py @@ -106,6 +106,31 @@ async def test_setup_minimum(hass: HomeAssistant) -> None: assert len(hass.states.async_all("sensor")) == 1 +@respx.mock +async def test_setup_encoding(hass: HomeAssistant) -> None: + """Test setup with non-utf8 encoding.""" + respx.get("http://localhost").respond( + status_code=HTTPStatus.OK, + stream=httpx.ByteStream("tack själv".encode(encoding="iso-8859-1")), + ) + assert await async_setup_component( + hass, + DOMAIN, + { + "sensor": { + "name": "mysensor", + "encoding": "iso-8859-1", + "platform": "rest", + "resource": "http://localhost", + "method": "GET", + } + }, + ) + await hass.async_block_till_done() + assert len(hass.states.async_all("sensor")) == 1 + assert hass.states.get("sensor.mysensor").state == "tack själv" + + @respx.mock async def test_manual_update(hass: HomeAssistant) -> None: """Test setup with minimum configuration."""