mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Fix sql false warning (#67614)
This commit is contained in:
parent
5965b015dd
commit
3f9a6bbaa7
@ -172,7 +172,7 @@ class SQLSensor(SensorEntity):
|
||||
else:
|
||||
self._attr_native_value = data
|
||||
|
||||
if not data:
|
||||
if data is None:
|
||||
_LOGGER.warning("%s returned no results", self._query)
|
||||
|
||||
sess.close()
|
||||
|
@ -115,7 +115,9 @@ async def test_query_limit(hass: HomeAssistant) -> None:
|
||||
assert state.attributes["value"] == 5
|
||||
|
||||
|
||||
async def test_query_no_value(hass: HomeAssistant) -> None:
|
||||
async def test_query_no_value(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test the SQL sensor with a query that returns no value."""
|
||||
config = {
|
||||
"sensor": {
|
||||
@ -137,6 +139,9 @@ async def test_query_no_value(hass: HomeAssistant) -> None:
|
||||
state = hass.states.get("sensor.count_tables")
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
text = "SELECT 5 as value where 1=2 returned no results"
|
||||
assert text in caplog.text
|
||||
|
||||
|
||||
async def test_invalid_query(hass: HomeAssistant) -> None:
|
||||
"""Test the SQL sensor for invalid queries."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user