Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/flipr/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
SensorEntityDescription(
key="chlorine",
translation_key="chlorine",
native_unit_of_measurement=UnitOfElectricPotential.MILLIVOLT,
native_unit_of_measurement="mg/L",
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
Expand Down
6 changes: 6 additions & 0 deletions homeassistant/components/rest/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ async def async_update(self, log_errors: bool = True) -> None:
rendered_headers = template.render_complex(self._headers, parse_result=False)
rendered_params = template.render_complex(self._params)

# Convert boolean values to lowercase strings for compatibility with aiohttp/yarl
if rendered_params:
for key, value in rendered_params.items():
if isinstance(value, bool):
rendered_params[key] = str(value).lower()

_LOGGER.debug("Updating from %s", self._resource)
# Create request kwargs
request_kwargs: dict[str, Any] = {
Expand Down
2 changes: 1 addition & 1 deletion tests/components/flipr/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def test_sensors(

state = hass.states.get("sensor.flipr_myfliprid_chlorine")
assert state
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "mV"
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "mg/L"
assert state.attributes.get(ATTR_STATE_CLASS) is SensorStateClass.MEASUREMENT
assert state.state == "0.23654886"

Expand Down
49 changes: 49 additions & 0 deletions tests/components/rest/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,52 @@ async def test_rest_data_timeout_error(
"Timeout while fetching data: http://example.com/api" in caplog.text
or "Platform rest not ready yet" in caplog.text
)


async def test_rest_data_boolean_params_converted_to_strings(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test that boolean parameters are converted to lowercase strings."""
# Mock the request and capture the actual URL
aioclient_mock.get(
"http://example.com/api",
status=200,
json={"status": "ok"},
headers={"Content-Type": "application/json"},
)

assert await async_setup_component(
hass,
DOMAIN,
{
DOMAIN: {
"resource": "http://example.com/api",
"method": "GET",
"params": {
"boolTrue": True,
"boolFalse": False,
"stringParam": "test",
"intParam": 123,
},
"sensor": [
{
"name": "test_sensor",
"value_template": "{{ value_json.status }}",
}
],
}
},
)
await hass.async_block_till_done()

# Check that the request was made with boolean values converted to strings
assert len(aioclient_mock.mock_calls) == 1
method, url, data, headers = aioclient_mock.mock_calls[0]

# Check that the URL query parameters have boolean values converted to strings
assert url.query["boolTrue"] == "true"
assert url.query["boolFalse"] == "false"
assert url.query["stringParam"] == "test"
assert url.query["intParam"] == "123"
Loading