1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Fix mFi error handling in setup_platform

The exception we were catching incorrectly referenced the client variable
in local scope instead of the module. Also, if we fail to connect we can
get a requests exception, so catch and handle that as well.
This commit is contained in:
Dan Smith
2016-02-25 15:48:46 -08:00
parent dc02370b43
commit 37e5b98919
3 changed files with 19 additions and 4 deletions

View File

@@ -7,6 +7,8 @@ Tests mFi sensor.
import unittest
import unittest.mock as mock
import requests
import homeassistant.components.sensor as sensor
import homeassistant.components.sensor.mfi as mfi
from homeassistant.const import TEMP_CELCIUS
@@ -54,6 +56,15 @@ class TestMfiSensorSetup(unittest.TestCase):
dict(self.GOOD_CONFIG),
None))
@mock.patch('mficlient.client')
def test_setup_failed_connect(self, mock_client):
mock_client.FailedToLogin = Exception()
mock_client.MFiClient.side_effect = requests.exceptions.ConnectionError
self.assertFalse(
self.PLATFORM.setup_platform(self.hass,
dict(self.GOOD_CONFIG),
None))
@mock.patch('mficlient.client.MFiClient')
def test_setup_minimum(self, mock_client):
config = dict(self.GOOD_CONFIG)