1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00
This commit is contained in:
Paulus Schoutsen
2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View File

@@ -18,7 +18,7 @@ def session_scope(*, hass=None, session=None):
session = hass.data[DATA_INSTANCE].get_session()
if session is None:
raise RuntimeError('Session required')
raise RuntimeError("Session required")
need_rollback = False
try:
@@ -38,6 +38,7 @@ def session_scope(*, hass=None, session=None):
def commit(session, work):
"""Commit & retry work: Either a model or in a function."""
import sqlalchemy.exc
for _ in range(0, RETRIES):
try:
if callable(work):
@@ -64,15 +65,16 @@ def execute(qry):
try:
timer_start = time.perf_counter()
result = [
row for row in
(row.to_native() for row in qry)
if row is not None]
row for row in (row.to_native() for row in qry) if row is not None
]
if _LOGGER.isEnabledFor(logging.DEBUG):
elapsed = time.perf_counter() - timer_start
_LOGGER.debug('converting %d rows to native objects took %fs',
len(result),
elapsed)
_LOGGER.debug(
"converting %d rows to native objects took %fs",
len(result),
elapsed,
)
return result
except SQLAlchemyError as err: