def test_eu_setup_full_config(self, mock_round, mock_evo): """Test the EU setup with complete configuration.""" config = { CONF_USERNAME: '******', CONF_PASSWORD: '******', honeywell.CONF_AWAY_TEMPERATURE: 20.0, honeywell.CONF_REGION: 'eu', } mock_evo.return_value.temperatures.return_value = [{ 'id': 'foo' }, { 'id': 'bar' }] hass = mock.MagicMock() add_entities = mock.MagicMock() assert honeywell.setup_platform(hass, config, add_entities) assert mock_evo.call_count == 1 assert mock_evo.call_args == mock.call('user', 'pass') assert mock_evo.return_value.temperatures.call_count == 1 assert mock_evo.return_value.temperatures.call_args == \ mock.call(force_refresh=True) mock_round.assert_has_calls([ mock.call(mock_evo.return_value, 'foo', True, 20.0), mock.call(mock_evo.return_value, 'bar', False, 20.0), ]) assert 2 == add_entities.call_count
def test_eu_setup_full_config(self, mock_round, mock_evo): """Test the EU setup with complete configuration.""" config = { CONF_USERNAME: '******', CONF_PASSWORD: '******', honeywell.CONF_AWAY_TEMPERATURE: 20.0, honeywell.CONF_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)) self.assertEqual(mock_evo.call_count, 1) self.assertEqual(mock_evo.call_args, mock.call('user', 'pass')) self.assertEqual(mock_evo.return_value.temperatures.call_count, 1) self.assertEqual( mock_evo.return_value.temperatures.call_args, mock.call(force_refresh=True) ) mock_round.assert_has_calls([ mock.call(mock_evo.return_value, 'foo', True, 20.0), mock.call(mock_evo.return_value, 'bar', False, 20.0), ]) self.assertEqual(2, add_devices.call_count)
def _test_us_filtered_devices(self, mock_ht, mock_sc, loc=None, dev=None): """Test for US filtered thermostats.""" config = { CONF_USERNAME: '******', CONF_PASSWORD: '******', honeywell.CONF_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
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))
def test_setup_us_failures(self, mock_sc): """Test the US setup.""" hass = mock.MagicMock() add_devices = mock.MagicMock() config = { CONF_USERNAME: '******', CONF_PASSWORD: '******', honeywell.CONF_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)
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]), ])
def test_eu_setup_error(self, mock_round, mock_evo): """Test the EU setup with errors.""" config = { CONF_USERNAME: '******', CONF_PASSWORD: '******', honeywell.CONF_AWAY_TEMPERATURE: 20, honeywell.CONF_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))
def test_setup_us(self, mock_ht, mock_sc): """Test for the US setup.""" config = { CONF_USERNAME: '******', CONF_PASSWORD: '******', honeywell.CONF_REGION: 'us', } bad_pass_config = { CONF_USERNAME: '******', honeywell.CONF_REGION: 'us', } bad_region_config = { CONF_USERNAME: '******', CONF_PASSWORD: '******', honeywell.CONF_REGION: 'un', } with self.assertRaises(vol.Invalid): honeywell.PLATFORM_SCHEMA(None) with self.assertRaises(vol.Invalid): honeywell.PLATFORM_SCHEMA({}) with self.assertRaises(vol.Invalid): honeywell.PLATFORM_SCHEMA(bad_pass_config) with self.assertRaises(vol.Invalid): honeywell.PLATFORM_SCHEMA(bad_region_config) 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, config, add_devices) self.assertTrue(result) self.assertEqual(mock_sc.call_count, 1) self.assertEqual(mock_sc.call_args, mock.call('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]), ])
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), ])
def test_eu_setup_partial_config(self, mock_round, mock_evo): """Test the EU setup with partial configuration.""" config = { CONF_USERNAME: '******', CONF_PASSWORD: '******', honeywell.CONF_REGION: 'eu', } mock_evo.return_value.temperatures.return_value = [ {'id': 'foo'}, {'id': 'bar'}] config[honeywell.CONF_AWAY_TEMPERATURE] = \ honeywell.DEFAULT_AWAY_TEMPERATURE hass = mock.MagicMock() add_entities = mock.MagicMock() assert honeywell.setup_platform(hass, config, add_entities) mock_round.assert_has_calls([ mock.call(mock_evo.return_value, 'foo', True, 16), mock.call(mock_evo.return_value, 'bar', False, 16), ])
def test_eu_setup_partial_config(self, mock_round, mock_evo): """Test the EU setup with partial configuration.""" config = { CONF_USERNAME: '******', CONF_PASSWORD: '******', honeywell.CONF_REGION: 'eu', } mock_evo.return_value.temperatures.return_value = [ {'id': 'foo'}, {'id': 'bar'}] config[honeywell.CONF_AWAY_TEMPERATURE] = \ honeywell.DEFAULT_AWAY_TEMPERATURE hass = mock.MagicMock() add_devices = mock.MagicMock() self.assertTrue(honeywell.setup_platform(hass, config, add_devices)) mock_round.assert_has_calls([ mock.call(mock_evo.return_value, 'foo', True, 16), mock.call(mock_evo.return_value, 'bar', False, 16), ])
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)
def test_setup_us(self, mock_ht, mock_sc): """Test for the US setup.""" config = { CONF_USERNAME: '******', CONF_PASSWORD: '******', honeywell.CONF_COOL_AWAY_TEMPERATURE: 18, honeywell.CONF_HEAT_AWAY_TEMPERATURE: 28, honeywell.CONF_REGION: 'us', } bad_pass_config = { CONF_USERNAME: '******', honeywell.CONF_COOL_AWAY_TEMPERATURE: 18, honeywell.CONF_HEAT_AWAY_TEMPERATURE: 28, honeywell.CONF_REGION: 'us', } bad_region_config = { CONF_USERNAME: '******', CONF_PASSWORD: '******', honeywell.CONF_COOL_AWAY_TEMPERATURE: 18, honeywell.CONF_HEAT_AWAY_TEMPERATURE: 28, honeywell.CONF_REGION: 'un', } with pytest.raises(vol.Invalid): honeywell.PLATFORM_SCHEMA(None) with pytest.raises(vol.Invalid): honeywell.PLATFORM_SCHEMA({}) with pytest.raises(vol.Invalid): honeywell.PLATFORM_SCHEMA(bad_pass_config) with pytest.raises(vol.Invalid): honeywell.PLATFORM_SCHEMA(bad_region_config) hass = mock.MagicMock() add_entities = 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, config, add_entities) assert result assert mock_sc.call_count == 1 assert mock_sc.call_args == mock.call('user', 'pass') mock_ht.assert_has_calls([ mock.call(mock_sc.return_value, devices_1[0], 18, 28, 'user', 'pass'), mock.call(mock_sc.return_value, devices_2[0], 18, 28, 'user', 'pass'), mock.call(mock_sc.return_value, devices_2[1], 18, 28, 'user', 'pass'), ])