From 14be60e5bf70d92a8e8a9555e9a0ce42b3cb8318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diefferson=20Koderer=20M=C3=B4ro?= Date: Wed, 23 Oct 2019 15:30:38 +0000 Subject: [PATCH] Move imports in nuheat component (#28038) * Move imports in nuheat component * Fix tox tests * Fix tox tests * Update tests/components/nuheat/test_init.py @Balloob suggested the change because direct replacement, the mock would never be reverted and impact the other tests. Co-Authored-By: Paulus Schoutsen --- homeassistant/components/nuheat/__init__.py | 8 +++----- homeassistant/components/nuheat/climate.py | 2 +- tests/components/nuheat/test_init.py | 9 +++++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/nuheat/__init__.py b/homeassistant/components/nuheat/__init__.py index f83611d3e40..88e10270d18 100644 --- a/homeassistant/components/nuheat/__init__.py +++ b/homeassistant/components/nuheat/__init__.py @@ -1,11 +1,11 @@ """Support for NuHeat thermostats.""" import logging +import nuheat import voluptuous as vol -from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_DEVICES -from homeassistant.helpers import config_validation as cv -from homeassistant.helpers import discovery +from homeassistant.const import CONF_DEVICES, CONF_PASSWORD, CONF_USERNAME +from homeassistant.helpers import config_validation as cv, discovery _LOGGER = logging.getLogger(__name__) @@ -29,8 +29,6 @@ CONFIG_SCHEMA = vol.Schema( def setup(hass, config): """Set up the NuHeat thermostat component.""" - import nuheat - conf = config[DOMAIN] username = conf.get(CONF_USERNAME) password = conf.get(CONF_PASSWORD) diff --git a/homeassistant/components/nuheat/climate.py b/homeassistant/components/nuheat/climate.py index 19780a35a20..5a4e4e233d1 100644 --- a/homeassistant/components/nuheat/climate.py +++ b/homeassistant/components/nuheat/climate.py @@ -9,9 +9,9 @@ from homeassistant.components.climate.const import ( HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF, + PRESET_NONE, SUPPORT_PRESET_MODE, SUPPORT_TARGET_TEMPERATURE, - PRESET_NONE, ) from homeassistant.const import ( ATTR_ENTITY_ID, diff --git a/tests/components/nuheat/test_init.py b/tests/components/nuheat/test_init.py index a6be3ac14f5..90a209fd897 100644 --- a/tests/components/nuheat/test_init.py +++ b/tests/components/nuheat/test_init.py @@ -1,11 +1,11 @@ """NuHeat component tests.""" import unittest - from unittest.mock import patch -from tests.common import get_test_home_assistant, MockDependency from homeassistant.components import nuheat +from tests.common import MockDependency, get_test_home_assistant + VALID_CONFIG = { "nuheat": {"username": "warm", "password": "feet", "devices": "thermostat123"} } @@ -27,11 +27,12 @@ class TestNuHeat(unittest.TestCase): @patch("homeassistant.helpers.discovery.load_platform") def test_setup(self, mocked_nuheat, mocked_load): """Test setting up the NuHeat component.""" - nuheat.setup(self.hass, self.config) + with patch.object(nuheat, "nuheat", mocked_nuheat): + nuheat.setup(self.hass, self.config) mocked_nuheat.NuHeat.assert_called_with("warm", "feet") assert nuheat.DOMAIN in self.hass.data - assert 2 == len(self.hass.data[nuheat.DOMAIN]) + assert len(self.hass.data[nuheat.DOMAIN]) == 2 assert isinstance( self.hass.data[nuheat.DOMAIN][0], type(mocked_nuheat.NuHeat()) )