2016-09-13 22:11:50 +00:00
|
|
|
"""The tests for SleepIQ sensor platform."""
|
|
|
|
import unittest
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
|
|
import requests_mock
|
|
|
|
|
2017-03-05 09:41:54 +00:00
|
|
|
from homeassistant.setup import setup_component
|
2016-09-13 22:11:50 +00:00
|
|
|
from homeassistant.components.sensor import sleepiq
|
|
|
|
|
|
|
|
from tests.components.test_sleepiq import mock_responses
|
2016-10-08 18:27:35 +00:00
|
|
|
from tests.common import get_test_home_assistant
|
2016-09-13 22:11:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestSleepIQSensorSetup(unittest.TestCase):
|
|
|
|
"""Tests the SleepIQ Sensor platform."""
|
|
|
|
|
|
|
|
DEVICES = []
|
|
|
|
|
|
|
|
def add_devices(self, devices):
|
|
|
|
"""Mock add devices."""
|
|
|
|
for device in devices:
|
|
|
|
self.DEVICES.append(device)
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""Initialize values for this testcase class."""
|
2016-10-08 18:27:35 +00:00
|
|
|
self.hass = get_test_home_assistant()
|
2016-09-13 22:11:50 +00:00
|
|
|
self.username = 'foo'
|
|
|
|
self.password = 'bar'
|
|
|
|
self.config = {
|
|
|
|
'username': self.username,
|
|
|
|
'password': self.password,
|
|
|
|
}
|
|
|
|
|
2017-01-07 00:47:25 +00:00
|
|
|
def tearDown(self): # pylint: disable=invalid-name
|
|
|
|
"""Stop everything that was started."""
|
|
|
|
self.hass.stop()
|
|
|
|
|
2016-09-13 22:11:50 +00:00
|
|
|
@requests_mock.Mocker()
|
|
|
|
def test_setup(self, mock):
|
2016-09-23 08:28:16 +00:00
|
|
|
"""Test for successfully setting up the SleepIQ platform."""
|
2016-09-13 22:11:50 +00:00
|
|
|
mock_responses(mock)
|
|
|
|
|
2017-02-24 05:44:47 +00:00
|
|
|
assert setup_component(self.hass, 'sleepiq', {
|
|
|
|
'sleepiq': {
|
|
|
|
'username': '',
|
|
|
|
'password': '',
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2016-09-13 22:11:50 +00:00
|
|
|
sleepiq.setup_platform(self.hass,
|
|
|
|
self.config,
|
|
|
|
self.add_devices,
|
|
|
|
MagicMock())
|
|
|
|
self.assertEqual(2, len(self.DEVICES))
|
|
|
|
|
|
|
|
left_side = self.DEVICES[1]
|
|
|
|
self.assertEqual('SleepNumber ILE Test1 SleepNumber', left_side.name)
|
|
|
|
self.assertEqual(40, left_side.state)
|
|
|
|
|
|
|
|
right_side = self.DEVICES[0]
|
|
|
|
self.assertEqual('SleepNumber ILE Test2 SleepNumber', right_side.name)
|
|
|
|
self.assertEqual(80, right_side.state)
|