mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Zone component config entry support (#14059)
* Initial commit * Add error handling to config flow Change unique identifyer to name Clean up hound comments * Ensure hass home zone is created with correct entity id Fix failing tests * Fix rest of tests * Move zone tests to zone folder Create config flow tests * Add possibility to unload entry * Use hass.data instead of globas * Don't calculate configures zones every loop iteration * No need to know about home zone during setup of entry * Only use name as title * Don't cache hass home zone * Add new tests for setup and setup entry * Break out functionality from init to zone.py * Make hass home zone be created directly * Make sure that config flow doesn't override hass home zone * A newline was missing in const * Configured zones shall not be imported Removed config flow import functionality Improved tests
This commit is contained in:
committed by
Paulus Schoutsen
parent
f5de2b9e5b
commit
4b06392442
55
tests/components/zone/test_config_flow.py
Normal file
55
tests/components/zone/test_config_flow.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""Tests for zone config flow."""
|
||||
|
||||
from homeassistant.components.zone import config_flow
|
||||
from homeassistant.components.zone.const import CONF_PASSIVE, DOMAIN, HOME_ZONE
|
||||
from homeassistant.const import (
|
||||
CONF_NAME, CONF_LATITUDE, CONF_LONGITUDE, CONF_ICON, CONF_RADIUS)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_flow_works(hass):
|
||||
"""Test that config flow works."""
|
||||
flow = config_flow.ZoneFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
result = await flow.async_step_init(user_input={
|
||||
CONF_NAME: 'Name',
|
||||
CONF_LATITUDE: '1.1',
|
||||
CONF_LONGITUDE: '2.2',
|
||||
CONF_RADIUS: '100',
|
||||
CONF_ICON: 'mdi:home',
|
||||
CONF_PASSIVE: True
|
||||
})
|
||||
|
||||
assert result['type'] == 'create_entry'
|
||||
assert result['title'] == 'Name'
|
||||
assert result['data'] == {
|
||||
CONF_NAME: 'Name',
|
||||
CONF_LATITUDE: '1.1',
|
||||
CONF_LONGITUDE: '2.2',
|
||||
CONF_RADIUS: '100',
|
||||
CONF_ICON: 'mdi:home',
|
||||
CONF_PASSIVE: True
|
||||
}
|
||||
|
||||
|
||||
async def test_flow_requires_unique_name(hass):
|
||||
"""Test that config flow verifies that each zones name is unique."""
|
||||
MockConfigEntry(domain=DOMAIN, data={
|
||||
CONF_NAME: 'Name'
|
||||
}).add_to_hass(hass)
|
||||
flow = config_flow.ZoneFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
result = await flow.async_step_init(user_input={CONF_NAME: 'Name'})
|
||||
assert result['errors'] == {'base': 'name_exists'}
|
||||
|
||||
|
||||
async def test_flow_requires_name_different_from_home(hass):
|
||||
"""Test that config flow verifies that each zones name is unique."""
|
||||
flow = config_flow.ZoneFlowHandler()
|
||||
flow.hass = hass
|
||||
|
||||
result = await flow.async_step_init(user_input={CONF_NAME: HOME_ZONE})
|
||||
assert result['errors'] == {'base': 'name_exists'}
|
||||
Reference in New Issue
Block a user