예제 #1
0
    def _test_us_filtered_devices(self, mock_ht, mock_sc, loc=None, dev=None):
        """Test for US filtered thermostats."""
        config = {
            CONF_USERNAME: '******',
            CONF_PASSWORD: '******',
            'region': 'us',
            'location': loc,
            'thermostat': dev,
        }
        locations = {
            1: mock.MagicMock(locationid=mock.sentinel.loc1,
                              devices_by_id={
                                  11: mock.MagicMock(
                                      deviceid=mock.sentinel.loc1dev1),
                                  12: mock.MagicMock(
                                      deviceid=mock.sentinel.loc1dev2),
                              }),
            2: mock.MagicMock(locationid=mock.sentinel.loc2,
                              devices_by_id={
                                  21: mock.MagicMock(
                                      deviceid=mock.sentinel.loc2dev1),
                              }),
            3: mock.MagicMock(locationid=mock.sentinel.loc3,
                              devices_by_id={
                                  31: mock.MagicMock(
                                      deviceid=mock.sentinel.loc3dev1),
                              }),
        }
        mock_sc.return_value = mock.MagicMock(locations_by_id=locations)
        hass = mock.MagicMock()
        add_devices = mock.MagicMock()
        self.assertEqual(True,
                         honeywell.setup_platform(hass, config, add_devices))

        return mock_ht.call_args_list, mock_sc
예제 #2
0
 def test_eu_setup_bad_temp(self, mock_round, mock_evo):
     """Test the EU setup with invalid temperature."""
     config = {
         CONF_USERNAME: '******',
         CONF_PASSWORD: '******',
         honeywell.CONF_AWAY_TEMP: 'ponies',
         'region': 'eu',
     }
     self.assertFalse(honeywell.setup_platform(None, config, None))
예제 #3
0
    def test_setup_us_failures(self, mock_sc):
        """Test the US setup."""
        hass = mock.MagicMock()
        add_devices = mock.MagicMock()
        config = {
            CONF_USERNAME: '******',
            CONF_PASSWORD: '******',
            'region': 'us',
        }

        mock_sc.side_effect = somecomfort.AuthError
        result = honeywell.setup_platform(hass, config, add_devices)
        self.assertFalse(result)
        self.assertFalse(add_devices.called)

        mock_sc.side_effect = somecomfort.SomeComfortError
        result = honeywell.setup_platform(hass, config, add_devices)
        self.assertFalse(result)
        self.assertFalse(add_devices.called)
예제 #4
0
    def test_setup_us(self, mock_ht, mock_sc):
        """Test for the US setup."""
        config = {
            CONF_USERNAME: '******',
            CONF_PASSWORD: '******',
            'region': 'us',
        }
        bad_pass_config = {
            CONF_USERNAME: '******',
            'region': 'us',
        }
        bad_region_config = {
            CONF_USERNAME: '******',
            CONF_PASSWORD: '******',
            'region': 'un',
        }
        hass = mock.MagicMock()
        add_devices = mock.MagicMock()

        locations = [
            mock.MagicMock(),
            mock.MagicMock(),
        ]
        devices_1 = [mock.MagicMock()]
        devices_2 = [mock.MagicMock(), mock.MagicMock]
        mock_sc.return_value.locations_by_id.values.return_value = \
            locations
        locations[0].devices_by_id.values.return_value = devices_1
        locations[1].devices_by_id.values.return_value = devices_2

        result = honeywell.setup_platform(hass, bad_pass_config, add_devices)
        self.assertFalse(result)
        result = honeywell.setup_platform(hass, bad_region_config, add_devices)
        self.assertFalse(result)
        result = honeywell.setup_platform(hass, config, add_devices)
        self.assertTrue(result)
        mock_sc.assert_called_once_with('user', 'pass')
        mock_ht.assert_has_calls([
            mock.call(mock_sc.return_value, devices_1[0]),
            mock.call(mock_sc.return_value, devices_2[0]),
            mock.call(mock_sc.return_value, devices_2[1]),
        ])
예제 #5
0
 def test_eu_setup_error(self, mock_round, mock_evo):
     """Test the EU setup with errors."""
     config = {
         CONF_USERNAME: '******',
         CONF_PASSWORD: '******',
         honeywell.CONF_AWAY_TEMP: 20,
         'region': 'eu',
     }
     mock_evo.return_value.temperatures.side_effect = socket.error
     add_devices = mock.MagicMock()
     hass = mock.MagicMock()
     self.assertFalse(honeywell.setup_platform(hass, config, add_devices))
예제 #6
0
 def test_eu_setup_partial_config(self, mock_round, mock_evo):
     """Test the EU setup with partial configuration."""
     config = {
         CONF_USERNAME: '******',
         CONF_PASSWORD: '******',
         'region': 'eu',
     }
     mock_evo.return_value.temperatures.return_value = [
         {'id': 'foo'}, {'id': 'bar'}]
     hass = mock.MagicMock()
     add_devices = mock.MagicMock()
     self.assertTrue(honeywell.setup_platform(hass, config, add_devices))
     default = honeywell.DEFAULT_AWAY_TEMP
     mock_round.assert_has_calls([
         mock.call(mock_evo.return_value, 'foo', True, default),
         mock.call(mock_evo.return_value, 'bar', False, default),
     ])
예제 #7
0
 def test_eu_setup_full_config(self, mock_round, mock_evo):
     """Test the EU setup wwith complete configuration."""
     config = {
         CONF_USERNAME: '******',
         CONF_PASSWORD: '******',
         honeywell.CONF_AWAY_TEMP: 20,
         'region': 'eu',
     }
     mock_evo.return_value.temperatures.return_value = [
         {'id': 'foo'}, {'id': 'bar'}]
     hass = mock.MagicMock()
     add_devices = mock.MagicMock()
     self.assertTrue(honeywell.setup_platform(hass, config, add_devices))
     mock_evo.assert_called_once_with('user', 'pass')
     mock_evo.return_value.temperatures.assert_called_once_with(
         force_refresh=True)
     mock_round.assert_has_calls([
         mock.call(mock_evo.return_value, 'foo', True, 20),
         mock.call(mock_evo.return_value, 'bar', False, 20),
     ])
     self.assertEqual(2, add_devices.call_count)