Fix unknown data in influxdb (#85619)

This commit is contained in:
epenet 2023-01-10 16:41:16 +01:00 committed by GitHub
parent 65750fec9b
commit d313d82eb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View File

@ -18,7 +18,6 @@ from homeassistant.const import (
CONF_UNIT_OF_MEASUREMENT,
CONF_VALUE_TEMPLATE,
EVENT_HOMEASSISTANT_STOP,
STATE_UNKNOWN,
)
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady, TemplateError
@ -248,10 +247,10 @@ class InfluxSensor(SensorEntity):
"""Get the latest data from Influxdb and updates the states."""
self.data.update()
if (value := self.data.value) is None:
value = STATE_UNKNOWN
value = None
if self._value_template is not None:
value = self._value_template.render_with_possible_json_value(
str(value), STATE_UNKNOWN
str(value), None
)
self._state = value

View File

@ -245,7 +245,7 @@ async def test_minimal_config(hass, mock_client, config_ext, queries, set_query_
"unit_of_measurement": "unit",
"measurement": "measurement",
"where": "where",
"value_template": "value",
"value_template": "123",
"database": "db2",
"group_function": "fn",
"field": "field",