Fix tests (#3387)
This commit is contained in:
1 parent
165362da0c
commit
afc527ea55
2 files changed
+16
-21
No files matched your search
@@ -98,8 +98,7 @@ def run_information(point_in_time: Optional[datetime]=None):
|
||||
|
||||
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Setup the recorder."""
|
||||
# pylint: disable=global-statement
|
||||
global _INSTANCE
|
||||
global _INSTANCE # pylint: disable=global-statement
|
||||
|
||||
if _INSTANCE is not None:
|
||||
_LOGGER.error('Only a single instance allowed.')
|
||||
@@ -164,7 +163,6 @@ class Recorder(threading.Thread):
|
||||
self.hass = hass
|
||||
self.purge_days = purge_days
|
||||
self.queue = queue.Queue() # type: Any
|
||||
self.quit_object = object()
|
||||
self.recording_start = dt_util.utcnow()
|
||||
self.db_url = uri
|
||||
self.db_ready = threading.Event()
|
||||
@@ -205,12 +203,9 @@ class Recorder(threading.Thread):
|
||||
while True:
|
||||
event = self.queue.get()
|
||||
|
||||
if event == self.quit_object:
|
||||
if event is None:
|
||||
self._close_run()
|
||||
self._close_connection()
|
||||
# pylint: disable=global-statement
|
||||
global _INSTANCE
|
||||
_INSTANCE = None
|
||||
self.queue.task_done()
|
||||
return
|
||||
|
||||
@@ -238,8 +233,11 @@ class Recorder(threading.Thread):
|
||||
|
||||
def shutdown(self, event):
|
||||
"""Tell the recorder to shut down."""
|
||||
self.queue.put(self.quit_object)
|
||||
self.queue.join()
|
||||
global _INSTANCE # pylint: disable=global-statement
|
||||
_INSTANCE = None
|
||||
|
||||
self.queue.put(None)
|
||||
self.join()
|
||||
|
||||
def block_till_done(self):
|
||||
"""Block till all events processed."""
|
||||
@@ -251,8 +249,7 @@ class Recorder(threading.Thread):
|
||||
|
||||
def _setup_connection(self):
|
||||
"""Ensure database is ready to fly."""
|
||||
# pylint: disable=global-statement
|
||||
global Session
|
||||
global Session # pylint: disable=global-statement
|
||||
|
||||
import homeassistant.components.recorder.models as models
|
||||
from sqlalchemy import create_engine
|
||||
@@ -275,8 +272,7 @@ class Recorder(threading.Thread):
|
||||
|
||||
def _close_connection(self):
|
||||
"""Close the connection."""
|
||||
# pylint: disable=global-statement
|
||||
global Session
|
||||
global Session # pylint: disable=global-statement
|
||||
self.engine.dispose()
|
||||
self.engine = None
|
||||
Session = None
|
||||
|
||||
Reference in new issue
Block a user