Address error in SQL query (#39939)

This commit is contained in:
Diogo Gomes 2020-09-15 19:01:36 +01:00 committed by GitHub
parent 5a12056e59
commit 749d3c360a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -122,6 +122,7 @@ class SQLSensor(Entity):
def update(self):
"""Retrieve sensor data from the query."""
data = None
try:
sess = self.sessionmaker()
result = sess.execute(self._query)
@ -147,7 +148,7 @@ class SQLSensor(Entity):
finally:
sess.close()
if self._template is not None:
if data is not None and self._template is not None:
self._state = self._template.async_render_with_possible_json_value(
data, None
)