adaptive-lighting/tests/test_init.py
pre-commit-ci[bot] 95a59438b6
[pre-commit.ci] pre-commit autoupdate (#882)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.1.6 → v0.2.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.6...v0.2.0)
- [github.com/psf/black: 23.11.0 → 24.1.1](https://github.com/psf/black/compare/23.11.0...24.1.1)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-02-05 14:13:13 -08:00

53 lines
1.7 KiB
Python

"""Tests for Adaptive Lighting integration."""
from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import CONF_NAME
from homeassistant.setup import async_setup_component
from pytest_homeassistant_custom_component.common import MockConfigEntry
from custom_components import adaptive_lighting
from custom_components.adaptive_lighting.const import DEFAULT_NAME, UNDO_UPDATE_LISTENER
async def test_setup_with_config(hass):
"""Test that we import the config and setup the integration."""
config = {
adaptive_lighting.DOMAIN: {
adaptive_lighting.CONF_NAME: DEFAULT_NAME,
}
}
assert await async_setup_component(hass, adaptive_lighting.DOMAIN, config)
assert adaptive_lighting.DOMAIN in hass.data
async def test_successful_config_entry(hass):
"""Test that Adaptive Lighting is configured successfully."""
entry = MockConfigEntry(
domain=adaptive_lighting.DOMAIN,
data={CONF_NAME: DEFAULT_NAME},
)
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
assert entry.state == ConfigEntryState.LOADED
assert UNDO_UPDATE_LISTENER in hass.data[adaptive_lighting.DOMAIN][entry.entry_id]
async def test_unload_entry(hass):
"""Test removing Adaptive Lighting."""
entry = MockConfigEntry(
domain=adaptive_lighting.DOMAIN,
data={CONF_NAME: DEFAULT_NAME},
)
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()
assert entry.state == ConfigEntryState.NOT_LOADED
assert adaptive_lighting.DOMAIN not in hass.data