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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user