Hi,
I am currently having a hard time to write tests for my custom integration to import long-term statistics.
Pytest is working, and I can test local methods.
But I would like to test if the import of statistical data really worked, and the imported data are available in the HA database. For that, I have to at least get the recorder up and running from the test (the recorder is of course a dependency of the import integration). And the only way to read the historical data I found is the HA REST API, so I would need this as well.
But I did not even manage to setup the recorder. When I do this:
async def test_async_setup(hass):
"""Test the component gets setup."""
assert await async_setup_component(hass, DOMAIN, {}) is True
I get this:
tests/test_test.py:16: AssertionError
----------------------------------------------------------------------------- Captured stderr call -----------------------------------------------------------------------------
INFO:homeassistant.loader:Loaded import_statistics from custom_components.import_statistics
WARNING:homeassistant.loader:We found a custom integration import_statistics which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
INFO:homeassistant.loader:Loaded recorder from homeassistant.components.recorder
INFO:homeassistant.setup:Setting up recorder
ERROR:homeassistant.setup:Error during setup of component recorder
Traceback (most recent call last):
File "/home/vscode/.local/lib/python3.11/site-packages/homeassistant/setup.py", line 333, in _async_setup_component
result = await task
^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/homeassistant/components/recorder/__init__.py", line 152, in async_setup
instance = hass.data[DATA_INSTANCE] = Recorder(
^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/homeassistant/components/recorder/core.py", line 198, in __init__
db_connected: asyncio.Future[bool] = hass.data[DOMAIN].db_connected
~~~~~~~~~^^^^^^^^
KeyError: 'recorder'
ERROR:homeassistant.setup:Unable to set up dependencies of 'import_statistics'. Setup failed for dependencies: recorder
ERROR:homeassistant.setup:Setup failed for custom integration 'import_statistics': (DependencyError(...), 'Could not setup dependencies: recorder')
(repo see https://github.com/klausj1/homeassistant-statistics/tree/addtests)
Probably I need the whole HA core up and running, but I have no idea how to do this.
Can please somebody help for the above problem, and also for the REST API (or point me to a better API to read long term statistical data)?
Thanks!