* 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
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
"""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'}
|