Fix recorder being imported before deps are installed (#77460)

pull/75391/head^2
J. Nick Koston 2022-08-28 22:18:35 -05:00 committed by GitHub
parent f41ba39a5e
commit 4333d9a7d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 18 deletions

View File

@ -1,8 +1,6 @@
"""Models for Recorder."""
from __future__ import annotations
import asyncio
from dataclasses import dataclass, field
from datetime import datetime
import logging
from typing import Any, TypedDict, overload
@ -32,14 +30,6 @@ class UnsupportedDialect(Exception):
"""The dialect or its version is not supported."""
@dataclass
class RecorderData:
"""Recorder data stored in hass.data."""
recorder_platforms: dict[str, Any] = field(default_factory=dict)
db_connected: asyncio.Future = field(default_factory=asyncio.Future)
class StatisticResult(TypedDict):
"""Statistic result data class.

View File

@ -1,9 +1,21 @@
"""Helpers to check recorder."""
import asyncio
from dataclasses import dataclass, field
from typing import Any
from homeassistant.core import HomeAssistant, callback
DOMAIN = "recorder"
@dataclass
class RecorderData:
"""Recorder data stored in hass.data."""
recorder_platforms: dict[str, Any] = field(default_factory=dict)
db_connected: asyncio.Future = field(default_factory=asyncio.Future)
def async_migration_in_progress(hass: HomeAssistant) -> bool:
"""Check to see if a recorder migration is in progress."""
@ -18,10 +30,7 @@ def async_migration_in_progress(hass: HomeAssistant) -> bool:
@callback
def async_initialize_recorder(hass: HomeAssistant) -> None:
"""Initialize recorder data."""
# pylint: disable-next=import-outside-toplevel
from homeassistant.components.recorder import const, models
hass.data[const.DOMAIN] = models.RecorderData()
hass.data[DOMAIN] = RecorderData()
async def async_wait_recorder(hass: HomeAssistant) -> bool:
@ -30,9 +39,7 @@ async def async_wait_recorder(hass: HomeAssistant) -> bool:
Returns False immediately if the recorder is not enabled.
"""
# pylint: disable-next=import-outside-toplevel
from homeassistant.components.recorder import const
if const.DOMAIN not in hass.data:
if DOMAIN not in hass.data:
return False
db_connected: asyncio.Future[bool] = hass.data[const.DOMAIN].db_connected
db_connected: asyncio.Future[bool] = hass.data[DOMAIN].db_connected
return await db_connected