|
1 | 1 | """Component for ThermIQ-MQTT support.""" |
2 | 2 | import logging |
3 | 3 | from builtins import property |
| 4 | +from datetime import datetime |
| 5 | +from sqlalchemy import update, select |
4 | 6 |
|
5 | 7 | from homeassistant.config_entries import ConfigEntry |
6 | 8 | from homeassistant.core import HomeAssistant, Event |
7 | 9 | from homeassistant.const import EVENT_HOMEASSISTANT_STARTED |
8 | | -from homeassistant.components.recorder import get_instance as recorder_get_instance |
9 | | -from homeassistant.helpers.recorder import session_scope |
| 10 | + |
| 11 | +from homeassistant.helpers.recorder import session_scope, get_instance as recorder_get_instance |
10 | 12 | from homeassistant.helpers import entity_registry as er |
| 13 | +from homeassistant.components.recorder.db_schema import StatisticsMeta |
11 | 14 |
|
12 | 15 | from .const import ( |
13 | 16 | DOMAIN, |
@@ -155,8 +158,6 @@ async def _migrate_statistics_metadata(hass: HomeAssistant, recorder, entity_id: |
155 | 158 |
|
156 | 159 | def _update_metadata(session): |
157 | 160 | """Update metadata within a database session.""" |
158 | | - from sqlalchemy import update, select |
159 | | - from homeassistant.components.recorder.db_schema import StatisticsMeta |
160 | 161 |
|
161 | 162 | try: |
162 | 163 | # First check if metadata exists |
@@ -187,6 +188,9 @@ def _update_metadata(session): |
187 | 188 | ) |
188 | 189 |
|
189 | 190 | result = session.execute(update_stmt) |
| 191 | + # Suggest to replace with but this is alread doen. |
| 192 | + #homeassistant.components.recorder.get_instance(hass).async_add_executor_job() |
| 193 | + |
190 | 194 |
|
191 | 195 | if result.rowcount > 0: |
192 | 196 | _LOGGER.debug("Updated statistics metadata for %s", entity_id) |
|
0 commit comments