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 committed 2016-02-25 15:52:13 -08:00
1 parent dc02370b43
commit 37e5b98919
3 files changed
+19 -4

No files matched your search

+11
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)