Fix sql false warning (#67614)
This commit is contained in:
parent
5965b015dd
commit
3f9a6bbaa7
2 changed files with 7 additions and 2 deletions
|
@ -172,7 +172,7 @@ class SQLSensor(SensorEntity):
|
||||||
else:
|
else:
|
||||||
self._attr_native_value = data
|
self._attr_native_value = data
|
||||||
|
|
||||||
if not data:
|
if data is None:
|
||||||
_LOGGER.warning("%s returned no results", self._query)
|
_LOGGER.warning("%s returned no results", self._query)
|
||||||
|
|
||||||
sess.close()
|
sess.close()
|
||||||
|
|
|
@ -115,7 +115,9 @@ async def test_query_limit(hass: HomeAssistant) -> None:
|
||||||
assert state.attributes["value"] == 5
|
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."""
|
"""Test the SQL sensor with a query that returns no value."""
|
||||||
config = {
|
config = {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -137,6 +139,9 @@ async def test_query_no_value(hass: HomeAssistant) -> None:
|
||||||
state = hass.states.get("sensor.count_tables")
|
state = hass.states.get("sensor.count_tables")
|
||||||
assert state.state == STATE_UNKNOWN
|
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:
|
async def test_invalid_query(hass: HomeAssistant) -> None:
|
||||||
"""Test the SQL sensor for invalid queries."""
|
"""Test the SQL sensor for invalid queries."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue