diff --git a/homeassistant/components/nuheat/__init__.py b/homeassistant/components/nuheat/__init__.py index 0bb8ed2ddaa..2f51ae377a5 100644 --- a/homeassistant/components/nuheat/__init__.py +++ b/homeassistant/components/nuheat/__init__.py @@ -5,11 +5,9 @@ import logging import nuheat import requests -import voluptuous as vol -from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry +from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - CONF_DEVICES, CONF_PASSWORD, CONF_USERNAME, HTTP_BAD_REQUEST, @@ -24,49 +22,12 @@ from .const import CONF_SERIAL_NUMBER, DOMAIN, PLATFORMS _LOGGER = logging.getLogger(__name__) -CONFIG_SCHEMA = vol.Schema( - { - DOMAIN: vol.Schema( - { - vol.Required(CONF_USERNAME): cv.string, - vol.Required(CONF_PASSWORD): cv.string, - vol.Required(CONF_DEVICES, default=[]): vol.All( - cv.ensure_list, [cv.string] - ), - } - ) - }, - extra=vol.ALLOW_EXTRA, -) +CONFIG_SCHEMA = cv.deprecated(DOMAIN) async def async_setup(hass: HomeAssistant, config: dict): """Set up the NuHeat component.""" hass.data.setdefault(DOMAIN, {}) - conf = config.get(DOMAIN) - if not conf: - return True - - for serial_number in conf[CONF_DEVICES]: - # Since the api currently doesn't permit fetching the serial numbers - # and they have to be specified we create a separate config entry for - # each serial number. This won't increase the number of http - # requests as each thermostat has to be updated anyways. - # This also allows us to validate that the entered valid serial - # numbers and do not end up with a config entry where half of the - # devices work. - hass.async_create_task( - hass.config_entries.flow.async_init( - DOMAIN, - context={"source": SOURCE_IMPORT}, - data={ - CONF_USERNAME: conf[CONF_USERNAME], - CONF_PASSWORD: conf[CONF_PASSWORD], - CONF_SERIAL_NUMBER: serial_number, - }, - ) - ) - return True diff --git a/homeassistant/components/nuheat/config_flow.py b/homeassistant/components/nuheat/config_flow.py index eb76c620767..40de3844620 100644 --- a/homeassistant/components/nuheat/config_flow.py +++ b/homeassistant/components/nuheat/config_flow.py @@ -92,13 +92,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): step_id="user", data_schema=DATA_SCHEMA, errors=errors ) - async def async_step_import(self, user_input): - """Handle import.""" - await self.async_set_unique_id(user_input[CONF_SERIAL_NUMBER]) - self._abort_if_unique_id_configured() - - return await self.async_step_user(user_input) - class CannotConnect(exceptions.HomeAssistantError): """Error to indicate we cannot connect.""" diff --git a/tests/components/nuheat/mocks.py b/tests/components/nuheat/mocks.py index de87f72fffb..a5c2b403948 100644 --- a/tests/components/nuheat/mocks.py +++ b/tests/components/nuheat/mocks.py @@ -3,9 +3,15 @@ from unittest.mock import MagicMock, Mock from nuheat.config import SCHEDULE_HOLD, SCHEDULE_RUN, SCHEDULE_TEMPORARY_HOLD -from homeassistant.components.nuheat.const import DOMAIN +from homeassistant.components.nuheat.const import CONF_SERIAL_NUMBER, DOMAIN from homeassistant.const import CONF_DEVICES, CONF_PASSWORD, CONF_USERNAME +MOCK_CONFIG_ENTRY = { + CONF_USERNAME: "me", + CONF_PASSWORD: "secret", + CONF_SERIAL_NUMBER: 12345, +} + def _get_mock_thermostat_run(): serial_number = "12345" diff --git a/tests/components/nuheat/test_climate.py b/tests/components/nuheat/test_climate.py index e5fc6246841..133c3a15ccb 100644 --- a/tests/components/nuheat/test_climate.py +++ b/tests/components/nuheat/test_climate.py @@ -4,19 +4,18 @@ from unittest.mock import patch from homeassistant.components.nuheat.const import DOMAIN from homeassistant.const import ATTR_ENTITY_ID -from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util from .mocks import ( + MOCK_CONFIG_ENTRY, _get_mock_nuheat, _get_mock_thermostat_run, _get_mock_thermostat_schedule_hold_available, _get_mock_thermostat_schedule_hold_unavailable, _get_mock_thermostat_schedule_temporary_hold, - _mock_get_config, ) -from tests.common import async_fire_time_changed +from tests.common import MockConfigEntry, async_fire_time_changed async def test_climate_thermostat_run(hass): @@ -28,7 +27,9 @@ async def test_climate_thermostat_run(hass): "homeassistant.components.nuheat.nuheat.NuHeat", return_value=mock_nuheat, ): - assert await async_setup_component(hass, DOMAIN, _mock_get_config()) + config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG_ENTRY) + config_entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() state = hass.states.get("climate.master_bathroom") @@ -59,7 +60,9 @@ async def test_climate_thermostat_schedule_hold_unavailable(hass): "homeassistant.components.nuheat.nuheat.NuHeat", return_value=mock_nuheat, ): - assert await async_setup_component(hass, DOMAIN, _mock_get_config()) + config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG_ENTRY) + config_entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() state = hass.states.get("climate.guest_bathroom") @@ -87,7 +90,9 @@ async def test_climate_thermostat_schedule_hold_available(hass): "homeassistant.components.nuheat.nuheat.NuHeat", return_value=mock_nuheat, ): - assert await async_setup_component(hass, DOMAIN, _mock_get_config()) + config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG_ENTRY) + config_entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() state = hass.states.get("climate.available_bathroom") @@ -119,7 +124,9 @@ async def test_climate_thermostat_schedule_temporary_hold(hass): "homeassistant.components.nuheat.nuheat.NuHeat", return_value=mock_nuheat, ): - assert await async_setup_component(hass, DOMAIN, _mock_get_config()) + config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG_ENTRY) + config_entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() state = hass.states.get("climate.temp_bathroom") diff --git a/tests/components/nuheat/test_config_flow.py b/tests/components/nuheat/test_config_flow.py index 246c7130c94..a21e2e744de 100644 --- a/tests/components/nuheat/test_config_flow.py +++ b/tests/components/nuheat/test_config_flow.py @@ -53,45 +53,6 @@ async def test_form_user(hass): assert len(mock_setup_entry.mock_calls) == 1 -async def test_form_import(hass): - """Test we get the form with import source.""" - await setup.async_setup_component(hass, "persistent_notification", {}) - - mock_thermostat = _get_mock_thermostat_run() - - with patch( - "homeassistant.components.nuheat.config_flow.nuheat.NuHeat.authenticate", - return_value=True, - ), patch( - "homeassistant.components.nuheat.config_flow.nuheat.NuHeat.get_thermostat", - return_value=mock_thermostat, - ), patch( - "homeassistant.components.nuheat.async_setup", return_value=True - ) as mock_setup, patch( - "homeassistant.components.nuheat.async_setup_entry", return_value=True - ) as mock_setup_entry: - result = await hass.config_entries.flow.async_init( - DOMAIN, - context={"source": config_entries.SOURCE_IMPORT}, - data={ - CONF_SERIAL_NUMBER: "12345", - CONF_USERNAME: "test-username", - CONF_PASSWORD: "test-password", - }, - ) - await hass.async_block_till_done() - - assert result["type"] == "create_entry" - assert result["title"] == "Master bathroom" - assert result["data"] == { - CONF_SERIAL_NUMBER: "12345", - CONF_USERNAME: "test-username", - CONF_PASSWORD: "test-password", - } - assert len(mock_setup.mock_calls) == 1 - assert len(mock_setup_entry.mock_calls) == 1 - - async def test_form_invalid_auth(hass): """Test we handle invalid auth.""" result = await hass.config_entries.flow.async_init( diff --git a/tests/components/nuheat/test_init.py b/tests/components/nuheat/test_init.py index dde4fd8c787..093cd0573f6 100644 --- a/tests/components/nuheat/test_init.py +++ b/tests/components/nuheat/test_init.py @@ -2,9 +2,10 @@ from unittest.mock import patch from homeassistant.components.nuheat.const import DOMAIN -from homeassistant.setup import async_setup_component -from .mocks import _get_mock_nuheat +from .mocks import MOCK_CONFIG_ENTRY, _get_mock_nuheat + +from tests.common import MockConfigEntry VALID_CONFIG = { "nuheat": {"username": "warm", "password": "feet", "devices": "thermostat123"} @@ -20,5 +21,7 @@ async def test_init_success(hass): "homeassistant.components.nuheat.nuheat.NuHeat", return_value=mock_nuheat, ): - assert await async_setup_component(hass, DOMAIN, VALID_CONFIG) + config_entry = MockConfigEntry(domain=DOMAIN, data=MOCK_CONFIG_ENTRY) + config_entry.add_to_hass(hass) + assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done()