mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Add config flow for min_max sensor (#67807)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com> Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
55
tests/components/min_max/test_init.py
Normal file
55
tests/components/min_max/test_init.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""Test the Min/Max integration."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.min_max.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.mark.parametrize("platform", ("sensor",))
|
||||
async def test_setup_and_remove_config_entry(
|
||||
hass: HomeAssistant,
|
||||
platform: str,
|
||||
) -> None:
|
||||
"""Test setting up and removing a config entry."""
|
||||
hass.states.async_set("sensor.input_one", "10")
|
||||
hass.states.async_set("sensor.input_two", "20")
|
||||
|
||||
input_sensors = ["sensor.input_one", "sensor.input_two"]
|
||||
|
||||
registry = er.async_get(hass)
|
||||
min_max_entity_id = f"{platform}.my_min_max"
|
||||
|
||||
# Setup the config entry
|
||||
config_entry = MockConfigEntry(
|
||||
data={},
|
||||
domain=DOMAIN,
|
||||
options={
|
||||
"entity_ids": input_sensors,
|
||||
"name": "My min_max",
|
||||
"round_digits": 2.0,
|
||||
"type": "max",
|
||||
},
|
||||
title="My min_max",
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Check the entity is registered in the entity registry
|
||||
assert registry.async_get(min_max_entity_id) is not None
|
||||
|
||||
# Check the platform is setup correctly
|
||||
state = hass.states.get(min_max_entity_id)
|
||||
assert state.state == "20.0"
|
||||
assert state.attributes["count_sensors"] == 2
|
||||
|
||||
# Remove the config entry
|
||||
assert await hass.config_entries.async_remove(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Check the state and entity registry entry are removed
|
||||
assert hass.states.get(min_max_entity_id) is None
|
||||
assert registry.async_get(min_max_entity_id) is None
|
||||
Reference in New Issue
Block a user